1 Reply Latest reply on Mar 19, 2014 8:07 PM by Shawn Pantzke

    Is it possible to link revisions to a drawing from a part and also macro problems?

    Brandon Stephan

      I am attempting to redaw several dozen drawings to have a more presentable bank of drawings and to add revisions that need to be noted on all of them. I am trying to incorperate a macro to redraw all of the configurations and have it place them in the appropriate views. I'm also trying to link revisions from the part to the drawing files so when a new revision is added to a part it will automatically insert the revision into the drawings. This would save a lot of time instead of opening every single drawing individually to add the revisions. I am also having a problem with the macro creating every configuration including the flatpattern configuration, I would like it to skip the flatpattern configuration. I also don't know how to tell it to not auto save and exit. I would like to do the choosing to move onto the next drawing. I also heard you can annotate dimensions into the macro aswell. if anyone has any suggestions on my problems I'm open to anything.

       

       

      Here is the macro I am trying to work with:

       

       

      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swDraw As SldWorks.DrawingDoc

       

      Dim vConfs As Variant
      Dim i As Integer

       

      Dim sDrTemplate As String
      Dim lDrSize As Long

       

      Const sOutputFolder As String = "E:\Drawings\"

       

      Sub main()
         
          Set swApp = Application.SldWorks
         
          Set swModel = swApp.ActiveDoc
             
          sDrTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateDrawing)
          lDrSize = swDwgPaperSizes_e.swDwgPaperA0size
         
          vConfs = swModel.GetConfigurationNames()
         
          For i = 0 To UBound(vConfs)
             
              Set swDraw = swApp.NewDocument(sDrTemplate, lDrSize, 0, 0)
              swDraw.Create1stAngleViews2 swModel.GetPathName
              Dim swView As SldWorks.View
              Set swView = swDraw.GetFirstView
             
              While Not swView Is Nothing
                 
                  swView.ReferencedConfiguration = vConfs(i)
                 
                  Set swView = swView.GetNextView
                 
              Wend
             
              Dim swDrawModel As SldWorks.ModelDoc2
              Set swDrawModel = swDraw
                    
              swDrawModel.ForceRebuild3 False
             
              swDraw.InsertModelAnnotations3 swImportModelItemsSource_e.swImportModelItemsFromEntireModel, 32776, True, True, False, False
                     
              swDrawModel.Extension.SaveAs sOutputFolder + swModel.GetTitle() + "_" + vConfs(i) + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0
             
              swApp.CloseDoc swDrawModel.GetTitle()
             
          Next
         
      End Sub

        • Re: Is it possible to link revisions to a drawing from a part and also macro problems?
          Shawn Pantzke

          Brandon,

           

          I have modified the code that you posted so that it will pull the property from the part to the drawing, assuming that they both have the same property name.

           

          I have also made it so that it will skip the flat pattern configurations, you may need to tweek this slightly depending on your configuration names.

           


          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swDraw As SldWorks.DrawingDoc
          Dim swView As SldWorks.View
          Dim swDrawModel As SldWorks.ModelDoc2

          Dim vConfs As Variant
          Dim i As Integer

          Dim sDrTemplate As String
          Dim lDrSize As Long
          Dim RevValue As String

          Const sOutputFolder As String = "E:\Drawings\"
          Const FlatIdentifier As String = "flatpattern" 'For skipping flat patterns
          Const Revision As String = "Revision"

          Public Function GetPrpValue(PrpName As String) As String

          Dim swFile                      As Object
          Dim swCustProp                  As CustomPropertyManager
          Dim swModelDocExt               As ModelDocExtension
          Dim bool                        As Boolean

              Set swApp = Application.SldWorks
              Set swFile = swApp.ActiveDoc
              Set swModelDocExt = swFile.Extension
              Set swCustProp = swModelDocExt.CustomPropertyManager("")
              bool = swCustProp.Get4(PrpName, False, "", GetPrpValue)
             
              Set swFile = Nothing
              Set swModelDocExt = Nothing
              Set swCustProp = Nothing
          End Function
          Public Function SetPrpValue(PrpName As String, PrpValue_)
          Dim swFile                      As Object
          Dim swCustProp                  As CustomPropertyManager
          Dim swModelDocExt               As ModelDocExtension
          Dim bool                        As Boolean

              Set swApp = Application.SldWorks
              Set swFile = swApp.ActiveDoc
              Set swModelDocExt = swFile.Extension
              Set swCustProp = swModelDocExt.CustomPropertyManager("")
              bool = swCustProp.Set(PrpName, PrpValue_)
             
              Set swFile = Nothing
              Set swModelDocExt = Nothing
              Set swCustProp = Nothing
          End Function

          Sub main()
              Set swApp = Application.SldWorks
             
              Set swModel = swApp.ActiveDoc
                   RevValue = GetPrpValue(Revision)   'Get part's Revision property
            
              sDrTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateDrawing)
              lDrSize = swDwgPaperSizes_e.swDwgPaperA0size
             
              vConfs = swModel.GetConfigurationNames()
              For i = 0 To UBound(vConfs)
                  If LCase(Right(vConfs(i), Len(FlatIdentifier))) = FlatIdentifier Then GoTo Skip 'Skip flat pattern configurations
                  Set swDraw = swApp.NewDocument(sDrTemplate, lDrSize, 0, 0)
                  swDraw.Create1stAngleViews2 swModel.GetPathName
                  Dim swView As SldWorks.View
                  Set swView = swDraw.GetFirstView
                 
                  While Not swView Is Nothing
                     
                      swView.ReferencedConfiguration = vConfs(i)
                     
                      Set swView = swView.GetNextView
                     
                  Wend
                 
                  Dim swDrawModel As SldWorks.ModelDoc2
                  Set swDrawModel = swDraw
                   SetPrpValue Revision, RevValue 'set revision property in drawing file to match part file
                  swDrawModel.ForceRebuild3 False
                 
                  swDraw.InsertModelAnnotations3 swImportModelItemsSource_e.swImportModelItemsFromEntireModel, 32776, True, True, False, False
                 
              'this is the portion of the code that saves and closes the files
                  swDrawModel.Extension.SaveAs sOutputFolder + swModel.GetTitle() + "_" + vConfs(i) + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0
                  swApp.CloseDoc swDrawModel.GetTitle()
          Skip:
              Next
             
          End Sub