Attributes & iParts

Often we need to access attributes and attribute sets in an iPart Child component.  Unfortunately, attributes that you create in the iPart Factory do not carry over to the children.

Thankfully, we can still get to those attributes through automation.  This involves using the Inventor API but this code can be ran in iLogic just as if it was using the iLogic Snippets.

This code is only looking at Faces and Workplanes but that can be expanded upon to look at other entities.  

The full code is listed at the bottom of this post.  I'll break down what it's doing:

The main sub gets the iPart Child occurrence that is used in your assembly and passes that to the CopyAttributes subroutine.

The CopyAttributes subroutine:

  1. Gets the Factory document from the occurrence
  2. Loops through all the faces/workplanes in the Factory document
  3. If it finds an attribute set, then it creates the same attribute set on the corresponding entity of the Child occurrence.

These attributes can be used for finding entities (think of the times that you select a face or a workplace while in an assembly).  One of the more common reasons I use them is for creating constraints.

Sub Main()
	
	' Get occurrence
	Dim oOcc as ComponentOccurrence
	oOcc = Component.InventorComponent("BrowserName")

	' Copy attributes
	CopyAttributes(oOcc)

End Sub


Public Sub CopyAttributes(oOcc As ComponentOccurrence)

	' Declarations
	Dim oOccFaces As Faces
	oOccFaces = oOcc.SurfaceBodies.Item(1).Faces
	
	Dim oOccWorkPlanes as Workplanes
	oOccWorkPlanes = oOcc.Definition.Workplanes 

	Dim oFactoryDoc As PartDocument
	oFactoryDoc = oOcc.Definition.iPartMember.ParentFactory.Parent

	Dim oNativeFaces As Faces
	oNativeFaces = oFactoryDoc.ComponentDefinition.SurfaceBodies.Item(1).Faces
	
	Dim oNativeWorkPlanes As Workplanes
	oNativeWorkPlanes = oFactoryDoc.ComponentDefinition.Workplanes 

	' Loop thru faces in factory and copy
	Dim i As Long

	For i = 1 To oNativeFaces.Count
		Dim oFaceProxy As Face
		oFaceProxy = oOccFaces.Item(i)

		Dim oAttributeSet As AttributeSet

		For Each oAttributeSet In oNativeFaces(i).AttributeSets
			' Delete if existing
			If oFaceProxy.AttributeSets.NameIsUsed(oAttributeSet.Name) Then
				oFaceProxy.AttributeSets(oAttributeSet.Name).Delete
			End If
			
			Dim oNewAttSet As AttributeSet
			oNewAttSet = oFaceProxy.AttributeSets.Add(oAttributeSet.Name)
		Next
	Next
	
	For i = 1 To oNativeWorkPlanes.count
		Dim oWPProxy As WorkPlane
		oWPProxy = oOccWorkPlanes.item(i)

		Dim oAttributeSet As AttributeSet

		For Each oAttributeSet In oNativeWorkPlanes(i).AttributeSets
			' Delete if existing
			If oWPProxy.AttributeSets.NameIsUsed(oAttributeSet.name) Then
				oWPProxy.AttributeSets(oAttributeSet.name).Delete
			End If

			Dim oNewAttSet As AttributeSet
			oNewAttSet = oWPProxy.AttributeSets.Add(oAttributeSet.name)
		Next
	Next

End Sub

 

About the Author

Randall Mabery

I love the technology, thoroughly enjoy helping people find solutions and believe in the software. I train individuals in the use of Autodesk design software such as Inventor and AutoCAD. The most satisfying part of my job is working on automation solutions for clients, assisting them in streamlining their design process and automating tasks.

Follow on Linkedin More Content by Randall Mabery
Previous Video
Developing Inventor Assemblies with iLogic
Developing Inventor Assemblies with iLogic

Explore the different methodologies for populating an assembly with iLogic to help you determine the best o...

Next Article
Inventor Frame Generator: G_L Parameter Becomes Disassociated After Removing End Treatments
Inventor Frame Generator: G_L Parameter Becomes Disassociated After Removing End Treatments

Inventor Frame Generator: G_L Parameter Becomes Disassociated After Removing End Treatments. This provides ...

Streamline Manual Processes with Automation

Learn More