Ilogic - create an insert constraint

Ilogic - create an insert constraint

emiliano.alberici
Participant Participant
515 Views
8 Replies
Message 1 of 9

Ilogic - create an insert constraint

emiliano.alberici
Participant
Participant

Hello World

 

i have a simple problem yet the solution seems to elude me.

i have an inventor Assembly, and i need to create an ilogic to constrain it in another assembly.

i did figure how to use the

Components.Add()

 command but the problem is that i need to create a insert constrain whit:

Constraints.AddInsert()

 my problem at the moment is that i need the first half of the AddInsert to be always i geometry defined on the assembli i'm placing down, and the second one needs to be picked by the user.

i've also found the command:

 

ThisApplication.CommandManager.Pick(SelectionFilterEnum.XXXX)

 but even with the guide i canno figure out what to put in place of XXXX to have the same pick filter as the insert constrain.

 

anyone can help me?

0 Likes
516 Views
8 Replies
Replies (8)
Message 2 of 9

Curtis_Waguespack
Consultant
Consultant

@emiliano.alberici , you can use something like this, where the components have the named Edges authored in the part file as shown.

 

Hope that Helps,

Curtis

 

Dim oComponent1 As ComponentOccurrence
oComponent1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter,
"select the 1st component")
Dim oEdge As Edge
oEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter,
"select the 2nd component by edge")

Dim oComponent2 As ComponentOccurrence

oComponent2 = oEdge.Parent.Parent

Constraints.AddInsert("", oComponent1.Name, "Edge0", oComponent2.Name, "Edge1",
axesOpposed := True, lockRotation := True)

 

Curtis_Waguespack_2-1728477138134.png

 

Curtis_Waguespack_0-1728477410378.png

 

 

EESignature

0 Likes
Message 3 of 9

emiliano.alberici
Participant
Participant

First of all thank you for the super fast reply

 

i think i still miss a pice of the puzzle 

Sub main()
	'code not working
	Dim oComponent1 As ComponentOccurrence
	Dim oEdge As Edge
	Dim oComponent2 As ComponentOccurrence
	Dim i As Integer
	
	i = 1
	If ThisApplication.ActiveDocument Is Nothing Or ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
	   	MsgBox ("ERRORE: ESEGUIRE SU UN ASSIEME")
	   	Exit Sub
	End If
	
	'in the future this will be recursive
	Try
		Components.Add("T20022436 - Tappo epdm" & i, "C:\temp\subassembly.iam", position := Nothing, grounded := False, visible := True, appearance := Nothing)		
		oComponent1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Seleziona punto inserimento")
		Constraints.AddInsert("", oComponent1.Name, "Edge0", oComponent2.Name, "Edge1", axesOpposed := True, lockRotation := False)
	
		i=i+1
	Catch
		MsgBox ("errore generale")
	End Try
End Sub

mainly the problem is that i'm tryng to insert an assembly inside another assembly.

so i cannot create an edge entiy in the subassembly i'm positioning.

i wonder if there is a way to define half iMate inside the subassembly and mate it with a picked selection from the user.

0 Likes
Message 4 of 9

emiliano.alberici
Participant
Participant

i think i'm almost there, i had to do some work on both the parts and the code, i have just one more obstacole to overcome.

 

Constraints.AddInsert("", oComponent1.Name, "Edge0", oComponent2.Name, "Edge1",
axesOpposed := True, lockRotation := True)

i need one of the two edges in this command to be indipendent from a fixed name, i need it to be whatever  the user has picked.

but i'm unable to do so.

any idea on how i can do that? am i missing something obvious?

0 Likes
Message 5 of 9

_dscholtes_
Advocate
Advocate

@emiliano.alberici wrote:

i need one of the two edges in this command to be indipendent from a fixed name, i need it to be whatever  the user has picked.

but i'm unable to do so.

any idea on how i can do that? am i missing something obvious?


See lines 4 to 6 in @Curtis_Waguespack 's code example on how to select an edge and get the corresponding component it's in:

 

Dim oEdge As Edge
oEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter,
"select the 2nd component by edge")

Dim oComponent2 As ComponentOccurrence
oComponent2 = oEdge.Parent.Parent

 

Note that in the last line of his code example, where the insert is created, it says Edge1, but that should have been oEdge (why select it and never use it 🙂 ).

0 Likes
Message 6 of 9

emiliano.alberici
Participant
Participant

thanks for the help, but not quite

i've tried that already, my code looks like this now

 

 

Constraints.AddInsert("constranio", {oComp_Nome_occorrenza, nome_guarnizione }, spigolo_inserito, oComp_selezione.Name, Spigolo_selezionato, axesOpposed := True, lockRotation := False)

 

where

  1. "constranio" is just a name for the constrain
  2. the wierd {} is a selection for a subcomponent
  3. spigolo_inserito is a string with the first edge name 
  4. oComp_selezione.Name is the name of the occurrence selected by the user
  5. Spigolo_selezionato is the equivalent of oEdge.

if i try to run that with an Edge item in the spot where "Edge 1" was, i get an error. in that particular argument of AddInsert it seems that a string is needed.

 

this is so frustrating, i feel like i'm missing something simple....

 

I'm also investigating if i can create some sort of "temporary" geometry name on the user selection but no luck so far.

since i'm working at assembly level (which does not allow for the creation of named geometry)

 

i've read this

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=ff3be188-bafe-cd05-a5ec-ba2280d5b9f3 

 

autodesk.png

this last part is haunting me in my sleep.....what does it mean? is there a way to learn this power?

0 Likes
Message 7 of 9

Curtis_Waguespack
Consultant
Consultant

@_dscholtes_  thanks for catching that!

EESignature

0 Likes
Message 8 of 9

emiliano.alberici
Participant
Participant

 

@Curtis_Waguespack @_dscholtes_ 

Sub main()
	Dim oComponent1 As ComponentOccurrence
	oComponent1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter,"select the 1st component")
	Dim oEdge As Edge
	oEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter,
	"select the 2nd component by edge")

	Dim oComponent2 As ComponentOccurrence

	oComponent2 = oEdge.Parent.Parent

	Constraints.AddInsert("", oComponent1.Name, "Edge0", oComponent2.Name, oEdge,axesOpposed := True, lockRotation := True)
End Sub

 

 

i've tried it with oEdge, it results in a comcast error

 

 

System.InvalidCastException: Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di classe 'System.String'. Non è possibile eseguire il cast di istanze di tipi che rappresentano componenti COM in tipi che non rappresentano componenti COM. È tuttavia possibile eseguirne il cast in interfacce, purché il componente COM sottostante supporti le chiamate QueryInterface per l'IID dell'interfaccia.
   in ThisRule.Main() in regola esterna: rule_prova:riga 12
   in Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   in iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

0 Likes
Message 9 of 9

Curtis_Waguespack
Consultant
Consultant

@emiliano.alberici, I think in this case, since you're working with subassemblies and the pick command, using the API function to create an insert, would be preferable over the iLogic function to create an insert. See this example.

 

Hope that helps,

Curtis

 

Dim oEdge1 As Edge
oEdge1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter,
"select the 1st component by edge")

Dim oEdge2 As Edge
oEdge2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter,
"select the 2nd component by edge")

Dim oComponent1 As ComponentOccurrence = oEdge1.Parent.Parent
Dim oComponent2 As ComponentOccurrence = oEdge2.Parent.Parent

Dim EdgeProxy1 As EdgeProxy
oComponent1.CreateGeometryProxy(oEdge1, oEdgeProxy1)

Dim EdgeProxy2 As EdgeProxy
oComponent2.CreateGeometryProxy(oEdge2, oEdgeProxy2)

Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = ThisApplication.ActiveDocument.ComponentDefinition

Call oAssyDef.Constraints.AddInsertConstraint2(oEdge1, oEdge2, True, 0, True)

InventorVb.DocumentUpdate()

 

EESignature

0 Likes