Community
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