Converting Symbology to a Representation (VB.NET)

Discussion created by ammconsulting on May 15, 2014
Latest reply on May 16, 2014 by ammconsulting

I'm having trouble with converting a feature class to a representation that also converts its symbology to representation rules. I know this is possible within ArcMap. Basically what I'd like to do is to programmatically convert a feature class that is symbolized based on unique values to a representation which then contains a representation rule for each symbolized category.

Following the sample codes given by ESRI, I was able to convert a feature class to a representation that has no representation rules. I then tried to test out ESRI's sample code to convert a marker symbol into a representation symbol and adding this to the representation rules when converting the feature class. However, the marker did not show up in ArcMap (everything was a red square). I have a feeling that this is because the symbol I tried to use was one that we made ourselves and added to the style library as a picture marker symbol.

Unfortunately I'm having trouble finding enough resources to accomplish this myself so if anyone can point me in the right direction, I would really appreciate it! I've included my code below:

 Module Representation
    Public Sub CreateRepClass(ByVal layerName As String)
            Dim pMxDoc As IMxDocument
            Dim pMap As IMap
            Dim pLayer As IFeatureLayer
            Dim pFClass As IFeatureClass
            Dim index As Integer

            'Get the feature class I want to convert:
            pMxDoc = My.ArcMap.Application.Document
            pMap = pMxDoc.FocusMap
            index = FindLayer(layerName)
            pLayer = pMap.Layer(index)
            pFClass = pLayer.FeatureClass

            Dim pDataset As IDataset
            Dim pWorkspace As IWorkspace
            Dim pRepWSExt As IRepresentationWorkspaceExtension
            Dim pRules As IRepresentationRules

            'Get the workspace from the feature class:
            pDataset = pFClass
            pWorkspace = pDataset.Workspace
            pRepWSExt = GetRepWSExt(pWorkspace) 'Get the representation extension using function below

            'Get the representation rules using the function below:
            pRules = ConvertToRepMarker() 'New RepresentationRules

            'Create representation class from feature class and rules:
            pRepWSExt.CreateRepresentationClass(pFClass, pFClass.AliasName + "_Rep", "My_RuleID", "My_Override", True, pRules, Nothing)
        Catch ex As Exception
        End Try
    End Sub

    Public Function GetRepWSExt(ByVal pWorkspace As IWorkspace) As IRepresentationWorkspaceExtension
        Dim pExtManager As IWorkspaceExtensionManager
        Dim pUID As IUID

        'Assign new UID
        pExtManager = pWorkspace
        pUID = New UID
        pUID.Value = "{FD05270A-8E0B-4823-9DEE-F149347C32B6}"

        'Find and return the representation workspace extension
        Dim pRepWSExt As IRepresentationWorkspaceExtension
        pRepWSExt = pExtManager.FindExtension(pUID)

        Return pRepWSExt
    End Function

    Public Function ConvertToRepMarker() As IRepresentationRules
        Dim pRepresentationRules As IRepresentationRules
        Dim pMarker As IMarkerSymbol
        Dim pRepresentationRule As IRepresentationRule
        Dim pRepRuleInit As IRepresentationRuleInit

        'Create new representation rules:
        pRepresentationRules = New RepresentationRules

        'Find the symbol from the style library using a function
        'This function has been tested before and works
        pMarker = FindSymbol("MarkerName", "Category")

        'Create new representation rule:
        pRepresentationRule = New RepresentationRule
        pRepRuleInit = pRepresentationRule
        pRepRuleInit.InitWithSymbol(pMarker)    'Convert marker symbol to representation

        'Give the rule a name:
        Dim ID As Long
        ID = pRepresentationRules.Add(pRepresentationRule)
        pRepresentationRules.Name(ID) = "TestRule"

        'Return the representation rules:
        Return pRepresentationRules
    End Function
End Module