15 Replies Latest reply on May 20, 2014 2:07 PM by Kelvin Lamport

# Converting sketch3D to sketch ????

hi :-)

How can convert sketch3D to sketch

or

how can draw a 3D rectangle in  an ORDINARY sketch (not 3DSketch)

thanks :-)

• ###### Re: Converting sketch3D to sketch ????

Well, you can't work in 3D while in a 2D sketch, so the second question is not possible.

As for the first question, there isn't a quick conversion tool.  You can use "Convert Entities" while in the 2D sketch and grab the sketch entities from the 3D sketch though.

• ###### Re: Converting sketch3D to sketch ????

What do you mean with 3D rectangle? Can you put an example here?

• ###### Re: Converting sketch3D to sketch ????

i have 4 points of a rectangle

p1(x1,y1,z1)

p2(x2,y2,z2)

p3(x3,y3,z3)

p4(x4,y4,z4)

i create these points in my macro therfore i know these points are in one plane.

i want draw a rectangle with these points to a sketch, and i can only draw a true rectangle

with "SketchManager.Insert3DSketch(True)"

but i need draw this rectangle with "SketchManager.InsertSketch(True)"

and when use "SketchManager.InsertSketch(True)", the drawing rectangle is not true

or can not draw a rectangle.

sorry for my poor english :-)

• ###### Re: Converting sketch3D to sketch ????

The sketch plane for a 2D sketch is defined in 3D space. While the elements of the 2D sketch must lie within the plane, the 2D sketch exists in 3D space just like a 3D sketch.

So, to answer your question, a rectangle drawn in a 2D sketch IS a rectangle drawn in 3D space.

• ###### Re: Converting sketch3D to sketch ????

I'm wondering if maybe Ar is looking to convert an Isometric view of a cube into a 2D sketch.  Or something along those lines.

If that is the case, locating a plane at the required angle should let you use Convert Entities to project the edges of the 3D cube onto the 2D plane.

• ###### Re: Converting sketch3D to sketch ????

i have 4 points of a rectangle

p1(x1,y1,z1)

p2(x2,y2,z2)

p3(x3,y3,z3)

p4(x4,y4,z4)

i create these points in my macro therfore i know these points are in one plane.

i want draw a rectangle with these points to a sketch, and i can only draw a true rectangle

with "SketchManager.Insert3DSketch(True)"

but i need draw this rectangle with "SketchManager.InsertSketch(True)"

and when use "SketchManager.InsertSketch(True)", the drawing rectangle is not true

or can not draw a rectangle.

sorry for my poor english :-)

• ###### Re: Converting sketch3D to sketch ????

it sounds like you need to define a plane for the sketch to be on before starting your rectangle. unless those points happen to be on one of the default planes.

• ###### Re: Converting sketch3D to sketch ????
i have 4 points of a rectangle

p1(x1,y1,z1)

p2(x2,y2,z2)

p3(x3,y3,z3)

p4(x4,y4,z4)

i create these points in my macro therfore i know these points are in one plane.

I agree the points shown are on one plane, but they describe a straight line, not a rectangle.

• ###### Re: Converting sketch3D to sketch ????

Kelvin,

I think those were variable names, not the actual coordinates.

• ###### Re: Converting sketch3D to sketch ????

Maybe ... but I have my doubts.

• ###### Re: Converting sketch3D to sketch ????

I can draw rectangle with points (p1,p2,p3,p4) in 3DSketch !!!

• ###### Re: Converting sketch3D to sketch ????

I would very much like to see that.

Please post the sketch as a SW part.

• ###### Re: Converting sketch3D to sketch ????

You'll need to create a plane before you can sketch in 2D.  If your sketch is at an odd angle (which it sounds like it is), you can use this example to create a plane using three points:

http://help.solidworks.com/2014/English/api/sldworksapi/create_plane_thru_3_points_in-context_example_vb.htm

You would need to create a 3D sketch of the first three points, then add a plane using those points as references.  Then you can create a 2D sketch on that plane and sketch your rectangle.

Message was edited by: Patrick O Hern

• ###### Re: Converting sketch3D to sketch ????

May 20, 2014 6:43 AM (in response to Ar K)

Re: Converting sketch3D to sketch ????

Patrick O Hern wrote:

You would need to create a 3D sketch of the first three points, then add a plane using those points as references.  Then you can create a 2D sketch on that plane and sketch your rectangle.

Message was edited by: Patrick O Hern

Thank you :-)

your way is true but it is incomplete.

for complete your way we need using transform data of plane similar to :

http://help.solidworks.com/2014/English/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.imathtransform.html

http://help.solidworks.com/2014/English/api/sldworksapi/get_transform_of_plane_example_vb.htm

after getting transform data Matrix , we must multiply this matrix with x and y and z of our points :-)

'VB.NET Language

'Dim swDoc As ModelDoc2 = swApp.ActiveDoc

'Dim boolstatus As Boolean

'Dim myRefPlane As RefPlane' is solidworks object

'Dim pt1, pt2, pt3, pt4 As _Point' _point is my object

'transform

TransformToSketch2D(MyPlane, pt1)

TransformToSketch2D(MyPlane, pt2)

TransformToSketch2D(MyPlane, pt3)

TransformToSketch2D(MyPlane, pt4)

'Create Sketch

boolstatus = swDoc.Extension.SelectByID2("MyPlane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

swDoc.SketchManager.InsertSketch(True)

swDoc.ClearSelection2(True)

'Drawing Rectangle

Dim vSkLines As Array = Nothing

vSkLines =swDoc.SketchManager.Create3PointCornerRectangle( pt1.x, pt1.y, pt1.z, pt2.x, pt2.y, pt2.z, pt3.x, pt3.y, pt3.z)

'Closing Sketch

swDoc.ClearSelection2(True)

swDoc.SketchManager.InsertSketch(True)

Public Sub TransformToSketch2D(ByVal plane As RefPlane, ByVal pt As _Point)

Dim swXform As MathTransform = plane.Transform

Dim x, y, z As Double

x = pt.x

y = pt.y

z = pt.z

pt.x = swXform.ArrayData(0) * x + swXform.ArrayData(1) * y + swXform.ArrayData(2) * z + swXform.ArrayData(9)

pt.y = swXform.ArrayData(3) * x + swXform.ArrayData(4) * y + swXform.ArrayData(5) * z + swXform.ArrayData(10)

pt.z = swXform.ArrayData(6) * x + swXform.ArrayData(7) * y + swXform.ArrayData(8) * z + swXform.ArrayData(11)

End Sub