Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I sketch a symmetric rectangle in a single step? 3

Status
Not open for further replies.

bvanhiel

Mechanical
Oct 23, 2001
510
Is there an easy way to sketch a rectangle that will be centered and symmetric with the orgin? I find myself defining this sketch quite often and I'm wondering is there's some kind of control-drag way of defining a rectangle that will make this a quicker process.

For reference, I currently sketch a rectangle and then sketch centerlines from the orgin to the midpoints of the top and right side. I then define the center lines as vertical and horizontal. I'd love to find a faster way.

-b
 
Replies continue below

Recommended for you

Yes, there is. Read Help Topics about polygons.

"Art without engineering is dreaming; Engineering without art is calculating."

Have you read faq731-376 to make the best use of Eng-Tips Forums?
 
I don't think the polygon tool will do a rectangle, but that's the kind of funtionality I want. FYI, I'm using 2007.

-b
 
1. Sketch the rectangle.
2. Draw a single construction line from one corner to the opposite corner.
3. Place a point at the mid-point of the construction line.
4. Constrain that point to the origin.

finisher SW 2007
 
Sorry bvanhiel. I read your post as "triangles"... I use the same method as finisher for rectangles and squares.

"Art without engineering is dreaming; Engineering without art is calculating."

Have you read faq731-376 to make the best use of Eng-Tips Forums?
 
If using finisher's method, you don't need to place a point at the midpoint of your diagonal construction line - just put a midpoint constraint between the construction line and the origin.
 
I use:

Code:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Part.ClearSelection2 True
Part.SketchRectangle -0.03093212735166, 0.04488191027496, 0, 0.0511492040521, -0.02506917510854, 0, 1
Part.ClearSelection2 True
Part.CreateLine2(0.0511492040521, 0.04488191027496, 0, -0.03093212735166, -0.02506917510854, 0).ConstructionGeometry = True
Part.ClearSelection2 True
Part.SetPickMode
boolstatus = Part.Extension.SelectByID("Line5", "SKETCHSEGMENT", 0.01516280752533, 0.0141519536903, 0, False, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing)
Part.SketchAddConstraints "sgATMIDDLE"
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID("Line5", "SKETCHSEGMENT", 0.01516280752533, 0.0141519536903, 0, False, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line2", "SKETCHSEGMENT", -0.03133646888567, 0.01051287988423, 0, False, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line1", "SKETCHSEGMENT", -0.01799319826339, 0.02587785817656, 0, True, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line4", "SKETCHSEGMENT", 0.03012344428365, 0.001213024602026, 0, True, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line3", "SKETCHSEGMENT", 0.01758885672938, -0.02466483357453, 0, True, 0, Nothing)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID("Line1", "SKETCHSEGMENT", -0.009502026049204, 0.02709088277858, 0, False, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line2", "SKETCHSEGMENT", -0.03052778581766, 0.01293892908828, 0, True, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line3", "SKETCHSEGMENT", 0.01475846599132, -0.02709088277858, 0, True, 0, Nothing)
boolstatus = Part.Extension.SelectByID("Line4", "SKETCHSEGMENT", 0.02891041968162, -0.01051287988423, 0, True, 0, Nothing)
End Sub

Nothing but a recorded macro, not cleaned up or anything.

For the record, I think this is the crappiest macro I've ever posted here, but I use it all the time. I have it mapped with a keyboard shortcut.
 
2008 has the best of all enhancements...(drum roll, please)...I give you...the Center Rectangle. It's one of those enhancements that are actual time savers and should have been available from day 1.

Dan

 
I do it similar to finisher, except that I make the construction line midpoint to the top and bottom horizontal line. This way, if I choose to put a fillet on the sketch I do not lose the constraints made on the corners and the construction line.

That is also how the "rectangle" macro is done found on the CD of the Solidworks Bible.



Flores
 
...this is the crappiest macro I've ever posted here

Function over form. I'll use this quite often. Thanks.

Joe
SW Office 2006 SP5.1
P4 3.0Ghz 1GB
ATI FireGL X1
 
Another way to do it is without additional construction lines. Draw the rectangle with origin inside. Select midpoint of top line and control select origin and make vertical than midpoint of left line and origin and make horizontal.
Midpoint is selected by right clicking on the line and choosing from the menu.
 
I have a sketch in my design library for the symmetric rectangle.

Eric
 
SW2008 finally allows you to draw a rectangle by selecting a center point, so we no longer have to add construction lines as was previously required.
 
Crappy macro #2 (as recorded):
Code:
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager

swApp.ActiveDoc.ActiveView.FrameState = 1
Part.ClearSelection2 True
Dim vSkLines As Variant
vSkLines = Part.SketchManager.CreateCornerRectangle(-0.07072414660869, -0.03687367058217, 0, 0.07599696221126, 0.04203082730694, 0)
Part.SetPickMode
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Line3", "SKETCHSEGMENT", -0.009611839420063, 0.04228868514318, 0, False, 0, Nothing, 0)
Part.SelectMidpoint
boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
Part.SketchAddConstraints "sgVERTICALPOINTS2D"
Part.SketchAddConstraints "sgVERTICALPOINTS2D"
boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", -0.07356058280732, -2.578578362389E-04, 0, False, 0, Nothing, 0)
Part.SelectMidpoint
boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
Part.SketchAddConstraints "sgHORIZONTALPOINTS2D"
Part.SketchAddConstraints "sgHORIZONTALPOINTS2D"
Part.SetPickMode
Part.ClearSelection2 True
End Sub

 
Hey, Guys. The macros are cool for earlier versions, but why not just use the center rectangle as I suggested for '08? Am I missing something besides my hair?

Dan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor