VBA API trying to constrain workplanes

VBA API trying to constrain workplanes

MARCO.TIBAQUIRA
Contributor Contributor
944 Views
6 Replies
Message 1 of 7

VBA API trying to constrain workplanes

MARCO.TIBAQUIRA
Contributor
Contributor

Hello community,

 

Trying to constrain workplanes. I was using some of the code that I found here in the forums and also on the API help samples on the Inventor suite. the problem I am having is that the "Componentdefinition" does not support the workplanes. In other words, when I write the code:

 

Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oAsmCompDef.Occurrences.Item(1)
Dim oOcc2 As ComponentOccurrence
Set oOcc2 = 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
    Set oPartPlane1 = oOcc1.Definition.WorkPlanes.Item(3)

The last line "Occ1.definition" then the workplanes are NOT in the menu of objects that can be accessed through the definition

no workplanesno workplanes
Can anyone help me with another way to access the workplanes so that I can complete the code?

I appreciate you guys help


0 Likes
Accepted solutions (2)
945 Views
6 Replies
Replies (6)
Message 2 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@MARCO.TIBAQUIRA,

 

If you are sure that occurrence is part document, then try below VBA code.

Dim oDef1 As PartComponentDefinition
Set oDef1 = oOcc1.Definition

Dim oPartPlane1 As WorkPlane
Set oPartPlane1 = oDef1.WorkPlanes.Item(3)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 7

MARCO.TIBAQUIRA
Contributor
Contributor

Dear Chandra,

 

Thank you for your reply.

I am in need of constraining an assembly occurrence by workplanes in it. Therefore, I cannot assure that it will only be a part occurrence.

Can you help me with a solution for the assembly occurrence?

 

This is what I have:

 

Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = oApp.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oOccurrence As ComponentOccurrence
'Gets the fist component occurrence in assembly
Set oOccurrence = oAsmCompDef.Occurrences.Item(1)

'Plane in the part
Dim oPartPlane1 As WorkPlane
Dim oPartPlane2 As WorkPlane
Dim oPartPlane3 As WorkPlane
 oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(1)  'Component YZ Plane

********************************************************************************************

The last line is the one that has the issue:

 

"workplanes" appears not to be supported by "Definition"

 

No workplanes ii.JPG

 

 

 

 

 

 

0 Likes
Message 4 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@MARCO.TIBAQUIRA,

 

The ComponentDefinition object is the base class for the PartComponentDefinition, AssemblyComponentDefinition and the FlatPattern objects. This object contains only few properties and methods. Some more properties and methods are included based on the object type (like part or assembly).

 

For more details, refer below online documentation link.

 

http://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=GUID-4CA900FA-336C-458C-962B-0336EAE55B35

 

Event though, WorkPlanes property is not listed in the ComponentDefinition object. Still it can be accessed in ComponentDefintion object. I mean, below code works for both part and assembly to get workplanes.

 

Dim oPartPlane1 As WorkPlane
Dim oPartPlane2 As WorkPlane
Dim oPartPlane3 As WorkPlane
Set oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(1) 'Component YZ plane 
Set oPartPlane2 = oOccurrence.Definition.WorkPlanes.Item(2) 'Component XZ plane
Set oPartPlane3 = oOccurrence.Definition.WorkPlanes.Item(3) 'Component XY plane

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 7

BrianEkins
Mentor
Mentor
Accepted solution

The Definition property of the ComponentOccurrence object is typed to return a ComponentDefinition object.  That's because it can return either an AssemblyComponentDefinition or a PartComponentDefinition.  In practice, it always returns one of these, but in the API definition, it has to be to declared as the base class ComponentDefinition object so it can return either one of the derived objects. 

 

Intellisense in VBA and Visual Studio are using the type library to show you the properties available and the type library is saying it returns a  ComponentDefinition.  However, when the program runs it will be either a PartComponentDefinition or AssemblyComponentDefinition object.  You can go ahead and call the WorkPlanes property, even though it's not showing up in the list of available functions.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 7

MARCO.TIBAQUIRA
Contributor
Contributor

Dear Chandra,

 

This is resolved, it turns out I was not including the "set" word at the beginning of the following code line. i added "set" and it worked. 

Set oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(1) 'Component YZ plane

Therefore, it had nothing to do with the class or functions. 

I appreciate the time you took to help me with the research!!!  

0 Likes
Message 7 of 7

MARCO.TIBAQUIRA
Contributor
Contributor

Dear Mr Ekins,

 

Thank you for helping with this item. You were right!. 

It does work even though the function is not listed. 

I had another mistake I believe unrelated. I was not writing the word "Set" at the beginning of the expression.

Set oPartPlane1 = oOccurrence.Definition.WorkPlanes.Item(1) 'Component YZ plane

 

 

0 Likes