21 Replies Latest reply on Jun 20, 2017 3:42 PM by Rod Thompson

    Converting points

    Rod Thompson

      Is there a way to mass convert points from a 3D sketch to a 2D sketch? Currently I have to click on each point to convert. Copy and paste also does not work properly.

       

      Thanks

        • Re: Converting points
          John Van Kesteren

          It is not ideal, but might work for your situation. If you can link all of the points with lines then you can select the 3 sketch and convert the entities and then convert all of the entities to construction geometry? Would this be suitable or your situation? if not could you please provide more details on the context of the situation.

          Thanks

          • Re: Converting points
            Kelvin Lamport

            How many points would typically be involved?

            • Re: Converting points
              John Stoltzfus

              Could you use the Derived Sketch

              • Re: Converting points
                Rod Thompson

                The first image shows that the individual points (CMM scan) are not at the same Z height. That is why I want to convert them onto a plane for a 2D sketch. From there I can spline them. There are approximately 135 points per section and I have 100 parts to do this for.

                 

                 

                 

                 

                Z HEIGHTS.PNG3D SKETCH.PNG

                  • Re: Converting points
                    Kelvin Lamport

                    That is why I want to convert them onto a plane for a 2D sketch. From there I can spline them.

                    If you are going to join each point with a spline after creating a 2D sketch, why not join the points in the 3D sketch (viewed face on) and then convert the spline into a 2D sketch?

                     

                  • Re: Converting points
                    Rob Edwards

                    Hi Rod

                    I would say you need a macro, for a similar situation (model vertices -> sketch points) I wrote my first one, took me all day but it puts a smile on your face when it works.

                     

                    As I was trying I made one that copies points from "Sketch1" to "Sketch2".  In it's current form it isn't very useful, I was just learning and this was a stepping stone.  I would you suggest you ask in the api forum?

                     

                    Here is what I wrote/copy/pasted/cannibalised...

                     

                    '---------------------------------------------

                     

                    Option Explicit

                     

                        Dim swApp As SldWorks.SldWorks

                     

                        Dim selMgr As SldWorks.SelectionMgr

                     

                        Dim Model As SldWorks.ModelDoc2

                     

                        Dim SketchPoints As Variant

                     

                        Dim SketchFeature As SldWorks.Feature

                        Dim skPoint As Object

                        Dim boolstatus As Boolean

                        Dim i As Integer

                       

                    Sub main()

                     

                        Set swApp = CreateObject("SldWorks.Application")

                        Set Model = swApp.ActiveDoc

                        Set selMgr = Model.SelectionManager

                      

                        Model.ClearSelection2 True

                        boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

                        Model.SketchManager.InsertSketch True

                     

                        Model.ClearSelection2 True

                        boolstatus = Model.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

                        Set SketchFeature = selMgr.GetSelectedObject6(1, 0)

                        Set SketchFeature = SketchFeature.GetSpecificFeature2

                        SketchPoints = SketchFeature.GetSketchPoints2

                     

                        For i = 0 To UBound(SketchPoints)

                            Set skPoint = Model.SketchManager.CreatePoint(SketchPoints(i).X, SketchPoints(i).Y, 0#)

                        Next i

                      

                        Model.ClearSelection2 True

                        boolstatus = Model.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

                        Set SketchFeature = selMgr.GetSelectedObject6(1, 0)

                        Set SketchFeature = SketchFeature.GetSpecificFeature2

                        SketchPoints = SketchFeature.GetSketchPoints2

                     

                        For i = 0 To UBound(SketchPoints)

                            Set skPoint = Model.SketchManager.CreatePoint(SketchPoints(i).X, SketchPoints(i).Y, 0#)

                        Next i

                     

                        Model.SketchManager.InsertSketch True

                        Model.ClearSelection2 True

                     

                    End Sub

                     

                    edit: actually my memories failing me,,, I think this is trying to copy 2 sketches worth of points, I can't remember, it did work kindof at the time

                    • Re: Converting points
                      Dan Pihlaja

                      Could you use the macro provided here: Tutorial-How to export points from solidworks to a excel file! - GrabCAD

                      To export your 3D points to excel?   Then change the Z column to all one value, then save the excel file as a txt file and then re-import it into Solidworks.

                      Tutorial-How to import points to solidworks from a text file ! - GrabCAD

                      • Re: Converting points
                        Dennis Bacon

                        Can you get away with doing an on plane relation with all the points?.. In my example I edited a 3d sketch where I had randomly created 3d sketch points, then selected the plane I wanted to make an on plane relation, then box selected the points. Don't know why I had to select the plane first, but I did.

                        • Re: Converting points
                          Rod Thompson

                          Thank you everyone for your input. I'll try the API fellas.

                            • Re: Converting points
                              Rob Edwards

                              Good Luck Rod, I would be interested in the macro myself so will look out for it

                               

                              I just hastily cobbled this together, which creates a sketch on front plane and adds points at the origin and then makes them coincident with each point in 3DSketch1, but you have to turn off 'snapping manually' I don't know how do that

                               

                              Option Explicit

                               

                               

                                  Dim swApp As SldWorks.SldWorks

                               

                               

                                  Dim selMgr As SldWorks.SelectionMgr

                               

                               

                                  Dim Model As SldWorks.ModelDoc2

                               

                               

                                  Dim SketchPoints As Variant

                               

                               

                                  Dim SketchFeature As SldWorks.Feature

                               

                               

                                  Dim skPoint As Object

                                  Dim boolstatus As Boolean

                                  Dim i As Integer

                                  

                               

                               

                              Sub main()

                               

                               

                                  Set swApp = CreateObject("SldWorks.Application")

                                  Set Model = swApp.ActiveDoc

                                  Set selMgr = Model.SelectionManager

                                 

                                  Model.ClearSelection2 True

                                  boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

                                  Model.SketchManager.InsertSketch True

                               

                               

                                  Model.ClearSelection2 True

                                  boolstatus = Model.Extension.SelectByID2("3DSketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

                                  Set SketchFeature = selMgr.GetSelectedObject6(1, 0)

                                  Set SketchFeature = SketchFeature.GetSpecificFeature2

                                  SketchPoints = SketchFeature.GetSketchPoints2

                               

                               

                                  For i = 0 To UBound(SketchPoints)

                                      Set skPoint = Model.SketchManager.CreatePoint(0, 0, 0#)

                                      boolstatus = SketchPoints(i).Select4(False, selMgr)

                                      boolstatus = skPoint.Select4(True, selMgr)

                                      Model.SketchAddConstraints "sgCOINCIDENT"

                                  Next i

                                 

                               

                               

                                  Model.SketchManager.InsertSketch True

                                  Model.ClearSelection2 True

                               

                               

                              End Sub