1 Reply Latest reply on Mar 21, 2012 4:25 AM by Yong Ning

    How to use SW-Length?

    Yong Ning

      How to get spline length assigned to equation variable or custom property?

      I would set up something like "MyLength"="SW-Length@@@Spline1@3DSketch1@@MyConfig@MyPart.sldprt)

      SolidWorks Drawings ER Blitz - Voting Results

       

      Provide an "SW-Length" property to apply parametrically a user-selected curve (line, arc, circle, spline, or Compcurve).

       

      Target

      How to use "SW-Length@..." obtain Fig Length 484.55.

      Thanks 

       

       

       

      1.JPG

        • Re: How to use SW-Length?
          Yong Ning

          With API solve method

           

          ------------

           

          Option Explicit
              Dim swApp As SldWorks.SldWorks
              Dim Part As SldWorks.ModelDoc2
              Dim swSketchSeg                 As SldWorks.SketchSegment
              Dim SwSkSeg As SldWorks.SketchSegment
                    
              Sub main()
                       
              Dim ThisFile As String
              Dim Methods(8) As String
              Dim Names As Variant
              Dim Types As Variant
              Dim Values As Variant
              Dim editBody As body2
              Dim swmacrofeaturebydefault As Variant
              ''
              Dim swSelMgr As SldWorks.SelectionMgr

              ''
                          
             
              Set swApp = Application.SldWorks
              Set Part = swApp.ActiveDoc
              Set editBody = Nothing
              ''
              Set swSelMgr = Part.SelectionManager
              Set swSketchSeg = swSelMgr.GetSelectedObject5(1)
             

              Debug.Print aa.Name
             
              Debug.Print Round(swSketchSeg.GetLength * 1000, 2)
              Set SwSkSeg = swSketchSeg
              
             
              'Define the routines to call
              ThisFile = swApp.GetCurrentMacroPathName
              Methods(0) = ThisFile
              Methods(1) = "CalLen"
              Methods(2) = "swmRebuild"
              Methods(3) = ThisFile
              'Methods(4) = "MacroFeature_Module1"
              Methods(4) = "CalLen"
              Methods(5) = "swmEditDefinition"
              Methods(6) = "" 'A security routine is optional
              Methods(7) = ""
              Methods(8) = ""

              Names = Empty
              Types = Empty
              Values = Empty
                       
              'Insert the macro feature
              Part.FeatureManager.InsertMacroFeature "CalLen", "", (Methods), Names, Types, Values, editBody, swmacrofeaturebydefault
             
          End Sub

          Function swmRebuild(app As Variant, Part As Variant, Feature As Variant) As Variant
                 
              Dim Definition As SldWorks.MacroFeatureData
              Dim Objects As Variant
              Dim ObjTypes As Variant
              Dim SelMarks As Variant
              Dim DrwViews As Variant
              ''
             
              Set Definition = Feature.GetDefinition

              Definition.GetSelections2 Objects, ObjTypes, SelMarks, DrwViews
              Set swSketchSeg = Objects(0)
          Debug.Print swSketchSeg.GetLength

              Dim vol As Variant
              Dim conv As Variant
              Dim convRounded As String
              Dim prop As Boolean
             
              'Debug.Print SwSkSeg.GetID
             
              prop = Part.DeleteCustomInfo2("", "Len")
              Dim Var
              Var = Round(swSketchSeg.GetLength * 1000, 2)
              prop = Part.AddCustomInfo3("", "Len", 30, Str(Var) + " mm")
          End Function

          Function swmEditDefinition(app As Variant, Part As Variant, Feature As Variant) As Variant
          End Function