ilogic add constraints without naming them

ilogic add constraints without naming them

mat_hijs
Collaborator Collaborator
782 Views
2 Replies
Message 1 of 3

ilogic add constraints without naming them

mat_hijs
Collaborator
Collaborator

Is it possible to use the add constraints snippets without having to define the name of the constraints manually? I'd like it to just follow the normal naming scheme, without having to worry about the name.

Accepted solutions (2)
783 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Unfortunately, it's not that simple when done by code alone.  Inventor has several automated actions set-up behind the scenes to make the manual user interface process flow smoothly.  When done by code alone, you loose some of those background helpers, and if you want to simulate similar behavior of supplying the next indexed variation of a default naming scheme, you have to define that naming scheme yourself.  This could be done by extracting the base word from the type of constraint you are adding, and then adding an integer variable at the end.  And each time you create another of that type of constraint, it will add 1 to that previously used integer variable, before adding it to the next name.  This base word, plus integer, would be its own String variable, that is placed at the beginning of those Add() functions, where the name is to be specified.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

J-Camper
Advisor
Advisor
Accepted solution

I don't know abut the supplied snippet functions, but You can create constraints without a custom name if done through API and it will auto generate the names.  I created a auto origin constraining tool, here is the sub routine building the constraints:

Sub FlushOrigins(O1 As ComponentOccurrence, O2 As ComponentOccurrence, aCD As ComponentDefinition)
	On Error GoTo EER
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(aCD.Document, "Constraint Creation")
	'Setup Proxies
	Dim wPlane1 As WorkPlaneProxy
	Dim wPlane2 As WorkPlaneProxy
	'Run for 3 orgin planes:
	For i = 1 To 3
		O1.CreateGeometryProxy(O1.Definition.WorkPlanes.Item(i), wPlane1)
		O2.CreateGeometryProxy(O2.Definition.WorkPlanes.Item(i), wPlane2)
		
		Dim flushConst As AssemblyConstraint = aCD.Constraints.AddFlushConstraint(wPlane1, wPlane2, 0) 
	Next
	oTrans.End
	Exit Sub
EER :
	oTrans.Abort
End Sub

I actually do end up giving them a custom name because I like to identify my automated constraints/joints, but I simply removed that line.  All you need to do is define your parent assembly's Component Definition and the 2 occurrences you want to constrain together in your main sub and then call this routine with the supplied objects:

Sub Main
'Define Assembly Def: ex: parent.ComponentDefinition [where parent is the active assembly
'Define occurrence 1: ex: oOcc1
'Define occurrence 2: ex: oOcc2
'Call Subroutine:
Call FlushOrigins(oOcc1, oOcc2, parent.ComponentDefinition)
End Sub

Let me know if this is helpful, or if you have any questions.

0 Likes