2 Replies Latest reply on May 6, 2015 6:55 AM by Manikandan Babu

    how to measure the total routing length through API in solidworks 2014

    Manikandan Babu

      Hi all,

      Precondition

      Selecting the routing assembly in top level assembly

      Postcondition

      To measure the total length of all routesegment.

       

      Option Explicit

      Dim swApp As SldWorks.SldWorks

      Dim swmodel As SldWorks.ModelDoc2

      Dim swsel As SldWorks.SelectionMgr

      Dim swcomp As SldWorks.Component2

      Dim swassy As SldWorks.AssemblyDoc

      Dim rtRouteManager As SWRoutingLib.RouteManager

      Dim rtRouteProperty As SWRoutingLib.ElectricalRouteProperty

      Dim sketch As SldWorks.sketch

      Dim skSegments As Variant

      Dim skSegment As SldWorks.SketchSegment

      Dim i As Integer

      Sub main()

      Set swApp = Application.SldWorks

      Set swmodel = swApp.ActiveDoc

      Set swsel = swmodel.SelectionManager

      Set swcomp = swsel.GetSelectedObject6(1, -1)

      Set swassy = swcomp.GetModelDoc2

      Set rtRouteManager = swassy.GetRouteManager

      rtRouteManager.Editroute

      End Sub

       

      I have tried upto somelevel but I could not move further,please help me to resolve this.

       

      Thanks in advance

      Manikandan.B

        • Re: how to measure the total routing length through API in solidworks 2014
          Yuvaraj Sakthivel

          Dear Sir,

           

          After Edit route , get sketches and select all the sketches and by using Measure tool, we can get total length.

           

          Kindly verify below code and let me know

           

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swmodel As SldWorks.ModelDoc2

          Dim swsel As SldWorks.SelectionMgr

          Dim swcomp As SldWorks.Component2

          Dim swassy As SldWorks.AssemblyDoc

          Dim rtRouteManager As SWRoutingLib.RouteManager

          Dim rtRouteProperty As SWRoutingLib.ElectricalRouteProperty

          Dim sketch As SldWorks.sketch

          Dim skSegments As Variant

          Dim skSegment As SldWorks.SketchSegment

          Dim i As Integer

          Dim swSktMgr As SldWorks.SketchManager

          Dim swMeasure As SldWorks.Measure

           

           

          Sub main()

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swsel = swmodel.SelectionManager

          Set swcomp = swsel.GetSelectedObject6(1, -1)

          Set swassy = swcomp.GetModelDoc2

          Set rtRouteManager = swassy.GetRouteManager

          rtRouteManager.EditRoute

           

           

          Set swSktMgr = swmodel.SketchManager

          Set sketch = swSktMgr.ActiveSketch

          skSegments = sketch.GetSketchSegments

           

           

          For i = 0 To UBound(skSegments)

          Set skSegment = skSegments(i)

          skSegment.Select4 True, Nothing

          Next i

           

           

          Set swMeasure = swmodel.Extension.CreateMeasure

          swMeasure.Calculate Nothing

          Dim swTotal As Double

          swTotal = swMeasure.TotalLength

          swmodel.ClearSelection2 True

          swmodel.ForceRebuild3 True

          swassy.EditAssembly

          swmodel.ForceRebuild3 True

           

           

          MsgBox "Total Length in mm = " & swTotal * 1000

           

          End Sub

           

          Regards,

          Yuvaraj S