How to extract symbol properties using VBA?

1968
4
01-24-2012 03:44 AM
ChristineGo
New Contributor
I am writing a VBA program to extract symbol properties under feature layers of a MxDocument.
I'm able to extract properties like symbol colors and line width, but when I try to get more detail,
I'm not able to tell whether a symbol is SimpleLineSymbol or MarkerLineSymbol.
My program is like this:


Dim pGFL As IGeoFeatureLayer
Dim pSbl As ISymbol
Dim pSPR As ISimplyRenderer
Dim pMLS As IMarkerLineSymbol

If TypeOf pGFL.Renderer Is ISimpleRenderer Then
    Set pSPR = pGFL.Renderer

    If pFL.FeatureClass.ShapeType = esriGeometryPolyline Then
        Set pMLS = pSbl
        MsgBox "Marker Symbol Size = " & pMLS.MarkerSymbol.Size
    End If
End If


But I got error when I came over Set pMLS = pSbl.
If I define pMLS as MarkerLineSymbol instead of IMarkerLineSymbol, the statement Set pMLS = pSbl works,
but then it'll say pMLS.MarkerSymbol is a undefined method.

If I declare pMLS as ILineSymbol, I can set pMLS = pSbl, but I'm not able to get the MarkerSymbol related properties.
Could anyone share with me:
(1) How to obtain the Marker Symbol related properties from a ISymbol?
(2) How to determine the type of Symbol, e.g., SimpleLineSymbol or MarkerLineSymbol?

Thanks.
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
You do it the same way you're checking for the renderer type in your code, by using TypeOf.  The symbol for a polyline layer will be of type ILineSymbol.  There are several coclasses that implement ILineSymbol  - MarkerLineSymbol and SimpleLineSymbol are only two of them so you'll need to check for all of the others as well.

Dim lineSymbol As ILineSymbol = simpleRenderer.Symbol
If TypeOf lineSymbol Is IMarkerLineSymbol Then
  ' marker line symbol
ElseIf TypeOf lineSymbol Is ISimpleLineSymbol Then
  ' simple line symbol
End If
0 Kudos
ChristineGo
New Contributor
I did something like this, but why it didn't work?
The program error out in the 'Set' statement.

Dim Symbol As ISymbol = simpleRenderer.Symbol
Dim MLSymbol As IMarkerLineSymbol
Dim SLSymbol As ISimpleLineSymbol

If TypeOf Symbol Is IMarkerLineSymbol Then
  Set MLSymbol = Symbol
ElseIf TypeOf Symbol Is ISimpleLineSymbol Then
  Set SLSymbol = Symbol
End If
0 Kudos
ChristineGo
New Contributor
What's the difference between interface and co-class?
When we use 'TypeOf', should we use 'TypeOf xxx Is' followed by an interface or followed by a co-class?
I ask this because when I check a linesymbol against the interface of different linesymbols, I got no match;
when I use co-class, I got all match.
0 Kudos
NeilClemmons
Regular Contributor III
You use the interface when checking types with TypeOf.  Keep in mind that a symbol can be many different types.  If you look at the help for ISymbol then you'll see a list of all the coclasses that implement that interface.  In theory, it could be any of them but you can rule some of them out simply because it's a symbol being used by a line layer.  That's why I suggested only testing for the ILineSymbol types.  If you look at the help for ILineSymbol then you'll see the list of coclasses that you should be checking for.
0 Kudos