4 Replies Latest reply on Jan 2, 2018 4:45 PM by Elmar Klammer

    loop macro

    Faez Alkadi

      I have never worked on macro before and would love to know if there are some resources or videos to help me learn. I want to build a macro that offset surface of a body for i number of times and save every single offset as a separate IGES file format.

      In this macro I wish to be able to input offset distance (d) which increases with same amount every loop and number of desired loops (i).

      And get output, i number of files for the offseted surface in IGES format named from 1 to i. 

      For example:

      First offset file name is 1.IGS.

      Second offset file name is 2.IGS.

      and so on ....

      Last offset file name is 100.IGS. (if i =100)

      All in the same folder in my PC.

       

      I wish to use this micro to offset any surface one any solid part. After I select the surface that i want to offset, I just run the macro and determine (d) and ( i) and just run it.

       

      Thank you so much

        • Re: loop macro
          Peter Kennedy

          Keith Rice has a website with some good information about learning solidworks API. www.cadsharp.com

          • Re: loop macro
            Elmar Klammer

            Hi Faez

             

             

            Check How to delete overlapping solids?  it does part one. Use macro below to find offset feature. Look api for save as code.

            you are done.

             

            '------------------------------------

            ' Preconditions:

            ' 1. A part document is open in SolidWorks.

            ' 2. Open the Immediate window.

            ' 3. Run the macro.

            '

            ' Postconditions: Examine the Immediate window for

            ' the position and names of the features in the

            ' FeatureManager design tree in reverse

            ' chronological order.

            '--------------------------------------

            Option Explicit

            Dim swApp As SldWorks.SldWorks

            Dim Part As SldWorks.ModelDoc2

            Dim theFeature As SldWorks.Feature

            Dim featCount As Long

            Dim featName As String

            Dim i As Long

            Sub main()

                Set swApp = CreateObject("SldWorks.Application")

                Set Part = swApp.ActiveDoc

                featCount = Part.GetFeatureCount

                For i = featCount To 1 Step -1

                    Set theFeature = Part.FeatureByPositionReverse(featCount - i)

                    If Not theFeature Is Nothing Then

                        featName = theFeature.Name

                    Debug.Print "Feature " + Str(i) + " is " + featName

                    End If

                Next

                Set Part = Nothing

            End Sub