Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic code tweak on creating viewreps

1 REPLY 1
Reply
Message 1 of 2
DClunie1
268 Views, 1 Reply

Ilogic code tweak on creating viewreps

Hi All

 

I am after some help converting code to do something different on how this runs.

 

Code attached searches a custom property we have embedded within our Inventor oarts and if found creates a viewe rep and locks down that view.

 

The code workd great and does the job but i need the browsr node name to be different as it copies file name and places it there for its name.And I would like the code to work exactly the same but to give viewrep the name the Description of the part instead.

 

Appreciated if someone can show me the teak i need to enables this to work.

 

 

SyntaxEditor Code Snippet

Sub Main
Dim propertyName As String = "DESC2"
Dim propertyValue As String = "BEVEL/"
Dim propertyValue2 as String = "ROUT/WRAP/"
Dim propertyValue3 as String = "ROUT/"
Dim propertyValue4 as String = "NOTCH/"
Dim propertyValue5 as String = "HP/"
Dim propertyValue6 as String = "HINGE/"
Dim propertyValue7 as String = "SLOT/"
Dim propertyValue8 as String = "ROUT/WRAP/HINGE/"


Dim oDoc As Inventor.AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    
Dim oCompDef As Inventor.ComponentDefinition
    oCompDef = oDoc.ComponentDefinition

'define view rep 
Dim oViewRep As DesignViewRepresentation
'define an arraylist to hold the list of  view rep names
Dim NameList As New ArrayList()
'Look at the view reps in the assembly
For Each oViewRep In oCompDef.RepresentationsManager.DesignViewRepresentations
    'set the list of names to the array list
    NameList.add(oViewRep.Name)
Next

Dim oCompOcc as ComponentOccurrence
Dim oCompOcc2 as ComponentOccurrence
    For Each oCompOcc In oCompDef.Occurrences
        If oCompOcc.SubOccurrences.Count = 0 Then
        '[
        Try
            OCompOccName = oCompOcc.Name
            If iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue2 _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue3 _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue4 _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue5 _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue6 _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue7 _
            Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue8 Then
                'check for a Test view rep and create it if not found
                If Not NameList.Contains(OCompOccName) Then
                    'create Test view rep 
                    oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Add(OCompOccName) 
                    oViewRep.ShowAll
                    oViewRep.Activate
                Else
                    'reference existing View Rep 
                    oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Item(OCompOccName) 
                    oViewRep.Activate
                    oViewRep.Locked = False
                    oViewRep.ShowAll
                End If
                For Each oCompOcc2 In oCompDef.Occurrences
                    Dim oCompOcc2Name As String
                    oCompOcc2Name = oCompOcc2.Name
                    If oCompOcc2.SubOccurrences.Count = 0 Then
                        If oCompOcc2Name = oCompOccName Then
                        oCompOcc2.Visible = True
                        'MessageBox.Show(oCompOcc2Name, "Visible")
                        ThisApplication.ActiveView.Update()
                        Else
                        oCompOcc2.Visible = False
                        'MessageBox.Show(oCompOcc2Name, "Not Visible")
                        ThisApplication.ActiveView.Update()
                        End If
                    Else
                        processSubOcc(oCompOcc2, oCompOccName)
                    End If
                Next
                'lock view rep
                oViewRep.Locked = True
                'messagebox.Show("View locked", "Done")
            End If
        Catch ex As exception
        End Try
        ']
        Else
        processAllSubOcc(oCompDef, oCompOcc, NameList, propertyName, propertyValue, propertyValue2, propertyValue3, propertyValue4, propertyValue5, propertyValue6, propertyValue7, propertyValue8 )
        End If
    Next
    'Master
oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default")
oViewRep.Activate
End Sub

' This function is called for processing sub assembly. It is called recursively' to iterate through the entire assembly tree.
 Sub processAllSubOcc(ByVal oCompDef as ComponentDefinition, ByVal oCompOcc As ComponentOccurrence, ByVal NameList As ArrayList, ByRef propertyName As String,ByRef propertyValue As String, ByRef propertyValue2 as String,ByRef propertyValue3 as String,ByRef propertyValue4 as String,ByRef propertyValue5 as String,ByRef propertyValue6 as String,ByRef propertyValue7 as String,ByRef propertyValue8 as String)
    Dim oSubCompOcc As ComponentOccurrence

    For Each oSubCompOcc In oCompOcc.SubOccurrences
        If oSubCompOcc.SubOccurrences.Count = 0 Then
        '[
        Try
            oSubCompOccName = oSubCompOcc.Name
            If iProperties.Value(oSubCompOccName ,"Custom",propertyName ) = propertyValue Or iProperties.Value(oSubCompOccName ,"Custom",propertyName ) = propertyValue2 Then
                'check for a Test view rep and create it if not found
                If Not NameList.Contains(OSubCompOccName) Then
                    'create Test view rep 
                    oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Add(OSubCompOccName) 
                    oViewRep.ShowAll
                    oViewRep.Activate
                Else
                    'reference existing View Rep 
                    oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Item(OSubCompOccName) 
                    oViewRep.Activate
                    oViewRep.Locked = False
                    oViewRep.ShowAll
                End If
                For Each oCompOcc2 In oCompDef.Occurrences
                    Dim oCompOcc2Name As String
                    oCompOcc2Name = oCompOcc2.Name
                    If oCompOcc2.SubOccurrences.Count = 0 Then
                        If oCompOcc2Name = oSubCompOccName Then
                        oCompOcc2.Visible = True
                        ThisApplication.ActiveView.Update()
                        Else
                        oCompOcc2.Visible = False
                        ThisApplication.ActiveView.Update()
                        End If
                    Else
                        processSubOcc(oCompOcc2, oSubCompOccName)
                    End If
                Next
                'lock view rep
                oViewRep.Locked = True
            End If
        Catch ex As exception
        End Try
        ']
        Else
        processAllSubOcc(oCompDef, oCompOcc, NameList, propertyName, propertyValue, propertyValue2, propertyValue3, propertyValue4, propertyValue5, propertyValue6, propertyValue7, propertyValue8)
        End If
    Next
    
End Sub

 Sub processSubOcc(ByVal oCompOcc As ComponentOccurrence, _
                             ByRef oCompOccName As String)
    Dim oSubCompOcc As ComponentOccurrence

    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
        Dim oSubCompOccName As String
        oSubCompOccName = oSubCompOcc.Name
        If oSubCompOcc.SubOccurrences.Count = 0 Then
            If oSubCompOccName = oCompOccName Then
            oSubCompOcc.Visible = True
            ThisApplication.ActiveView.Update()
            Else
            oSubCompOcc.Visible = False
            ThisApplication.ActiveView.Update()
            End If
        Else
            processSubOcc(oSubCompOcc, oCompOccName)
        End If
    Next
End Sub 

 

 

 

 

 

 

1 REPLY 1
Message 2 of 2
Vladimir.Ananyev
in reply to: DClunie1

If you are able to get the information for the new name then the rest is quite easy.

You should change the Name property of the DesignViewRepresentation object:

Dim oViewReps As DesignViewRepresentations
Set oViewReps = oAsmDef.RepresentationsManager.DesignViewRepresentations
Dim vr As DesignViewRepresentation
'get the existing design view representation by its current name
Set vr = oViewReps.Item("OldName")
'change name
vr.Name = "NewNameFromDescription"

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report