3 Replies Latest reply on Aug 8, 2018 1:51 PM by Deepak Gupta

    Adding Model to second sheet of drawing

    Robert Caste

      I’m new to VB and thought this would be a simple task but it’s not proving to be. I need to activate the second sheet of a drawing template after it has been opened by a macro that places views and a BOM on the front page and insert the model in the predefined views on the second page template. I know I can use Insermodelinpredefinedview and I’m pointing to the sheet to activatesheet (sheetname) with the name of the sheet, but it errors to “empty” on this line. Does anyone have any sample code of something close to this or suggestions?

        • Re: Adding Model to second sheet of drawing
          Deepak Gupta

          When you are using InsertModelInPredefinedView, are you giving the model full path as the parameter? If not then do that and try again.

           

          Here are two examples you can look at

           

          API: How to load a reference model into a drawing view

          API equivalent of "Make drawing from part/assembly"

            • Re: Adding Model to second sheet of drawing
              Robert Caste

              Even when removing the insertmodelinpredifinedview code I still can’t get an open document to activate the second page.

               

              Dim swdrawmodel As SldWorks.ModelDoc2

              Dim sheetnames() As String

              Dim i As Long

              Dim currentsheet As String

               

              Dim swModel As SldWorks.ModelDoc2

              Dim vSheetNames As Variant

              Dim swDraw As SldWorks.DrawingDoc

              Dim swView As SldWorks.View

              Dim swSheet As SldWorks.Sheet

              'Dim bRet As Boolean

              Dim swApp As SldWorks.SldWorks

               

               

               

              Sub main()

               

               

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swDraw = swModel

              Set swdrawmodel = swDraw

              Set swSheet = swDraw.GetCurrentSheet

              currentsheet = swSheet.GetName

              sheetnames = swDraw.GetSheetNames

               

              swDraw.ActivateSheet (apucolumn2)

                • Re: Adding Model to second sheet of drawing
                  Deepak Gupta

                  Try these codes and modify as needed.

                   

                  Option Explicit

                      Dim swApp                       As SldWorks.SldWorks

                      Dim swModel                     As SldWorks.ModelDoc2

                      Dim swDraw                      As SldWorks.DrawingDoc

                      Dim vSheetName                  As Variant

                      Dim swSheet                     As Sheet

                     

                  Sub main()

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swDraw = swModel

                   

                         vSheetName = swDraw.GetSheetNames

                         swDraw.ActivateSheet vSheetName(1)

                   

                          Set swSheet = swDraw.GetCurrentSheet

                          If (swSheet.IsLoaded) Then

                             Debug.Print vSheetName(1) & " is loaded."

                          Else

                               Debug.Print vSheetName(1) & " is not loaded."

                          End If

                   

                  End Sub