iLogic Mating - Custom Planes

iLogic Mating - Custom Planes

Anonymous
Not applicable
2,589 Views
28 Replies
Message 1 of 29

iLogic Mating - Custom Planes

Anonymous
Not applicable

Hello all,

I am fairly new to Inventor iLogic, but I have been able to piece together a fairly extensive set of codes. I am currently attempting to mate my newly generated assembly via the Component Occurrences.
I have custom named work planes in two different parts which I need to mate. This is the code I have so far on this:

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim comp0cc1 As ComponentOccurrence = Component.InventorComponent("Component_#1")
Dim comp0cc2 As ComponentOccurrence = Component.InventorComponent("Component_#2")

Dim oPlane1 As WorkPlane
oPlane1 = comp0cc1.Definition.WorkPlanes("Work Plane #1")
Dim oPlane2 As WorkPlane
oPlane2 = comp0cc2.Definition.WorkPlanes("Work Plane #2")

Dim oproxyPlane1 As WorkPlaneProxy
comp0cc1.CreateGeometryProxy(oPlane1, oproxyPlane1)
Dim oproxyPlane2 As WorkPlaneProxy
comp0cc2.CreateGeometryProxy(oPlane2, oproxyPlane2)

Dim oConstraint As MateConstraint
oConstraint = oAsmCompDef.Constraints.AddMateConstraint(oproxyPlane1, oproxyPlane2,0)
oConstraint.Name = comp0cc1.Name & ":" & comp0cc2.Name & " mate"

The Error I get when running this code is:
[highlight #CC0000]Error in rule: Pushrod_1_Selection, in document: Assembly Test 2.iam
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

I understand the problem is I don't know the proper way to reference the custom named work plane from the component occurrence. Does anyone know the proper notation for this reference?

Thank you very much for reading this and for your assistance!

-Lance

0 Likes
Accepted solutions (1)
2,590 Views
28 Replies
Replies (28)
Message 2 of 29

ToddHarris7556
Collaborator
Collaborator

I don't have the time just at the moment to parse through your code carefully - but as a possibly-related side note... as of IV2019, you now have the ability to Assign Names to geometry in iLogic. Not sure if this changes/affects your need at all. The question is still legit and I'll get back to it later. 


Todd
Product Design Collection (Inventor Pro, 3DSMax, HSMWorks)
Fusion 360 / Fusion Team
0 Likes
Message 3 of 29

AlexFielder
Advisor
Advisor

After looking through the sample you've used to create your rule, the only thing I can see that looks different is the missing "Call" as shown here in red on the lines below:

 

Public Sub MateConstraintOfWorkPlanes()
    Dim oAsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

    ' Get references to the two occurrences to constrain.
    ' This arbitrarily gets the first and second occurrence.
    Dim oOcc1 As ComponentOccurrence = oAsmCompDef.Occurrences.Item(1)

    Dim oOcc2 As ComponentOccurrence = oAsmCompDef.Occurrences.Item(2)

    ' Get the XY plane from each occurrence.  This goes to the
    ' component definition of the part to get this information.
    ' This is the same as accessing the part document directly.
    ' The work plane obtained is in the context of the part,
    ' not the assembly.
    Dim oPartPlane1 As WorkPlane = oOcc1.Definition.WorkPlanes.Item(3)

    Dim oPartPlane2 As WorkPlane = oOcc2.Definition.WorkPlanes.Item(3)

    ' Because we need the work plane in the context of the assembly
    ' we need to create proxies for the work planes.  The proxies
    ' represent the work planes in the context of the assembly.
    Dim oAsmPlane1 As WorkPlaneProxy
    Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)

    Dim oAsmPlane2 As WorkPlaneProxy
    Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

    ' Create the constraint using the work plane proxies.
    Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)
End Sub

(FWIW I just quickly converted the sample I linked to earlier into what I assume would work as iLogic, I haven't tested the above in any fashion!)

 

Your best bet would be to share a pack & go of your assembly here for us to look at.

 

Thanks,

 

Alex.

 

0 Likes
Message 4 of 29

R.Mabery
Advocate
Advocate

Hi llerickson,

 

Are you sure you have the component browser node names and the work plane names correct?

 

What version of Inventor are you running this in?  Are you running this as an internal iLogic rule?

 

This code should work as you have it above.


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 5 of 29

Anonymous
Not applicable

Thank you for the responses! I am currently running this on Inventor Professional 2018.
I was attempting to add a proxy plane for an existing working plane I had in the individual part file. 

I have resorted to attempting to offset planes from the origin planes of the parts, adding proxies, and mating them. I am facing some difficulty due to the shear amount I am having one single rule do. Do you know if there are technical limitations to the number of objects you can reference or planes you can offset and proxy within a single rule?

0 Likes
Message 6 of 29

R.Mabery
Advocate
Advocate

As far as I know there are no limitations.  I write rules that handle a lot of references.

 

Are you able to upload your assembly and the required parts?

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 7 of 29

Anonymous
Not applicable

I am not certain about the relationship between browser node names and the parts in an assembly. Would a browser node name be available for an offset plane in an individual part file, and would that be accessible through the assembly ilogic? The version of Inventor is 2018 Professional, and this is an internal rule to an assembly file. 
The rule summons iParts and matches them based upon custom properties linked within the tables. Would then mating them be a technical limitation?

0 Likes
Message 8 of 29

AlexFielder
Advisor
Advisor

There are no limitations on what you can include in a rule. But bear in mind if you build a massively complex rule, you'll be the one left scratching your head when you have to maintain it in 3/6 months time.

You can break rules into separate files (if using external rules) or even separate rules within the same file.

0 Likes
Message 9 of 29

AlexFielder
Advisor
Advisor

If the Browser node name appears within the browser nodes in the Assembly then it's available to the assembly-proper. As @R.Mabery & I said earlier, your best bet is to share the Assembly here so we can help. If you're worried about product IP you could simply build an empty assembly with basic (part) geometry using the same names you mentioned in your OP.

0 Likes
Message 10 of 29

Anonymous
Not applicable

That is good to hear about the limitations. 
I am unfortunately not able to release the assembly or part files. 

At some point I was able to make this work, but currently it results in an unspecified error. I am curious how to then refer to the proxy planes to flip their orientation? 

SyntaxEditor Code Snippet

Dim comp0cc1 As ComponentOccurrence = Component.InventorComponent("Item_#1")
Dim comp0cc2 As ComponentOccurrence = Component.InventorComponent("Item_#2")

Dim
oPlane1 As WorkPlane
Dim PRXY As WorkPlane

PRXY = comp0cc1.Definition.WorkPlanes.Item(3)
Offset1 = (-(Parameter("Item_#1", "Length"))+Parameter("Item_#1", "Bore_Depth")) & "in"
oPlane1 = comp0cc1.Definition.WorkPlanes.AddByPlaneAndOffset(PRXY, Offset1, False)

Dim
oPlane2 As WorkPlane
oPlane2 = comp0cc2.Definition.WorkPlanes.Item(3)

Dim
oproxyPlane1 As WorkPlaneProxy
Call comp0cc1.CreateGeometryProxy(oPlane1, oproxyPlane1)
Dim oproxyPlane2 As WorkPlaneProxy
Call comp0cc2.CreateGeometryProxy(oPlane2, oproxyPlane2)
'WorkPlane.FlipNormal("Work Plane1", "-Z")

Dim oConstraint2 As MateConstraint
oConstraint2 = oAsmCompDef.Constraints.AddMateConstraint(oproxyPlane1, oproxyPlane2,0)
oConstraint2.Name = comp0cc1.Name & ":" & comp0cc2.Name & " Plane mate"

 

0 Likes
Message 11 of 29

AlexFielder
Advisor
Advisor

I don't see much that's different in there from the code in the OP.

 

Since you can't share the files I would suggest sharing with us the specific error message and the "Details" page from the error message.

 

Beyond that, are you certain that the formula you have created to build Offset1 actually returns the result you expect?

 

Are you using "Option Explicit On" at the top of your rules? This will force you to provide a type (i.e. Dim Offset1 as String) for everything and can help when working out why things aren't working the way you expect. It also forces you to be less lazy when writing rules.

0 Likes
Message 12 of 29

Anonymous
Not applicable

The location of the error is at the plane offset, as far as I can see. Is there anything wrong with that portion of the code?

 

0 Likes
Message 13 of 29

Anonymous
Not applicable

Well shoot!

Add By Plane And Offset as a command is currently not supported in an assembly mode. I guess I will have to find another method of mating these parts. I thank you for your help everyone! If you have any suggestions moving forward, they would be appreciated. Once again, thank you for your help!

0 Likes
Message 14 of 29

R.Mabery
Advocate
Advocate

Your original code that you posted wasn't creating a plane.  You were using the planes in the lower level components and creating a proxy for the workplane.  This method works just fine in an assembly.

 

Not sure when creating a workplane creeped into the discussion but you are correct.  You cannot add a plane this way in an assembly.

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 15 of 29

AlexFielder
Advisor
Advisor
That's disappointing. I notice reading the API documentation a whole bunch of Workplanes methods are unsupported in Assemblies.

Your option then is to create extra workplanes within the parts themselves?
0 Likes
Message 16 of 29

AlexFielder
Advisor
Advisor
0 Likes
Message 17 of 29

AlexFielder
Advisor
Advisor
So actually, we're back to square one with this thread. I was going to create a dummy assembly to throw his OP code into to see what breaks.
0 Likes
Message 18 of 29

AlexFielder
Advisor
Advisor

Right, so here's my assembly (files attached) that runs with this rule:

2018-07-27 15_40_44-Autodesk Inventor Professional 2019 - [Assembly1].png

 

One thing I noticed is that after saving the two files with the "Component_#1" & "Component_#2" filenames I had to normalise the names within the assembly because they end up with "Component_#1:1" & "Component_#2:1" instead.

 

Normalisation removes the ":#" from the component name at assembly level and then OP's original code works correctly.

 

0 Likes
Message 19 of 29

Anonymous
Not applicable

I guess the question is at this point, how do I reference a Part based Work Plane in an assembly iLogic code?

 

iPart Image.PNGAssembly Image.PNG

On the left is an image of the iFactory open with the work plane clearly visible.

On the right is when it is imported into the assembly, and the plane is not accessible. 

 

How would i go forward using the plane of the left to constrain the two parts on the right? Also, this is not an origin plane, so it cannot be indexed as "1", "2", or "3".

0 Likes
Message 20 of 29

AlexFielder
Advisor
Advisor

You can access that workplane in exactly the same way that I just did in my sample assembly. You just need to know it's name and you're set.

0 Likes