ilogic auto constraints between part and assembly

ilogic auto constraints between part and assembly

henrikubbe4438
Advocate Advocate
1,306 Views
2 Replies
Message 1 of 3

ilogic auto constraints between part and assembly

henrikubbe4438
Advocate
Advocate

Hi All

I am running IV2020 and am trying to automate some constraining.

 

In an assembly i have parts and subassemblies with user workplanes which I want to constrain to user workplanes in the top assembly.

I can get it to work between two parts in the top assembly, but cannot seem to get hold of the top assembly itself.

Preferably I want to be able to (in the code) define which workplanes to use by name, not by number, as this would make it very sensitive in whick order the workplanes are created. 

 

This is what I got so far:

Btw, It is shamelessly copied from these forums, but I lost the name of the creator, sorry!

'This works, but only with two components in the assembly, 
'right now with the other one set as "101153 Fond Sv gardin:1"
'What I want to do is make a constraint between a workplane in one component to a workplane in the top assembly

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim compOcc1 As ComponentOccurrence = 
		ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Pick component")
Dim compOcc2 As ComponentOccurrence = Component.InventorComponent("101153 Fond Sv gardin:1")

Dim oPlane1 As WorkPlane
oPlane1 = compOcc1.Definition.Workplanes("Wpl Mitt")
Dim oPlane2 As WorkPlane
oPlane2 = compOcc2.Definition.Workplanes("Wpl Mitt") 

Dim oproxyPlane1 As WorkPlaneProxy
compOcc1.CreateGeometryProxy(oPlane1, oproxyPlane1)
Dim oproxyPlane2 As WorkPlaneProxy
compOcc2.CreateGeometryProxy(oPlane2, oproxyPlane2)

Dim oConstraint As FlushConstraint
oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oproxyPlane1, oproxyPlane2, 0)

 

 

0 Likes
Accepted solutions (1)
1,307 Views
2 Replies
Replies (2)
Message 2 of 3

R.Mabery
Advocate
Advocate
Accepted solution

I've added two lines for the assembly workplane and changed one of the arguments in your AddFlushConstraint.

 

Dim oAssyPlaneYZ As WorkPlane
oAssyPlaneYZ = oAsmCompDef.WorkPlanes.Item("YZ Plane")

Dim oConstraint As FlushConstraint
oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAssyPlaneYZ, oproxyPlane2, 0)

Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
Message 3 of 3

henrikubbe4438
Advocate
Advocate

Thank you, that did the trick.

 

This is the code in its (temporary) final form:

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim compOcc1 As ComponentOccurrence = 
		ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Pick component")
Dim oPlaneA As WorkPlane
Dim oPlaneB As WorkPlane
Dim oproxyPlaneA As WorkPlaneProxy

Dim dist As Integer
dist = 0.1*(InputBox("Avstånd från Nollan i mm", "Position", "8000"))

Try

'Flush "Wpl Mitt"
oPlaneA = compOcc1.Definition.Workplanes("Wpl Mitt")
oPlaneB = oAsmCompDef.WorkPlanes.Item("Wpl Mitt")
compOcc1.CreateGeometryProxy(oPlaneA, oproxyPlaneA)
i = oAsmCompDef.Constraints.AddFlushConstraint(oproxyPlaneA, oPlaneB, 0)


'Flush Wpl Scengolv
oPlaneA = compOcc1.Definition.Workplanes("Wpl Scengolv")
oPlaneB = oAsmCompDef.WorkPlanes.Item("Wpl Scengolv")
compOcc1.CreateGeometryProxy(oPlaneA, oproxyPlaneA)
i = oAsmCompDef.Constraints.AddFlushConstraint(oproxyPlaneA, oPlaneB, 0)


'Mate Wpl Front-Nolla
oPlaneA = compOcc1.Definition.Workplanes("Wpl Front")
oPlaneB = oAsmCompDef.WorkPlanes.Item("Wpl Nolla")
compOcc1.CreateGeometryProxy(oPlaneA, oproxyPlaneA)
i = oAsmCompDef.Constraints.AddFlushConstraint(oproxyPlaneA, oPlaneB, dist)


Catch
	MessageBox.Show("Kontrollera arbetsplanens namn och riktning", "Oops!")
	
End Try