ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
AGAlex Graff11/03/2015

Hello,

I just started writing macros yesterday so I am very new to this. By sifting through various forums and many discussions on this forum I managed to create a macro to do what I need. With a drawing open it deletes the current revision table and inserts a new revision table in the proper location. It isn't quite perfect because I was having trouble with the proper anchor location but somehow it is working. I now need a way to run this in task scheduler so it will open, change the revision table and save all the drawings in a given directory. Any help with this would be great. I will post what I currently have. Like I said it is bits and pieces that I put together that I found so I can't take much credit for the work done. I am not familiar with the namespace and arguments everything uses so it might be a little messy still.

I believe I need to take what I have and update it and save it as a .swb file. I know I need to define a string and then have the string be $$$my_file_path$$$ so I can input the desired directory in the parameters in task managers custom task. I am just getting to the point where I am getting lost with only minimal programming experience and only a day in SolidWorks API. The code below is what I have working as a macro on an open file. I am getting lost when it comes to opening changing and saving multiple files in a folder.

It took me 6 hours to get only as far as I am so I figured it was time to reach out for help. If I cant get this working I'm stuck doing all several hundred drawings by hand, which won't be as bad as it was now that I at least have a macro... but still a lengthy process.

Thanks in advance!

Const TABLE_TEMPLATE As String = "H:\SolidWorks\Revision Table Templates\MARIS REVISION.sldrevtbt"

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim swSheet As SldWorks.Sheet

Dim vViews As Variant

Dim swView As SldWorks.View

Dim swTableAnn As SldWorks.TableAnnotation

Dim swAnn As SldWorks.Annotation

Dim swRevTableAnn As SldWorks.RevisionTableAnnotation

Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

    Set swSheet = swDraw.GetCurrentSheet

    'Delete existing revision table

    Set swView = swDraw.GetFirstView

    Do While Not swView Is Nothing

        Set swTableAnn = swView.GetFirstTableAnnotation

        While Not swTableAnn Is Nothing

            If swTableAnn.Type = swTableAnnotation_RevisionBlock Then

                Set swAnn = swTableAnn.GetAnnotation

                swAnn.Select3 False, Nothing

                swModel.Extension.DeleteSelection2 Empty

                Exit Do

            End If

            Set swTableAnn = swTableAnn.GetNext

        Wend

        Set swView = swView.GetNextView

    Loop

    'Add new revision table

    Set swRevTableAnn = swSheet.InsertRevisionTable(True, Empty, Empty, _

        swBOMConfigurationAnchor_TopRight, TABLE_TEMPLATE)

End Sub