4 Replies Latest reply on Sep 20, 2018 5:28 AM by Kenneth Coutinho

    Macro to convert entities directly to construction lines

    Kenneth Coutinho

      Hey guys,

       

      I use the convert entities option quite often in SolidWorks. I then have to convert these lines to construction lines.

      Could you help me make a macro that directly converts entities to construction lines?

       

      Thanks

        • Re: Macro to convert entities directly to construction lines
          Fifi Riri

          Hello,

          Try this on an opened sketch:

           

          Option Explicit

          Sub main()

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swSelMgr As SldWorks.SelectionMgr

              Dim swSketch As SldWorks.Sketch

              Dim swSkRelMgr As SldWorks.SketchRelationManager

              Dim swSkRel As SldWorks.SketchRelation

              Dim vSkRel As Variant

              Dim Ent As Variant

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              swModel.ClearSelection2 True

              Set swSketch = swModel.GetActiveSketch2

              Set swSkRelMgr = swSketch.RelationManager

              For Each vSkRel In swSkRelMgr.GetRelations(swAll)

                  Set swSkRel = vSkRel

                  If swSkRel.GetEntitiesCount > 0 And (swSkRel.GetRelationType = swConstraintType_e.swConstraintType_OFFSETEDGE Or swSkRel.GetRelationType = swConstraintType_e.swConstraintType_USEEDGE) Then

                      For Each Ent In swSkRel.GetEntities

                          'Debug.Print Ent.GetType

                          Ent.ConstructionGeometry = True

                      Next

                  End If

              Next

          End Sub

            • Re: Macro to convert entities directly to construction lines
              Kenneth Coutinho

              Hey Fifi,

              This macro converts every entity in the sketch into a construction line.

              In an open sketch if i select an edge and run the macro i should i directly get a construction line. This is how the macro should run.

              Thanks.

                • Re: Macro to convert entities directly to construction lines
                  Fifi Riri

                  the above macro convert all sketch entities with an "on Edge" constrain to construction lines.

                  to convert entities to sketch entities first, just add :

                  swModel.SketchManager.SketchUseEdge3 False, False

                   

                  Option Explicit

                  Sub main()

                      Dim swApp As SldWorks.SldWorks

                      Dim swModel As SldWorks.ModelDoc2

                      Dim swSelMgr As SldWorks.SelectionMgr

                      Dim swSketch As SldWorks.Sketch

                      Dim swSkRelMgr As SldWorks.SketchRelationManager

                      Dim swSkRel As SldWorks.SketchRelation

                      Dim vSkRel As Variant

                      Dim Ent As Variant

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                    

                      swModel.SketchManager.SketchUseEdge3 False, False

                    

                      Set swSelMgr = swModel.SelectionManager

                      swModel.ClearSelection2 True

                      Set swSketch = swModel.GetActiveSketch2

                      Set swSkRelMgr = swSketch.RelationManager

                      For Each vSkRel In swSkRelMgr.GetRelations(swAll)

                          Set swSkRel = vSkRel

                          If swSkRel.GetEntitiesCount > 0 And (swSkRel.GetRelationType = swConstraintType_e.swConstraintType_OFFSETEDGE Or swSkRel.GetRelationType = swConstraintType_e.swConstraintType_USEEDGE) Then

                              For Each Ent In swSkRel.GetEntities

                                  'Debug.Print Ent.GetType

                                  Ent.ConstructionGeometry = True

                              Next

                          End If

                      Next

                  End Sub