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: 

Using iLogic to Rename Browser Nodes

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
Anonymous
10571 Views, 18 Replies

Using iLogic to Rename Browser Nodes

I'm looking for some help figuring out how to create an iLogic rule that automatically renames the browser nodes based on part number.  I know that this is a function in Inventor itself.  The problem is that there is no built-in functionality to automatically change the default browser name to something besides part number.  I've done a lot of digging and I came across the following code from an old thread discussing Inventor 2011.  I am interested in 2013.  It is also worth noting that when I run this code, my Inventor crashes.  

 

If someone knows more about programming than I do and can get this to work, it would be much appreciated.

 

 

 

PrivateSubMain
UpdateAssyBrowser(ThisDoc.Document)
End Sub

PrivateSubUpdateAssyBrowser(ByValoDocAsInventor.Document)
DimoAssyAsInventor.AssemblyDocument
DimoCompAsInventor.ComponentOccurrence
DimoSubDocAsInventor.Document

DimNodeName()AsString
DimInstNumAsString

IfoDoc.DocumentType=Inventor.DocumentTypeEnum.kAssemblyDocumentObjectThen
oAssy=CType(oDoc, AssemblyDocument)

ForEachoCompInoAssy.ComponentDefinition.Occurrences
oSubDoc=CType(oComp.Definition.Document, Document)
NodeName=oComp.Name.Split(NewChar() {":"c}, StringSplitOptions.None)
InstNum=":"&NodeName(1)
oComp.Name=GetProp(oSubDoc, "Design Tracking Properties", "Part Number")&InstNum

IfoSubDoc.DocumentType=Inventor.DocumentTypeEnum.kAssemblyDocumentObjectThen
CallUpdateAssyBrowser(oSubDoc)
EndIf

NextoComp
EndIf
End Sub

PrivateFunctionGetProp(ByValoDocAsInventor.Document, ByValPropSetNameAsString, ByValPropNameAsString)AsString
DimoPropSetAsInventor.PropertySet
DimsHoldAsString=""

oPropSet=oDoc.PropertySets(PropSetName)

DimoPropAsInventor.Property

ForEachoPropInoPropSet
IfoProp.DisplayName="Part Number"Then
sHold=CStr(oProp.Value)
ExitFor
EndIf
NextoProp

ReturnsHold
End Function

18 REPLIES 18
Message 2 of 19
GosponZ
in reply to: Anonymous
Message 3 of 19
Anonymous
in reply to: Anonymous

Here you go. Please let me know if you have any questions on how this works:

 

Sub Main()

'Grab the Assembly Document

Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument 'Grab the Active Assembly Component Definition

Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Get the model browser

Dim oPane As BrowserPane oPane = oDoc.BrowserPanes.Item("Model") ' Grab the occurrence of the object Dim oOcc As ComponentOccurrence For Each oOcc In oDoc.ComponentDefinition.Occurrences 'Grab Document from Occurrence

Dim oOccDoc As Document oOccDoc = oOcc.Definition.Document 'get design properties set'

Dim invDesignInfo As PropertySet invDesignInfo = oOccDoc.PropertySets.Item("Design Tracking Properties") ' Get the part number property.

Dim invPartNumberProperty As Inventor.Property invPartNumberProperty = invDesignInfo.Item("Part Number") ' Get the browser node that corresponds to the new item

Dim oSubAssyNode As BrowserNode oSubAssyNode = oPane.GetBrowserNodeFromObject(oOcc) If oSubAssyNode.NativeObject.Name <> invPartNumberProperty.Value Then 'Set The name
oSubAssyNode.NativeObject.Name = (invPartNumberProperty.Value) End If Next End Sub
Message 4 of 19
Anonymous
in reply to: Anonymous

That code looks like it works better, the only problem there is that it doesn't detect the instance number, so when I have

 

part001:1 

part001:2 

 

I get an error if I try to run the rule.  I appreciate the help!  

Message 5 of 19
Anonymous
in reply to: Anonymous

What would you like it to do in that case?

Message 6 of 19
Anonymous
in reply to: Anonymous

I would like to be able to maintain the instance number as is in Inventor so that the above example would be

 

partnumber001:1

partnumber001:2

 

Message 7 of 19
Anonymous
in reply to: Anonymous

That shouldn't be too hard. You just need to check if a name already exists and add :X to the end where X is the most recent instance +1. I'm out of time today but I might be able to whip that up in the next few days. 

Message 8 of 19
Anonymous
in reply to: Anonymous

Alright I got it after playing with it a little bit.  I added the appropriate code and it works perfectly.  I really appreciate your help! 

    Dim NodeName() As String
    NodeName=oOcc.Name.Split( {":"c},StringSplitOptions.None)
    InstNum=":" & NodeName(1)
Message 9 of 19
Anonymous
in reply to: Anonymous

Hi

 

Is it possible to get your full working code ? I can't get this to work...

 

Borre

Message 10 of 19
Anonymous
in reply to: Anonymous

I have the code set to iterate through the active assembly and rename all non standard content Center components based on Description. 

 

As a disclaimer, this code will not count unique occurrences for components.

 

 

Message 11 of 19
GosponZ
in reply to: Anonymous

Working perfect on my machine. I'm working with multi sheets.

 

oDoc = ThisDoc.Document

oSheets = oDoc.Sheets

      For Each oSheet In oSheets

            oSheet.activate

            oView = oSheet.DrawingViews.Item(1)

            modelName = oView.ReferencedDocumentDescriptor.ReferencedDocument

            oProp = modelName.PropertySets.Item("Design Tracking Properties")

            ActiveSheet.Sheet.Name = oProp.Item("Part Number").Value & " " & oProp.Item("Description").Value & " " & oProp.Item("Authority").Value

 

      Next

oSheets(1).activate

Message 12 of 19
Anonymous
in reply to: Anonymous

Thank's a lot. I can see where I failed, but my skills was not good enough to figure it out myself. This works perfect. Thank you again.

Message 13 of 19
Nsteel
in reply to: Anonymous

Can someone please help,

I have modified this script to rename the nodes as "Part Number - Revision Number"

There is an assembly file in it I don't want it to change, could somone show me what to add and so it skips over this one?

The node name for this file is "02002.Tube and Pipe Runs"

 

Thanks in advance.

Message 14 of 19
J.Classens
in reply to: Anonymous

I have a quastion about this old post.

 

When i want to customize the rule with other properties. 

It will fail and not work again. 

 

original:

    ' Get the part number property.
    Dim invPartNumberProperty As Inventor.Property
    invPartNumberProperty = invDesignInfo.Item("Description")
	

The description i want to change to multiple properties like Partnumber, description, title.

I can't get it to work like that. 

 

Any suggestions? 

 

Further i noticed that this rule only work at the first level from the BOM structure. 

The only childeren from assemblies doesn't update. 

 

I don't know how we can edit this. 

 

Thanks in advance!  

Message 15 of 19

Any solution on this problem?

Message 16 of 19

I have found a Ilogic rule to do the trick.

This Ilogic rule i have modified with the needed properties.

 

When you want to use VBA you write a code that opens this Ilogic rule. 

 

Sub Main
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim i As Integer = 0
	For Each oOcc As ComponentOccurrence In oADef.Occurrences
		SetOccName(oOcc, i)
		i = i + 1
	Next
End Sub

Sub SetOccName(oComp As ComponentOccurrence, oInt As Integer)
	Dim oOccDoc As Document = oComp.Definition.Document
	Dim oPSets As PropertySets = oOccDoc.PropertySets
	Dim oPNEmpty As Boolean = False
	Dim oArticleNoEmpty As Boolean = False
	Dim oTitleEmpty As Boolean  = False
	Dim oPN As String = oPSets.Item(3).Item("Part Number").Value
	If String.IsNullOrEmpty(oPN) Then oPNEmpty = True Else oPNEmpty = False
	Dim oTitle As String = oPSets.Item(1).Item("Title").Value
	If String.IsNullOrEmpty(oTitle) Then oTitleEmpty = True Else oTitleEmpty = False
	Dim oArticleNo As String
	Try
		'the custom iProperty may not exist, so use Try...Catch block to check it
		oArticleNo = oPSets.Item(4).Item("Article No").Value
	Catch
		'above failed, so it was not found
		'create it, or ignore it, or show a message
	
	End Try
	If String.IsNullOrEmpty(oArticleNo) Then oArticleNoEmpty = True Else oArticleNoEmpty = False
		
	Dim oNewName As String = "" 'to assemble name in variable first (no errors expected)
	'could just set it up so that if any are missing or empty, skip trying to rename this component to simplify
	'If oPNEmpty Or oArticleNoEmpty Or oTitleEmpty Then Continue For 'skip to next item in loop
	If oPNEmpty = False And oArticleNoEmpty = False And oTitleEmpty = False Then 'all present
		oNewName = oPN & " (" & oArticleNo & " " & oTitle & ")" & "-" & oInt
	ElseIf oPNEmpty = False And oArticleNoEmpty = True And oTitleEmpty = False Then 'ArticleNo missing
		oNewName = oPN & " (" & oTitle & ")" & "-" & oInt
	ElseIf oPNEmpty = True And oArticleNoEmpty = False And oTitleEmpty = False Then 'PN missing
		oNewName = "(" & oArticleNo & " " & oTitle & ")" & "-" & oInt
	ElseIf oPNEmpty = False And oArticleNoEmpty = False And oTitleEmpty = True Then 'Title missing
		oNewName = oPN & " (" & oArticleNo & ")" & "-" & oInt
	ElseIf oPNEmpty = True And oArticleNoEmpty = False And oTitleEmpty = True Then 'PN & Title missing
		oNewName = "(" & oArticleNo & ")" & "-" & oInt
	ElseIf oPNEmpty = False And oArticleNoEmpty = False And oTitleEmpty = True Then 'ArticleNo & Title missing
		oNewName = oPN & "-" & oInt
	End If
		
	Try 'just in case changing component name fails
		oComp.Name = oNewName
	Catch
		
	End Try
	
	'reset all String variables to empty (very likely not necessary, but we'll see)
	oNewName = ""
	oPN = ""
	oArticleNo = ""
	oTitle = ""
		
	If oComp.SubOccurrences.Count > 0 Then 'if it has any SubOccurrences, it's a sub-assembly
		For Each oSOcc As ComponentOccurrence In oComp.SubOccurrences
			SetOccName(oSOcc, oInt)
		Next
	End If
End Sub
Message 17 of 19

I have found a Ilogic rule to do the trick.

This Ilogic rule i have modified with the needed properties.

 

When you want to use VBA you write a code that opens this Ilogic rule. 

 

Sub Main
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim i As Integer = 0
	For Each oOcc As ComponentOccurrence In oADef.Occurrences
		SetOccName(oOcc, i)
		i = i + 1
	Next
End Sub

Sub SetOccName(oComp As ComponentOccurrence, oInt As Integer)
	Dim oOccDoc As Document = oComp.Definition.Document
	Dim oPSets As PropertySets = oOccDoc.PropertySets
	Dim oPNEmpty As Boolean = False
	Dim oArticleNoEmpty As Boolean = False
	Dim oTitleEmpty As Boolean  = False
	Dim oPN As String = oPSets.Item(3).Item("Part Number").Value
	If String.IsNullOrEmpty(oPN) Then oPNEmpty = True Else oPNEmpty = False
	Dim oTitle As String = oPSets.Item(1).Item("Title").Value
	If String.IsNullOrEmpty(oTitle) Then oTitleEmpty = True Else oTitleEmpty = False
	Dim oArticleNo As String
	Try
		'the custom iProperty may not exist, so use Try...Catch block to check it
		oArticleNo = oPSets.Item(4).Item("Article No").Value
	Catch
		'above failed, so it was not found
		'create it, or ignore it, or show a message
	
	End Try
	If String.IsNullOrEmpty(oArticleNo) Then oArticleNoEmpty = True Else oArticleNoEmpty = False
		
	Dim oNewName As String = "" 'to assemble name in variable first (no errors expected)
	'could just set it up so that if any are missing or empty, skip trying to rename this component to simplify
	'If oPNEmpty Or oArticleNoEmpty Or oTitleEmpty Then Continue For 'skip to next item in loop
	If oPNEmpty = False And oArticleNoEmpty = False And oTitleEmpty = False Then 'all present
		oNewName = oPN & " (" & oArticleNo & " " & oTitle & ")" & "-" & oInt
	ElseIf oPNEmpty = False And oArticleNoEmpty = True And oTitleEmpty = False Then 'ArticleNo missing
		oNewName = oPN & " (" & oTitle & ")" & "-" & oInt
	ElseIf oPNEmpty = True And oArticleNoEmpty = False And oTitleEmpty = False Then 'PN missing
		oNewName = "(" & oArticleNo & " " & oTitle & ")" & "-" & oInt
	ElseIf oPNEmpty = False And oArticleNoEmpty = False And oTitleEmpty = True Then 'Title missing
		oNewName = oPN & " (" & oArticleNo & ")" & "-" & oInt
	ElseIf oPNEmpty = True And oArticleNoEmpty = False And oTitleEmpty = True Then 'PN & Title missing
		oNewName = "(" & oArticleNo & ")" & "-" & oInt
	ElseIf oPNEmpty = False And oArticleNoEmpty = False And oTitleEmpty = True Then 'ArticleNo & Title missing
		oNewName = oPN & "-" & oInt
	End If
		
	Try 'just in case changing component name fails
		oComp.Name = oNewName
	Catch
		
	End Try
	
	'reset all String variables to empty (very likely not necessary, but we'll see)
	oNewName = ""
	oPN = ""
	oArticleNo = ""
	oTitle = ""
		
	If oComp.SubOccurrences.Count > 0 Then 'if it has any SubOccurrences, it's a sub-assembly
		For Each oSOcc As ComponentOccurrence In oComp.SubOccurrences
			SetOccName(oSOcc, oInt)
		Next
	End If
End Sub
Message 18 of 19
benjamin.eidemL3D38
in reply to: Anonymous

Thank you! I have used the rule with great success, but recently got an error message:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.get_Definition()
at ThisRule.SetOccName(ComponentOccurrence oComp, Int32 oInt)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Any idea on what's wrong here?

 

(PS! No "expert" in iLogic and coding 😅)

Message 19 of 19

Thank you! I have used the rule with great success, but recently got an error message:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.get_Definition()
at ThisRule.SetOccName(ComponentOccurrence oComp, Int32 oInt)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Any idea on what's wrong here?

 

(PS! No "expert" in iLogic and coding 😅)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report