Message 1 of 5
VBA drawing rectangle and extrude it
Not applicable
07-31-2009
09:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
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