VBA drawing rectangle and extrude it

VBA drawing rectangle and extrude it

Anonymous
Not applicable
3,449 Views
4 Replies
Message 1 of 5

VBA drawing rectangle and extrude it

Anonymous
Not applicable
Hi, I have a problem with Inventor VBA. I am trying to draw a rectangle of a specific size and extrude it also to a specific size. I am using this to draw the rectangle (below), which works, however the size of the rectangle isn't being drawn correctly (length 20 and width 10) for some reason. Also, since I'm a beginner with VBA, I'm stuck with the extrusion part...Can someone please help? Here is the code:

Private Sub RectangularBase()
' Create a sketch on the X-Y plane.

Dim oSketch As PlanarSketch
Set oPartDef = oPartDoc.ComponentDefinition
Set oSketch = oPartDef.Sketches.Add(oPartDef.WorkPlanes.Item(3))
'(oPartDef.WorkPlanes.Item(3)) - where 3 is the item index for xy plane, 1 for yz and 2 for xz

' Project the origin point onto the sketch.
Dim oOriginSketchPoint As SketchPoint
Set oOriginSketchPoint = oSketch.AddByProjectingEntity(oPartDef.WorkPoints.Item(1))


' Create a rectangle.
Call oSketch.SketchLines.AddAsTwoPointRectangle(oOriginSketchPoint, ThisApplication.TransientGeometry.CreatePoint2d(20, 10))
'AddAsTwoPointRectangle (corner point one: the origin sketch point, corner point two: point 20,10)

End Sub
0 Likes
3,450 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
All distances in the API are specified using centimeters as the unit. Your
code should be creating a 20cm x 10 cm rectangle.
--
Brian Ekins
Autodesk Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
0 Likes
Message 3 of 5

Anonymous
Not applicable
Oh...that's why!! I didn't know...and I spent hours trying to modify the code, obviously without success 😕

What about extrusion of the rectangle? Your help would be greatly appreciated. Thanks.
0 Likes
Message 4 of 5

Anonymous
Not applicable
If you look in the programming help that's delivered as part of Inventor
you'll find several samples that demonstrate this. To get to the
programming help go to the help menu and select "Additional Resources" and
then "Programming Help". You can access a list of all of the samples if you
look at the Contents tab on the left and the "Sample Code" link. The sample
listed under "Features - Create" called "Extrude Feature - Create Block with
Pocket" is doing exactly what you want plus a little more.
--
Brian Ekins
Autodesk Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
0 Likes
Message 5 of 5

Anonymous
Not applicable
That's great!!!

Thanks a lot for your help 🙂
0 Likes