Adding a custom property call parent.

Adding a custom property call parent.

Anonymous
Not applicable
1,265 Views
7 Replies
Message 1 of 8

Adding a custom property call parent.

Anonymous
Not applicable

Is there an iLogic rule that can make a custom property call parent (in every component in an assembly) and automatically fill it out with the parents file name? I would like to run a rule at the top level and drive in the information automatically.

 

For example:

Assembly file name – 1260-01

Subassembly file name – 1260-S20

All parts in the top level including the subassembly will add a custom property call parent and filled out with 1260-01.

All the parts in the subassembly will add a custom property call parent and filled out with 1260-S20.

 

That would help out a lot if anyone could help. It will cause a few problem that I will still need to work out. In the case if a part is in the assembly and subassembly then the custom property call parent, the field would have to have two different names filed in. If anyone has any ideas on how to get around that it would be awesome. If you could only help with one or the other that would be great.

0 Likes
Accepted solutions (2)
1,266 Views
7 Replies
Replies (7)
Message 2 of 8

MechMachineMan
Advisor
Advisor

Just have it fill in a Parent line for each file that is referenced. 

 

You may have fun keeping the parent property up to date if the part is used in a different assembly though, or if the part gets removed/moved/replaced, so you will have to develop some sort of scheme for keeping it up to date.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 8

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi,

 

Here is an example I created. I believe it does something like you are asking for.

 

Sub Main
	
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
	'Iterate through all of the occurrences
	Dim oOccurrence As ComponentOccurrence
	For Each oOccurrence In oAsmCompDef.Occurrences
		
		Call ProcessAllChildren(oOccurrence)
	
	Next

End Sub

Public Sub ProcessAllChildren(ByRef oOccurrence As ComponentOccurrence) 

		' Get the custom property set.
    	Dim invCustomPropertySet As PropertySet
    	invCustomPropertySet = oOccurrence.Definition.Document.PropertySets.Item("Inventor User Defined Properties")
		
		Dim invParentCustProp As Inventor.Property
        
		Try
			'If this fails Parent_Name Property does not exist
			invParentCustProp = invCustomPropertySet.Item("Parent_Name")
			'MessageBox.Show("invParentCustProp Exists" , oOccurrence.Name)

       	Catch
			' Create the property as it did not exist.
			'MessageBox.Show("invParentCustProp Does not Exist" , oOccurrence.Name)
			Try
				' oOccurrence.ParentOccurrence is nothing if it is a top level occurrence
				' ParentOccurence will be the sub assembly the occurrence is in
				invCustomPropertySet.Add(oOccurrence.ParentOccurrence.Definition.Document.DisplayName, "Parent_Name")

			Catch
				'This works if the occurrence is in the top level assembly
				' oOccurrence.Parent.Document.DisplayName
				invCustomPropertySet.Add(oOccurrence.Parent.Document.DisplayName, "Parent_Name")
			End Try

			invParentCustProp = invCustomPropertySet.Item("Parent_Name")
   		 
		End Try
		
		'Update the value for the custom property for this occurrence if it does not already have it
		Try
			Dim strExistingVal As String = invParentCustProp.Value
			If Not strExistingVal.Contains(oOccurrence.ParentOccurrence.Definition.Document.DisplayName) Then 
			' Try to get the ParentOccurrence, this will fail if it is a top level occurrence
			invParentCustProp.Value = strExistingVal & " ; " & oOccurrence.ParentOccurrence.Definition.Document.DisplayName
			'MessageBox.Show("In Try after Occurrence.ParentOccurrence.Definition.Document.DisplayName" , oOccurrence.ParentOccurrence.Definition.Document.DisplayName)
			End If
		Catch
			Dim strExistingVal As String = invParentCustProp.Value
			If Not strExistingVal.Contains(oOccurrence.Parent.Document.DisplayName) Then
			'This works the top level assembly
			invParentCustProp.Value =  strExistingVal & " ; " & oOccurrence.Parent.Document.DisplayName
			End If
		End Try
	
	Dim oCompOcc As ComponentOccurrence
	Dim oComponentSubOccurrences As ComponentOccurrences
'	
    For Each oCompOcc In oOccurrence.SubOccurrences
      
        If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
           oComponentSubOccurrences = oCompOcc.SubOccurrences
		   
		   If Not oComponentSubOccurrences Is Nothing Then
			If oComponentSubOccurrences.count > 0 Then
				ProcessAllChildren(oCompOcc)
			End If
           End If
        Else
            ProcessAllChildren(oCompOcc)
        End If
        
     Next

End Sub

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 4 of 8

Anonymous
Not applicable

Thank you so much for your help. That does exactly what I needed it to do. Is there an easy way to get rid of the .jam in the description?  Thank you again this will be very helpful.  

0 Likes
Message 5 of 8

ekinsb
Alumni
Alumni

I'm glad Wayne's program is working for you.  He's on a well deserved vacation now so I thought I would follow-up with this.  I don't understand what you mean by getting rid of the .jam in the description.  I don't see anything like that.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 8

Anonymous
Not applicable

When it fills in the custom property “Parent_Name” the ext. is part of the description. I was just wounding if there is a way that when looking at the parent file name that it could leave the ext. off. Thanks for any help you could give.

0 Likes
Message 7 of 8

ekinsb
Alumni
Alumni
Accepted solution

Here's a modified version of Wayne's rule that doesn't write out the file extension.

 

Sub Main
	
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
	'Iterate through all of the occurrences
	Dim oOccurrence As ComponentOccurrence
	For Each oOccurrence In oAsmCompDef.Occurrences
		
		Call ProcessAllChildren(oOccurrence)
	
	Next

End Sub

Public Sub ProcessAllChildren(ByRef oOccurrence As ComponentOccurrence) 

		' Get the custom property set.
    	Dim invCustomPropertySet As PropertySet
    	invCustomPropertySet = oOccurrence.Definition.Document.PropertySets.Item(​"Inventor User Defined Properties")
		
		Dim invParentCustProp As Inventor.Property
        
		Try
			'If this fails Parent_Name Property does not exist
			invParentCustProp = invCustomPropertySet.Item("Parent_Name")
			'MessageBox.Show("invParentCustProp Exists" , oOccurrence.Name)

       	Catch
			' Create the property as it did not exist.
			'MessageBox.Show("invParentCustProp Does not Exist" , oOccurrence.Name)
			Try
				' oOccurrence.ParentOccurrence is nothing if it is a top level occurrence
				' ParentOccurence will be the sub assembly the occurrence is in
				Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(oOccurrence.parentOccurrence.Definition.Document.Displayname)
				invCustomPropertySet.Add(filename, "Parent_Name")
			Catch
				'This works if the occurrence is in the top level assembly
				' oOccurrence.Parent.Document.DisplayName
				Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(oOccurrence.Parent.Document.DisplayName)
				invCustomPropertySet.Add(filename, "Parent_Name")
			End Try

			invParentCustProp = invCustomPropertySet.Item("Parent_Name")
   		 
		End Try
		
		'Update the value for the custom property for this occurrence if it does not already have it
		Try
			Dim strExistingVal As String = invParentCustProp.Value
			Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(oOccurrence.ParentOccurrence.Definition.Document.DisplayName)
			If Not strExistingVal.Contains(filename) Then
				' Try to get the ParentOccurrence, this will fail if it is a top level occurrence
				invParentCustProp.Value = strExistingVal & " ; " & filename
				'MessageBox.Show("In Try after Occurrence.ParentOccurrence.Definition.Document.Di​splayName" , oOccurrence.ParentOccurrence.Definition.Document.D​isplayName)
			End If
		Catch
			Dim strExistingVal As String = invParentCustProp.Value
			Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(oOccurrence.Parent.Document.DisplayName)
			If Not strExistingVal.Contains(filename) Then
				'This works the top level assembly
				invParentCustProp.Value =  strExistingVal & " ; " & filename
			End If
		End Try
	
	Dim oCompOcc As ComponentOccurrence
	Dim oComponentSubOccurrences As ComponentOccurrences
'	
    For Each oCompOcc In oOccurrence.SubOccurrences
      
        If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
           oComponentSubOccurrences = oCompOcc.SubOccurrences
		   
		   If Not oComponentSubOccurrences Is Nothing Then
			If oComponentSubOccurrences.count > 0 Then
				ProcessAllChildren(oCompOcc)
			End If
           End If
        Else
            ProcessAllChildren(oCompOcc)
        End If
        
     Next
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 8

Anonymous
Not applicable

Thank you very much for your help. That is exactly what I needed. 

0 Likes