Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
I am trying to make a macro (iLogic or VBA) that generates a rectagle, simetrical to main planes.
Here are the steps:
1) Create new sketch [DONE]
2) Select Plane [DONE]
3) Project all main planes [DONE]
4) Create a rectangle [DONE]
5) Center rectangle with symetric constrain
Can anyone help me on the missing points? Assuming I am already inside a sketch, I only need the create rectangle and center it.
Thanks in advance!!!
EDIT: Here is the code used to create the rectangle. How do I center it to main planes? It's the only thing missing. Thanks!
Dim oCompDef As PartComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim planeXY = oCompDef.WorkPlanes.Item(3)
Dim my_sketch As PlanarSketch
my_sketch = oCompDef.Sketches.Add(planeXY)
my_sketch.OriginPoint = oCompDef.WorkPoints.Item(1)
my_sketch.Edit
'PROJECT PLANES
Dim oPartDoc As PartDocument
Dim oAssyDoc As AssemblyDocument
Dim oSelectSet As SelectSet
Select Case ThisApplication.ActiveDocument.DocumentType
Case kPartDocumentObject
oPartDoc = ThisApplication.ActiveDocument
oSelectSet = oPartDoc.SelectSet
oSelectSet.Clear
For Each oWorkPlane In oPartDoc.ComponentDefinition.WorkPlanes
oSelectSet.Select(oWorkPlane)
Next
Case kAssemblyDocumentObject
oAssyDoc = ThisApplication.ActiveDocument
oSelectSet = oAssyDoc.SelectSet
For Each oWorkPlane In oAssyDoc.ComponentDefinition.WorkPlanes
oSelectSet.Select(oWorkPlane)
Next
End Select
ThisApplication.CommandManager.ControlDefinitions.Item("AppProjectGeometryWrapperCmd").Execute
ThisApplication.CommandManager.StopActiveCommand
Dim Width As Integer = 40
Dim Height As Integer = 80
Dim tg As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim lines As Inventor.SketchLines = my_sketch.SketchLines
Dim points As Inventor.SketchPoints = my_sketch.SketchPoints
Dim point_array(3) As Inventor.SketchPoint
point_array(0) = points.Add(tg.CreatePoint2d(-Width/2, -Height/2), False)
point_array(1) = points.Add(tg.CreatePoint2d(Width/2, -Height/2), False)
point_array(2) = points.Add(tg.CreatePoint2d(Width/2, Height/2), False)
point_array(3) = points.Add(tg.CreatePoint2d(-Width/2, Height/2), False)
'Draw lines
Dim line0 = lines.AddByTwoPoints(point_array(0), point_array(1))
Dim line1 = lines.AddByTwoPoints(point_array(1), point_array(2))
Dim line2 = lines.AddByTwoPoints(point_array(2), point_array(3))
Dim line3 = lines.AddByTwoPoints(point_array(3), point_array(0))
'constrain geometry
Dim constr As Inventor.GeometricConstraints
constr = my_sketch.GeometricConstraints
'horizontal constraints
constr.AddHorizontal(line0)
constr.AddHorizontal(line2)
'vertical constraints
constr.AddVertical(line1)
constr.AddVertical(line3)
'equal constraints
constr.AddEqualLength(line0, line1)
'Add Dimensions
my_sketch.DimensionConstraints.AddOffset(line0, line2.StartSketchPoint, tg.CreatePoint2d(5, 2), False, False)
ThisApplication.CommandManager.ControlDefinitions.Item("SketchHideAllConstraintsCtxCmd").Execute
Solved! Go to Solution.