5 Replies Latest reply on Sep 18, 2017 8:12 PM by Amen Allah Jlili

    Find the total length of all sketches of an assembly

    Mm Sharifuzzaman

      Hi,

      I am trying to develop a macro which will sum up all dimension greater than a specific values in all the sketches of an assembly and export that value to a Text file. Anyone can help will be appreciated.

       

      Thanks

        • Re: Find the total length of all sketches of an assembly
          Amen Allah Jlili

          All sketches in the assembly feature tree or all sketches in all components?

          • Re: Find the total length of all sketches of an assembly
            Jacob Corder

            perhaps what your end goal is will help.

             

            sketches can be unreliable as patterns will not have sketches defining edges,  if your just looking for a minimum radius that is different.

             

            using Edges is a much more reliable way to go about this.

             

            so your end goal with this macro will help us help you.

            • Re: Find the total length of all sketches of an assembly
              Amen Allah Jlili

              This should print all dimensions. Kindly keep the macro header notes if you'd like to share with others.
              You can modify the macro to save the dims in a text file. That's fairly easy to do.

               

              printdims.gif

               

              ' CADHero.com - SOLIDWORKS API CONSULTING AND TRAINING

              ' Print all sketch dimension

              ' written by JLILI Amen

               

               

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swAssembly As SldWorks.AssemblyDoc

              Dim swComponentObject

              Dim swComponent As SldWorks.Component2

              Dim Components As Variant

              Dim swModelFromComponent As SldWorks.ModelDoc2

              Dim swFeature As SldWorks.Feature

              Dim Features As Variant

              Dim swFeatureObject

              Dim swDisplayDimension As SldWorks.DisplayDimension

              Dim swDimension As SldWorks.Dimension

               

               

              Sub main()

               

               

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swAssembly = swModel

              Components = swAssembly.GetComponents(False)

              For Each swComponentObject In Components

              Set swComponent = swComponentObject

              Debug.Print "Component Name = " & swComponent.Name2

              Set swModelFromComponent = swComponent.GetModelDoc2

              If Not swModelFromComponent Is Nothing Then

              Features = swModelFromComponent.FeatureManager.GetFeatures(False)

              For Each swFeatureObject In Features

              Set swFeature = swFeatureObject

              If swFeature.GetTypeName2 = "ProfileFeature" Or swFeature.GetTypeName2 = "3DProfileFeature" Then

              Set swDisplayDimension = swFeature.GetFirstDisplayDimension

              While Not swDisplayDimension Is Nothing

              Set swDimension = swDisplayDimension.GetDimension2(0)

               

               

              Debug.Print vbTab + "Configuration Name = " + swComponent.ReferencedConfiguration

              Debug.Print vbTab + "Sketch Name = " + swFeature.Name

              Debug.Print vbTab + vbTab + "Dimension Name = " + swDimension.Name

              Debug.Print vbTab + vbTab + "Value = " + CStr(swDimension.Value)

               

               

              Set swDisplayDimension = swFeature.GetNextDisplayDimension(swDisplayDimension)

              Wend

              End If

              Next swFeatureObject

               

               

              End If

              Next swComponentObject

              End Sub