Create a plane with offset using Inventor API

Create a plane with offset using Inventor API

Anonymous
Not applicable
2,905 Views
9 Replies
Message 1 of 10

Create a plane with offset using Inventor API

Anonymous
Not applicable

Hello,

 

I'd like to create a new plane parallel to the XY plane with an offset of 35 mm in an assembly using Inventor API. I'm not yet familiar with VBA but I'm learning step by step.

I have searched on internet and I have found some code but none of them works. From what I've seen I guess it's something like that:

 

Sub createWP()
Dim oAssDoc As AssemblyDocument Set oAssDoc = ThisApplication.ActiveDocument Dim oAssCD As AssemblyComponentDefinition Set oAssCD = oAssDoc.ComponentDefinition Dim oWPlane as WorkPlane Set oWPlane = oAssCD.WorkPlanes.AddByPlaneAndOffset(oAssCD.WorkPlanes.Item("XY Plane"), 35) End Sub

 

Thank you in advance for you help !

0 Likes
Accepted solutions (1)
2,906 Views
9 Replies
Replies (9)
Message 2 of 10

Hochenauer
Autodesk
Autodesk
Accepted solution

Hi,

 

I debugged the code behind the API and found that the current  AddByPlaneAndOffset works for part documents only. I am logging a defect to get this working for assemblies as well - sorry for the inconvenience!

 

Kind regards,

Gerald

 



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

Message 3 of 10

Anonymous
Not applicable

Thank you for your answer I hope it will be fixed soon !

0 Likes
Message 4 of 10

ruthsteed
Autodesk
Autodesk

Hi,

When you create an offset workplane in an assembly from the UI, what really happens is a workplane is created and an offset constraint is applied.  You can do the same thing through the API, but you have to do the steps yourself.  Here is a sample that does what you want:

Public Sub AddWorkPlaneInAssembly()
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Dim oAssCD As AssemblyComponentDefinition
    Set oAssCD = oAsmDoc.ComponentDefinition

    Dim oWrkPlane1 As WorkPlane
    Set oWrkPlane1 = oAssCD.WorkPlanes.Item("XY Plane")

    Dim oOriginPnt As Point
    Dim oXaxis As UnitVector
    Dim oYaxis As UnitVector
    Set oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0#, 0#, 0#)
    Set oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1#, 0#, 0#)
    Set oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0#, 1#, 0#)

    Dim oWrkPlane As WorkPlane
    Set oWrkPlane = oAssCD.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis)  ' create the workplane
    oWrkPlane.AutoResize = True ' To make it easier to see
    oAssCD.Constraints.AddFlushConstraint oWrkPlane, oWrkPlane1, 35 ' constrain it to the XY plane
End Sub

Hope this helps.

 

Regards,

Ruth



Ruth Steed
Inventor Development Team
Autodesk, Inc.

Message 5 of 10

sam
Advocate
Advocate
This is still not working in assemblies? Any reason why?
Message 6 of 10

markus_gruebel
Participant
Participant

Hi!
I am trying to learn how to create my own VBA-Projects for Inventor.

Is there a source for all these functions , like creating a plane with an offset?
i have many ideas for macros, but i just have no idea where to look this up.

 

Greetings,

Markus

0 Likes
Message 7 of 10

hariharanhZXJ8L
Contributor
Contributor

I am trying to Create Plane using AddByPlaneAndOffset in 2022 version. But I am facing the same !
@Hochenauer  is the Issue Resolved ?

 

Thanks

HARI

0 Likes
Message 8 of 10

A.Acheson
Mentor
Mentor

There is still no AddByPlaneAndOffset in assembly see object in API help. Follow message 5 vba version. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 10

hariharanhZXJ8L
Contributor
Contributor

@A.Acheson 

do you have any option to create work plane in assembly with reference to Face object ?

0 Likes
Message 10 of 10

A.Acheson
Mentor
Mentor

From memory I think you can get a point on the face, use that point to create a fixed workplane about the face then constrain it afterwards.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes