Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: Need Assistance in VBA Code

$
0
0

  Hi All,

I have amended the code.  What I want to do is if selected element have a specific Family + Part then replace with new Part.  I am getting a runtime error.  If anyone can help me to fix this issue it would be a great help.  

Option Explicit

Public Sub UpdateParts()

Dim partRefNode As TFPartRefList
Dim oEnumerator As ElementEnumerator
Dim oFamily As String
Dim oPart As String
Dim oNewFamily As String
Dim oNewPart As String
Dim oNewLayer As String
Dim oNewColor As Integer

oFamily = "A1010"
oPart = "A1012_WALL"
oNewFamily = "A1010"
oNewPart = "A1012_BEAM"
oNewLayer = "New Layer"
oNewColor = 6

Set oEnumerator = ActiveModelReference.GetSelectedElements

Do While oEnumerator.MoveNext
    MsgBox "Type: " & oEnumerator.Current.Type
    Dim elm As TFElement
    Dim elmNode As New TFElementList
    Dim formRecipeList As TFFormRecipeList
    Dim formRecipe As TFFormRecipe
    Dim oElement As Element

    elmNode.InitFromElement oEnumerator.Current
    Set elm = elmNode

    Dim eFamily As String
    Dim ePart As String
    Dim ePartRefList As TFPartRefList
    Dim ePartList As TFPartList
    Set ePartRefList = elm.GetPartRef


    If Not ePartRefList Is Nothing Then

        Dim ePartRef As TFPartRef
        Set ePartRef = ePartRefList

        If ePartRef.IsResolvable Then
                ePartRef.GetPart ePartList
                ePartList.AsTFPart.GetFamilyName eFamily
                ePartList.AsTFPart.GetName ePart

                If eFamily = oFamily And ePart = oPart Then 'Old part and new specified Family+Part are the same
                    ePartRef.SetPartName oNewPart
                    elm.SetPartRef ePartRef
                    If elm.GetIsFormType() Then
                        elm.GetFormRecipeList formRecipeList
                        Set formRecipe = formRecipeList.AsTFFormRecipe'formRecipe.SetLevel oNewLayer'formRecipe.SetColor oColor
                        TFApplication.ModelReferenceRewriteFormRecipe ActiveModelReference, formRecipe
                        TFApplication.ModelReferenceRewriteFormRecipeList ActiveModelReference, formRecipeList
                    Else
                        elm.GetElement oElement'Set oElement.Level = oNewLayer'oElement.Color = oColor
                        oElement.Rewrite
                    End If

                End If

        End If
    End If

Loop

TFApplication.SynchronizePartUI True

End Sub

Regards,

Benjamin

Viewing all articles
Browse latest Browse all 7260

Trending Articles