Create a plane with offset using Inventor API

Create a plane with offset using Inventor API

Anonymous
Not applicable
4,168 Views
11 Replies
Message 1 of 12

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)
4,169 Views
11 Replies
Replies (11)
Message 2 of 12

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.



Let us know how we did on Trustpilot.
Message 3 of 12

Anonymous
Not applicable

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

0 Likes
Message 4 of 12

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 12

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

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 12

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 12

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 12

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 12

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
Message 11 of 12

amalikAHJNB
Observer
Observer

Has this bug been fixed? Because I am having the same issue and I am using Inventor 2024

0 Likes
Message 12 of 12

WCrihfield
Mentor
Mentor

Hi @amalikAHJNB.  As far as I know, the same restrictions are still in effect.  Still in the 2026 Inventor API, most of the WorkPlanes.Add... type methods will only work in Parts, not in assemblies, except for the WorkPlanes.AddFixed method, same as before.  And as mentioned in the online help for that method, when we create a WorkPlane with that method in an assembly, its definition is a AssemblyWorkPlaneDef type object.  And as you can see in the online help page for that object type, it does have properties for all 3 inputs that were required when defining it, but they are all 'ReadOnly' properties.  But it does also have the GetData & PutData methods, where the PutData method actually lets us 'change' those inputs, if necessary.  But we can also use its Constraints property to access the collection of assembly constraints associated with that WorkPlane, if any.  Then, if we wanted to, we could change something about one or more of those constraints.  And yes, the process shown in Message 4 above does still work to create an 'offset' WorkPlane in an assembly.  Below is an updated iLogic rule example of the same process which I just tested in Inventor 2024.4.1 and it worked just fine.  I made sure to add comments in the code too, to help guide folks about what the next line(s) of code are trying to do.

Sub Main
	'get current assembly
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	'get its 'definition' (where model geometry gets created)
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	'get its WorkPlanes collection
	Dim oWPlanes As Inventor.WorkPlanes = oADef.WorkPlanes
	'get the origin 'XY Plane', which is always Item 3
	Dim oXY_WPlane As Inventor.WorkPlane = oWPlanes.Item(3)
	'<<< define a 3D point, and 2 directions for the new WorkPlane we want to create >>>
	Dim oP3D As Inventor.Point = oADef.WorkPoints.Item(1).Point.Copy()
	oP3D.Z = 35 'units not specified, so they will be understood as centimeters
	Dim oX_Dir As Inventor.UnitVector = oADef.WorkAxes.Item(1).Line.Direction
	Dim oY_Dir As Inventor.UnitVector = oADef.WorkAxes.Item(2).Line.Direction
	'create a 'fixed' WorkPlane using those inputs
	Dim oNewWPlane As Inventor.WorkPlane = oWPlanes.AddFixed(oP3D, oX_Dir, oY_Dir)
	'turn on its AutoResize to make it more visible
	oNewWPlane.AutoResize = True
	'create a Flush constraint from the origin XY Plane to the new WorkPlane, which actually constrains the offset
	Dim oFlushConst As Inventor.FlushConstraint = oADef.Constraints.AddFlushConstraint(oXY_WPlane, oNewWPlane, "WorkPlaneOffset1 = 35 cm")
	'this just updates the current view, so you can immediately see the results
	ThisApplication.ActiveView.Fit(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)