Is there a way that will allow me to place a component into an assembly where it automatically creates a constrain between the components xz plane and the assembly xz plane? I tried the Ground and root component, but it does too much, I will need to constrain the component differently on the other component planes.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi dfitting,
What version of Inventor are you using?
Are you open to an iLogic solution?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Im using Inventor 2013, I am open to any solution. Being able to place them already on the xz plane will save me tons of time everyday!
Hi dfitting,
Here's an iLogic rule to try.
If you've not used iLogic rules before here are some links to get you started:
http://inventortrenches.blogspot.com/2012/01/creating-basic-ilogic-rule-with-event.html
http://autodeskmfg.typepad.com/blog/2012/01/working-with-external-ilogic-rules.html
Note that I would make this an external rule, so that it is always avaliable for use.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'get file to place
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.DialogTitle = "Select a File"
oFileDlg.InitialDirectory = ThisDoc.Path
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
MessageBox.Show("File not chosen.", "Dialog Cancellation")
Return
ElseIf oFileDlg.FileName <> "" Then
oFile = oFileDlg.FileName
End If
' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create a matrix.
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
'place an instance of the component
Dim oOccurrence As ComponentOccurrence
oOccurrence = oAsmCompDef.Occurrences.Add(oPath & oFile, oMatrix)
' Set the translation portion of the matrix so the part will be
'positioned at the co-ordinates
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))
'check for grounded component, such as the first component in the assembly
If oOccurrence.Grounded = True Then
oGrounded = MessageBox.Show("Should this component be grounded?", _
"iLogic",MessageBoxButtons.YesNo)
If oGrounded = vbNo Then
oOccurrence.Grounded = False
Else
End If
End If
'Get the plane from the selected part.
' The work plane obtained is in the context of the part, not the assembly.
Dim oPartPlane1 As WorkPlane
oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(2) 'Component XZ Plane
'oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(3) 'Component XY Plane
'Get the plane from the assembly
Dim oAsmPlane1 As WorkPlane
oAsmPlane1 = oAsmCompDef.WorkPlanes.Item(2) 'Assembly XZ Plane
'oAsmPlane1 = oAsmCompDef.WorkPlanes.Item(3) 'Assembly XY Plane
' Create proxies for the work planes of the part.
' The proxies represent the part work planes in the context of the assembly.
Dim oAsmPlane2 As WorkPlaneProxy
oOccurrence.CreateGeometryProxy(oPartPlane1, oAsmPlane2)
' Create the constraint using the part work plane proxies.
oConstraint = oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane2, oAsmPlane1, 0)
'zoom all
ThisApplication.ActiveView.Fit
'get user input
CNsFlip = MessageBox.Show("Flip the constraint?", "iLogic",MessageBoxButtons.YesNo)
If CNsFlip = vbYes then
oConstraint.Delete
oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane2, oAsmPlane1, 0)
Else
Return
End if
Great code, is it possible to alter this so that it flush:
part YZ to Assembly YZ
part XZ to Assembly XZ
part XY to Assembly XY
I know this can be done with "ground and root"
But I dont want to root the part, neither that it jumps to the top of my browser 🙂
Figured it out...
'get file to place Dim oFileDlg As inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*" oFileDlg.DialogTitle = "Select a File" oFileDlg.InitialDirectory = ThisDoc.Path oFileDlg.CancelError = True On Error Resume Next oFileDlg.ShowOpen() If Err.Number <> 0 Then MessageBox.Show("File not chosen.", "Dialog Cancellation") Return ElseIf oFileDlg.FileName <> "" Then oFile = oFileDlg.FileName End If ' set a reference to the assembly component definintion. ' This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Set a reference to the transient geometry object. Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry ' Create a matrix. Dim oMatrix As Matrix oMatrix = oTG.CreateMatrix 'place an instance of the component Dim oOccurrence As ComponentOccurrence oOccurrence = oAsmCompDef.Occurrences.Add(oPath & oFile, oMatrix) ' Set the translation portion of the matrix so the part will be 'positioned at the co-ordinates oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0)) 'check for grounded component, such as the first component in the assembly If oOccurrence.Grounded = True Then oGrounded = MessageBox.Show("Should this component be grounded?", _ "iLogic",MessageBoxButtons.YesNo) If oGrounded = vbNo Then oOccurrence.Grounded = False Else End If End If 'Get the plane from the selected part. ' The work plane obtained is in the context of the part, not the assembly. Dim oPartPlane1 As WorkPlane Dim oPartPlane2 As WorkPlane Dim oPartPlane3 As WorkPlane oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(1) 'Component YZ Plane oPartPlane2 = oOccurrence.Definition.WorkPlanes.Item(2) 'Component XZ Plane oPartPlane3 = oOccurrence.Definition.WorkPlanes.Item(3) 'Component XY Plane 'Get the plane from the assembly Dim oAsmPlane1 As WorkPlane Dim oAsmPlane2 As WorkPlane Dim oAsmPlane3 As WorkPlane oAsmPlane1 = oAsmCompDef.WorkPlanes.Item(1) 'Assembly YZ Plane oAsmPlane2 = oAsmCompDef.WorkPlanes.Item(2) 'Assembly XZ Plane oAsmPlane3 = oAsmCompDef.WorkPlanes.Item(3) 'Assembly XY Plane ' Create proxies for the work planes of the part. ' The proxies represent the part work planes in the context of the assembly. Dim oAsmPlane4 As WorkPlaneProxy Dim oAsmPlane5 As WorkPlaneProxy Dim oAsmPlane6 As WorkPlaneProxy oOccurrence.CreateGeometryProxy(oPartPlane1, oAsmPlane4) oOccurrence.CreateGeometryProxy(oPartPlane2, oAsmPlane5) oOccurrence.CreateGeometryProxy(oPartPlane3, oAsmPlane6) ' Create the constraint using the part work plane proxies. oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane1, oAsmPlane4, 0) oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane2, oAsmPlane5, 0) oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane3, oAsmPlane6, 0) 'zoom all ThisApplication.ActiveView.Fit
But is it possible to make it work so that I can point to a part with the mouse, or rather choose several parts in the assembly and have them flush to assembly origo planes?
Hello,
I am sorry to pick up an old thread, but I would be interested if anobody has an answer to the question from itjelta:
"But is it possible to make it work so that I can point to a part with the mouse, or rather choose several parts in the assembly and have them flush to assembly origo planes?"
The reason why I am asking is, that I am building a model of a factory for my master thesis in Inventor (I do not have anything else than Inventor for the task) and for that I have numerous parts which stand on the ground (the XZ-Plane in my case). And it would be nice if I could insert all the parts and then constrain them all at once, because it takes much time to insert every part for itself. (I need nearly all parts several times in my assembly but i cannot arrange them by a pattern, so I have to insert the parts as often as they appear in the factory and that can be up to 50 times.)
Thank you curtis for your iRule, it works great.
Now if anybody knows how to skip the "Open File" part and make it a "choose several parts already in the assembly and constrain them to the XZ-Plane" that would be really great.
Thanks in advance 🙂
Hi,
I figured out a rule to constrain selected parts in an assembly to the XZ plane of the assembly file.
I used some of the code given above and deleted/added some rows of code.
So if anybody is interested in a possibility to select parts in an assembly and constrain all parts to the XZ plane, here is the rule which works for me (in Iventor Professional 2015)
'iRule to add a flush constraint to the XZ-plane of all selected components with the XZ-plane of the assembly ' set a reference to the assembly component definintion. ' This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In ThisDoc.Document.SelectSet 'check for and skip virtual components '(in case a virtual component trips things up) If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then 'Get the plane from the selected part. ' The work plane obtained is in the context of the part, not the assembly. Dim oPartPlane1 As WorkPlane oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(2) 'Component XZ Plane 'oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(3) 'Component XY Plane 'Get the plane from the assembly Dim oAsmPlane1 As WorkPlane oAsmPlane1 = oAsmCompDef.WorkPlanes.Item(2) 'Assembly XZ Plane 'oAsmPlane1 = oAsmCompDef.WorkPlanes.Item(3) 'Assembly XY Plane ' Create proxies for the work planes of the part. ' The proxies represent the part work planes in the context of the assembly. Dim oAsmPlane2 As WorkPlaneProxy oOccurrence.CreateGeometryProxy(oPartPlane1, oAsmPlane2) ' Create the constraint using the part work plane proxies. oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane2, oAsmPlane1, 0) ' use "Constraints.AddMateConstraint" if you want to add a mate constraint instead of a flush constraint End If Next