How to Create Work Plane Proxy Given an origin plane in a part?

How to Create Work Plane Proxy Given an origin plane in a part?

MechMachineMan
Advisor Advisor
1,706 Views
4 Replies
Message 1 of 5

How to Create Work Plane Proxy Given an origin plane in a part?

MechMachineMan
Advisor
Advisor

As the title says, I'm trying to get the work plane proxy for use in an assembly - I'm trying to create an assembly mate constraint for two origin planes from within parts.

 

oCylOrigPlane1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select the origin plane of the cylinder")
oCylOrigPlane2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select the a co-planar origin plane of the rod")

oCylOrigPlane1.Parent.CreateGeometryProxy(oCylOrigPlane1, oAsmPlane1) oCylOrigPlane2.Parent.CreateGeometryProxy(oCylOrigPlane2, oAsmPlane2)

 I cannot figure out how to get the ComponentOccurence that contains the selected workplane though 😞

 

Any help would be much appreciated!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
1,707 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

I figured it out:

 

oCylOrigPlane1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select the origin plane of the cylinder")
oCylOrigPlane2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select the a co-planar origin plane of the rod")

Dim oCompDef1 As ComponentDefinition = oCylOrigPlane1.Parent()
Dim oCompDef2 As ComponentDefinition = oCylOrigPlane2.Parent()

Dim oCompOcc1 As ComponentOccurrence = oAsmCompDef.Occurrences.AllReferencedOccurrences(oCompDef1).Item(1)
Dim oCompOcc2 As ComponentOccurrence = oAsmCompDef.Occurrences.AllReferencedOccurrences(oCompDef2).Item(1)

oCompOcc1.CreateGeometryProxy(oCylOrigPlane1, oAsmPlane1)
oCompOcc2.CreateGeometryProxy(oCylOrigPlane2, oAsmPlane2)

 

This seems to be a workaround seeing as the intention is that there will ever only be one occurrence of each part in the assembly.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

ekinsb
Alumni
Alumni

It's not clear what exactly you're workflow is but here are a couple of things that will hopefully help.

 

When you select something in an assembly you're getting the proxy for that object so the entities you're getting back from the Pick method can immediately be used to create a constraint because they're already a proxy in the context of the top-level assembly.

 

However, there are cases where you do need to create a proxy.  This is when you have a reference to an entity in the context of the part or subassembly but then need a reference with respect to the top-level assembly.  For example, in your program it would probably more convenient to ask the user to select the cylinder part and then select the rod part, instead of having to select specific work planes.  In this case you have the occurrence but need to go into the part to get the correct plane (this assumes they've been named) and then create proxies of the planes to be able to use them in the context of the assembly.  Here's some VBA code that demonstrates the entire process.

 

Public Sub ConnectParts()
    ' Select the cylinder and rod occurrences.
    Dim cylPart As ComponentOccurrence
    Set cylPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select the cylinder part.")
    
    Dim rodPart As ComponentOccurrence
    Set rodPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select the rod part.")
    
    ' Find the origin work plane in the cylinder part.
    ' This leaves the context of the assembly because the
    ' component definitition returned is the same as if you
    ' opened the part by itself.
    Dim partDef As PartComponentDefinition
    Set partDef = cylPart.Definition
    Dim cylinderPlane As WorkPlane
    Set cylinderPlane = partDef.WorkPlanes.Item("OriginPlane")
    
    ' Find the origin plane in the rod part.
    Set partDef = rodPart.Definition
    Dim rodPlane As WorkPlane
    Set rodPlane = partDef.WorkPlanes.Item("OriginPlane")

    ' Create proxies for the two work planes.
    Dim cylPlaneProxy As WorkPlaneProxy
    Call cylPart.CreateGeometryProxy(cylinderPlane, cylPlaneProxy)
    Dim rodPlaneProxy As WorkPlaneProxy
    Call rodPart.CreateGeometryProxy(rodPlane, rodPlaneProxy)
    
    ' Create a mate constraint in the assembly.
    Dim asmDef As AssemblyComponentDefinition
    Set asmDef = ThisApplication.ActiveDocument.ComponentDefinition
    Call asmDef.Constraints.AddMateConstraint(cylPlaneProxy, rodPlaneProxy, 0)
End Sub

 

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor
This wouldn't work as I need to select work planes to set the orientation
of the rod within the cylinder.

I don't understand what you are saying; using the pick method was not
giving me the proxy as the program wasn't allowing me to use that plane in
a mate constraint right away.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 5

MechMachineMan
Advisor
Advisor
However, thanks for the input! I will have to go back and double check this
to make sure I wasn't getting the error from elsewhere.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes