3 Replies Latest reply on Oct 8, 2013 4:06 AM by Vishal Pambhar

    How to get edge length thru API

    Vishal Pambhar

      ..Please help me..

      I would like get length of selected edge(Body edge.Refer Attached jpeg) using API...For that i have wrote some code but it giving me some error.Error code highlighted by red color..Please find the code below..

       

      Sub main()

      Dim doc As SldWorks.ModelDoc2

      Dim part As SldWorks.PartDoc

      Dim feat As SldWorks.Feature

      Dim sketch As SldWorks.sketch

      Dim v As Variant

      Dim i As Long

      Dim sseg As SldWorks.SketchSegment

      Dim sline As SldWorks.SketchLine

      Dim sp As SldWorks.SketchPoint

      Dim ep As SldWorks.SketchPoint

      Dim s As String

      Dim boolstatus As Boolean

       

       

      Dim swApp     As SldWorks.SldWorks

      Dim swModel   As SldWorks.ModelDoc2

      Dim swSelMgr  As SldWorks.SelectionMgr

      Dim swSelObji  As Object

      Dim swSkLine    As SldWorks.SketchLine

      Dim bRet        As Boolean

      Dim nDisti     As Double

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Set swSelMgr = swModel.SelectionManager

          For i = 1 To 100

         

          Set swSelObji = swSelMgr.GetSelectedObject5(i)

          nDisti = swSelObji.GetLength

      Set exApp = CreateObject("Excel.Application")

      If Not exApp Is Nothing Then

        exApp.Visible = True

        If Not exApp Is Nothing Then

         Set exApp = GetObject(, "Excel.Application")

         Set Sheet = exApp.ActiveSheet

         End If

      End If

      Sheet.Cells(13, 4).Value = nDisti * 1000

      Set exApp = GetObject(, "Excel.Application")

         Set Sheet = exApp.ActiveSheet

          Sheet.Cells(13, 1).EntireRow.Resize(1).Insert

      Next i

      End Sub

       


        • Re: How to get edge length thru API
          Deepak Gupta

          You need to use swCurve.GetLength2 and not GetLength as this is for sketch length.

           

          Check this example: Get Length of Edge Example (VBA)

          • Re: How to get edge length thru API
            Keith Rice

            Hi,

             

            You're getting an error because you aren't using the required arguments with ICurve::GetLength.

             

            Anyway, ICurve::GetLength is obsolete, like Deepak said. You should use ICurve::GetLength2 if you want the base curve and ICurve::GetLength3 if you want the trimmed curve. So you might try out each one and see which one gives you the result you need. See the API Help remarks for GetLength3 to learn more.

             

            Here's how to get the length of a selected edge using ICurve::GetLength3. The length is printed in the immediate window.

             

            ======

             

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swSelMgr As SldWorks.SelectionMgr

            Dim swEdge As SldWorks.Edge

            Dim swCurve As SldWorks.Curve

            Dim swCurveParams As SldWorks.CurveParamData

            Dim dblLength As Double

             

            Sub main()

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swSelMgr = swModel.SelectionManager

             

                For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)

                    If swSelMgr.GetSelectedObjectType3(i, -1) = 1 Then

                        Set swEdge = swSelMgr.GetSelectedObject6(i, -1)

                        Set swCurve = swEdge.GetCurve

                        Set swCurveParams = swEdge.GetCurveParams3

                        dblLength = swCurve.GetLength3(swCurveParams.UMinValue, swCurveParams.UMaxValue)

                        dblLength = Round(dblLength, 4)

                        Debug.Print " Length = " & dblLength * 1000 & "mm"; g

                    End If

                Next i

            End Sub

             

            ======

             

            Keith

            SolidWorks API Tutorials