1 Reply Latest reply on Jul 13, 2014 11:25 PM by Artem Taturevych

    Generate cross sections in increments and save the file with increment number

    Rashiga Walallawita

      Hi All,


      I've a task where I need to generate cross sections in increment lengths in a comples shape. I need to save the dawring of that cross section which the  file name should be the cross section distance i've taken from a referance point.


      Here the things i've done so far,


      1. I created the cross section using extruded cut profile where small section is left out so to get a cross section.

      2. thought about how the macro should work


      Strat loop

      > select the extrude cut sketch

      > edit the dimension form the referance point in a increment

      > switch to the dawring view

      > save the already set front elevation ,with the file name "length from the referance point".dwg

      > continue the loop from begining till the nu,ber of steps reach a certain value.


      3. I tried to record a macro and edit it, but since i'm new to solidworks api I coudlnt code it correctly. Here's the code,


      Sub main()


      Set swApp = Application.SldWorks


      For i = 0 To 5


      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)


      Part.ClearSelection2 True

      boolstatus = Part.Extension.SelectByID2("D2@Sketch1@vajja.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

      Dim myDimension As Object

      Set myDimension = Part.Parameter("D2@Sketch1")

      step = i / 10

      myDimension.SystemValue = 1 + step

      Part.ClearSelection2 True

      Part.SketchManager.InsertSketch True

      swApp.ActivateDoc2 "vajja - Sheet1", False, longstatus

      Set Part = swApp.ActiveDoc

      Part.ClearSelection2 True

      longstatus = Part.SaveAs3("F:\2014\sw_ergo\vajja.SLDDRW", 0, 2)

      Next i

      End Sub


      I get the error in the following red colored line.


      Some help would be highly appreciated.


      Thanks in Advance.