Centre Point Rectangle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there.
I have a kludged (probably) sub that creates a centre-point rectangle based at a projection of the origin. It is quite klunky, I think, and has several limitations:
- I don't know how to grab the origin projection if it already exists, so i just check for it and deleted it. I'm sure i should be able to create a reference to it at that time.
- It probably would be nice to also use this code for a user-selected location for the rectangle. I would want the user just to pick the centre point, and a corner point. Can anyone help me with these two things?
(As I said, the code is probably quite clunky, and if you'd like to clean it up, that'd be fine too 😉
(I'm using IV9, not 2009. Yes, i know. And I created this from study and application of the help-file.)
Cheers.
Sub InitialRectangle() Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.ActiveDocument ' Set a reference to the component definition. Dim oCompDef As PartComponentDefinition Set oCompDef = oPartDoc.ComponentDefinition Dim oSketch As PlanarSketch Set oSketch = oCompDef.Sketches.Item(oCompDef.Sketches.count) ' Set a reference to the transient geometry object. Dim oLines(1 To 4) As SketchLine Dim oRectLines As SketchEntitiesEnumerator Dim count As Integer Dim XVal As Integer Dim YVal As Integer XVal = 3 YVal = 2 Dim oTransGeom As TransientGeometry Set oTransGeom = ThisApplication.TransientGeometry 'check to see if the origin has already been projected. If so, delete it. If oSketch.SketchPoints.count > 0 Then For count = 1 To oSketch.SketchPoints.count If oSketch.SketchPoints(count).Geometry.X = 0 And oSketch.SketchPoints(count).Geometry.Y = 0 Then oSketch.SketchPoints(count).Delete End If count = count + 1 Next End If With oTransGeom Set oRectLines = oSketch.SketchLines.AddAsTwoPointRectangle(.CreatePoint2d(-XVal, -YVal), .CreatePoint2d(XVal, YVal)) Dim oDiagonalLine As SketchLine Set oDiagonalLine = oSketch.SketchLines.AddByTwoPoints(.CreatePoint2d(XVal, -YVal), .CreatePoint2d(-XVal, YVal)) oDiagonalLine.Construction = True Dim oOrigin As WorkPoint Set oOrigin = oCompDef.WorkPoints.Item(1) Dim oOriginPoint As SketchPoint '******************* update this line ********************* Set oOriginPoint = oSketch.AddByProjectingEntity(oOrigin) '******************* update this line ********************* With oSketch.GeometricConstraints Call .AddCoincident(oDiagonalLine.StartSketchPoint, oRectLines(1)) Call .AddCoincident(oDiagonalLine.StartSketchPoint, oRectLines(2)) Call .AddCoincident(oDiagonalLine.EndSketchPoint, oRectLines(3)) Call .AddCoincident(oDiagonalLine.EndSketchPoint, oRectLines(4)) Call .AddMidpoint(oOriginPoint, oDiagonalLine) End With End With End Sub
This is my signature, not part of my post.