iLogic or VBA: Name Faces of Parts Based on Orientation in Assembly

iLogic or VBA: Name Faces of Parts Based on Orientation in Assembly

el_jefe_de_steak
Collaborator Collaborator
1,200 Views
4 Replies
Message 1 of 5

iLogic or VBA: Name Faces of Parts Based on Orientation in Assembly

el_jefe_de_steak
Collaborator
Collaborator

Hi, I'm wondering if there is a way to use iLogic or VBA to name faces of parts based on their orientation in an assembly. 

 

Use case: Naming a face of a beam "tag end" based on which end is farther away from the YZ or XY plane in an assembly. Our company would like to use named faces to create drawing notes for tagging parts, and would like them to always get tagged on a certain end based on how the parts are assembled.

0 Likes
Accepted solutions (1)
1,201 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Perhaps something along these lines?

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("THIS RULE '" & iLogicVb.RuleName & "' ONLY WORKS FOR ASSEMBLY DOCUMENTS.", "WRONG DOCUMENT TYPE", MessageBoxButtons.OK, MessageBoxIcon.Stop)
	Return
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oNamedFaces = ThisDoc.NamedEntities
Dim oOrigPlane As WorkPlane = oADef.WorkPlanes.Item(1)
Dim oUVector As UnitVector = oOrigPlane.Plane.Normal

Dim oOccs As ComponentOccurrences = oADef.Occurrences

For Each oOcc As ComponentOccurrence In oOccs
	If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDef As PartComponentDefinition = oOcc.Definition
		If oPDef.HasMultipleSolidBodies = False Then
			Dim oParams() As Double
			Dim oNormals() As Double
			For Each oFace As Face In oPDef.SurfaceBodies(1).Faces 'Assumes it't not MultiBody
				If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
					'oFace.Evaluator.GetNormal(oParams, oNormals)
					'If oParams(1).Equals(obj)
					'Then somehow compare this info to the Normal of your origin plane
					'End If
					If oOrigPlane.Plane.IsParallelTo(oFace) = True Then
						If oNamedFaces.NameExists(oFaceName) = False Then
							oNamedFaces.SetName(oFace,oFaceName)
						End If	
					End If
				End If
			Next
		End If
	End If
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

el_jefe_de_steak
Collaborator
Collaborator

Thanks, @WCrihfield I believe this would work to find and name faces that are "parallel".

 

The real issue is that now I would like to go one step beyond that and compare which parallel face of a given part has a greater X or Z location in relation to the origin planes of the assembly. Assuming that the face that has the greater value would get the name.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

True.  This is just a step in that general direction.  You could get the oFace.PointOnFace, then compare either the X,Y, or Z values of that point with the Origin Point.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

el_jefe_de_steak
Collaborator
Collaborator

Thanks. That gets me going!

0 Likes