AnsweredAssumed Answered

need help to adjust macro

Question asked by Itay Weingarten on Jul 2, 2015
Latest reply on Jul 2, 2015 by Deepak Gupta

hi, i found a macro in previous discussion in the forum. i am trying to file what i need to change so the drawing will be save at the same folder as the part.

also what i need to change so the file name will be the only the part name.slddrw. here the code:

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim swFeat As SldWorks.Feature

 

Dim vConfs As Variant

Dim i As Integer

 

Const sDrTemplate As String = "P:\pa lib\OTHER\TEMPLATES\SW\Sheet metal draw.drwdot"

 

Dim sOutputFolder As String

 

Sub main()

   

    Set swApp = Application.SldWorks

   

    Set swModel = swApp.ActiveDoc

   

    sOutputFolder = Left(swModel.GetPathName(), Len(swModel.GetPathName()) - Len(swModel.GetTitle()) - 7)

       

    vConfs = swModel.GetConfigurationNames()

   

    For i = 0 To UBound(vConfs)

       

        Set swDraw = swApp.NewDocument(sDrTemplate, 0, 0, 0)

       

        Dim swDrawModel As SldWorks.ModelDoc2

       

        Set swDrawModel = swDraw

       

        swDraw.InsertModelInPredefinedView swModel.GetPathName()

               

        Set swView = swDraw.GetFirstView

       

        While Not swView Is Nothing

           

            swView.ReferencedConfiguration = vConfs(i)

           

            Set swView = swView.GetNextView

           

        Wend

                      

        swDrawModel.ForceRebuild3 False

       

        swDraw.InsertModelAnnotations3 swImportModelItemsSource_e.swImportModelItemsFromEntireModel, 32776, True, True, False, False

               

        swDrawModel.Extension.SaveAs swModel.GetTitle() + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0

       

        swApp.CloseDoc swDrawModel.GetTitle()

       

    Next

   

End Sub

Outcomes