Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
brendon.serrano
in reply to: sam

I know that VBA and iLogic are similar, and I have a bit of code from iLogic I used to create a Bar Extrusion. I did this by creating the sketch in iLogic, but I'm sure if you just call the name to be the active object you will be able to do it. (assuming that it is the same in VBA)

 

' Create a new sketch.
Dim sketch As Inventor.PlanarSketch
sketch = oDef.Sketches.Add(xyPlane, True)
sketch.Name = "Bar_Sketch"

ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches("Bar_Sketch").Edit


InventorVb.DocumentUpdate()


' Check to make sure a sketch is open.
If Not TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
MessageBox.Show("A sketch must be active.", "iLogic")
Return
End If

'set a reference to the active sketch.
Dim oSketch As PlanarSketch
oSketch = ThisApplication.ActiveEditObject

'set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

' Create a rectangle 

width = Parameter("BAR_W") 'Trigger
height = Parameter("BAR_H") 'Trigger
length = Parameter("BAR_L") 'Trigger

Dim oRectangleLines As SketchEntitiesEnumerator
oRectangleLines = oSketch.SketchLines.AddAsTwoPointCenteredRectangle( oTransGeom.CreatePoint2d(0, 0),oTransGeom.CreatePoint2d(width*2.54/2, height*2.54/2))

Dim oSketchLine As Inventor.SketchLine
Dim oDim As DimensionConstraint

oSketchLine = oRectangleLines.Item(1) 

oDim = oSketch.DimensionConstraints.AddTwoPointDistance _
	(oSketchLine.StartSketchPoint, oSketchLine.EndSketchPoint, _
	DimensionOrientationEnum.kHorizontalDim, _
	oTransGeom.CreatePoint2d(0, -(width/2 )))

oDim.Parameter.Expression = "BAR_W"

oSketchLine = oRectangleLines.Item(2)

oDim = oSketch.DimensionConstraints.AddTwoPointDistance _
	(oSketchLine.StartSketchPoint, oSketchLine.EndSketchPoint, _
	DimensionOrientationEnum.kVerticalDim, _
	oTransGeom.CreatePoint2d(height+2, 0))

oDim.Parameter.Expression = "BAR_H"

ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches("Bar_Sketch").ExitEdit

Hope this helps!