Constrain part origins to assembly origins in assembly file

Constrain part origins to assembly origins in assembly file

lmc.engineering
Advocate Advocate
294 Views
0 Replies
Message 1 of 1

Constrain part origins to assembly origins in assembly file

lmc.engineering
Advocate
Advocate

Hopefully some of you may find this useful:

 

Something that has bugged me for a while when working with skeletal modelling, is having to manually constrain each part to the origins when placing parts in to an assembly. I have a rule that will take ALL parts and constrain them, but if I needed to add more to the assembly, I would have to do this process manually as it would duplicate constraints on anything already in there. This rule solves that issue. Pick your part and it will constrain for you. 

Enjoy!

 

SyntaxEditor Code Snippet

Sub Main()
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPlane As WorkPlane
Dim oProxyPlane As WorkPlaneProxy
Dim oPart As ComponentOccurrence
Line1 :
'''Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,"Select Part") 
	For i = 1 To 3		
    	oPlane = oPart.Definition.WorkPlanes.Item(i)
		'create component proxy plane in assembly		
   		Call oPart.CreateGeometryProxy(oPlane, oProxyPlane)	
	'get assembly plane
	Dim oPlane2 As WorkPlane
	oPlane2 = oAsmCompDef.WorkPlanes.Item(i)	
	' Create the constraint using the work plane proxies.
    Call oAsmCompDef.Constraints.AddFlushConstraint(oProxyPlane, oPlane2, 0)
Next i
'''Ask question to repeat command
Question = MessageBox.Show("Repeat Command?", "Constrain Part to Origins", MessageBoxButtons.OKCancel)
	If Question = vbOK Then
		''Repeat command
		GoTo Line1
	Else
		'''Do Nothing
	End If
End Sub

 

 

295 Views
0 Replies
Replies (0)