9 Replies Latest reply on Aug 26, 2016 2:04 PM by Christian Chu

    Drawing Note Macro No Longer Working in SW2016

    Ian Chamberlin

      Greetings all...

       

      I have a macro that we use to populate drawing notes which was downloaded from Lenny Kikstra's site (CommonNotes v2.5).  This worked fine until we recently upgraded from 2012 to 2016.  The code is hanging at this line:

       

      FileTyp = Document.GetType

       

      This should determine the document type but I'm guessing it hangs here now because the syntax of the command has changed?  I don't have enough API knowledge to figure this out so I'm hoping someone can chime in to help me get this macro running again.

       

      Thanks,

      Ian

        • Re: Drawing Note Macro No Longer Working in SW2016
          Christian Chu

          There are many changes in API from 2012 to 2016

           

          Try this:

          If swModelDoc.GetType <> swDocDRAWING Then

                  MsgBox "The active document is not a SW drawing", vbInformation, "Wrong Document Type"

                  End

              End If

           

          or post your macro here so we can take a look

            • Re: Drawing Note Macro No Longer Working in SW2016
              Ian Chamberlin

              Thanks for the response.  I tried replacing the relevant line but it still throws an error.  The current code is as follows:

               

              Global swApp    As Object
              Global Document As Object

              Global boolstatus   As Boolean

              Global longstatus   As Long

              Global SelMgr   As Object
              Global PickPt   As Variant

              Global CustomNote   As String

              Global Const swDocDRAWING = 3           ' Consistent with swconst.bas

              Global Const version = 2.55

               

               

              Sub main()

                Set swApp = Application.SldWorks          ' Attach to SolidWorks

                Set Document = swApp.ActiveDoc            ' Get active document

                If Not Document Is Nothing Then           ' Document is valid

                  FileTyp = Document.GetType              ' Get document type

                  If FileTyp = swDocDRAWING Then          ' Is it a drawing ?

                    PickPt = Document.GetInsertionPoint   ' Get user selected point

                    If IsEmpty(PickPt) Then               ' Valid point

                      MsgBox "Please pick an insertion point before running macro.", _

                             vbExclamation

                    Else

                      FormSelectNotes.Show                ' Show user form

                    End If

                  Else

                    MsgBox "Current document is not a drawing." & Chr(13) & Chr(13) _

                          & "Please load/activate a SolidWorks " & Chr(13) _

                          & "drawing and try again.", vbExclamation

                  End If

                Else

                    MsgBox "No active drawing found in SolidWorks." & Chr(13) & Chr(13) _

                          & "Please load/activate a SolidWorks " & Chr(13) _

                          & "drawing and try again.", vbExclamation

                End If

              End Sub

               

               

              Is there any way to tag code chunks in these forum messages for better formatting?

                • Re: Drawing Note Macro No Longer Working in SW2016
                  Christian Chu

                  1) change  Public swApp As SldWorks.SldWorks

                  2) change long to longptr

                  3) change

                  FileTyp = Document.GetType              ' Get document type

                      If FileTyp = swDocDRAWING Then .... with

                   

                  If Document.GetType <> 3 Then

                          MsgBox "The active document is not a SW drawing", vbInformation, "Wrong Document Type"

                          End

                      End If

                   

                   

                  make sure to check the ref. all up to 2016

                  • Re: Drawing Note Macro No Longer Working in SW2016
                    Ivana Kolin

                    yes you can format your code.

                    Choose "advanced editor " and syntax highlighting - > Plain

                     

                    Option Explicit
                    Global swApp                                      As SldWorks.SldWorks
                    Global swMod                                      As SldWorks.ModelDoc2
                    Global Document                                   As SldWorks.DrawingDoc
                    Global boolstatus                                 As Boolean
                    Global longstatus                                 As Long
                    Global SelMgr                                     As Object
                    Global PickPt                                     As Variant
                    Global CustomNote                                 As String
                    Global Const swDocDRAWING = 3                              ' Consistent with swconst.bas
                    Global Const version = 2.55
                    Dim FileTyp                                       As Integer
                    
                    
                    Sub main()
                        Set swApp = Application.SldWorks                       ' Attach to SolidWorks
                        Set swMod = swApp.ActiveDoc                            ' Get active document
                        If Not swMod Is Nothing Then                           ' Document is valid
                            FileTyp = swMod.GetType                            ' Get document type
                            If FileTyp = swDocDRAWING Then                     ' Is it a drawing ?
                                PickPt = Document.GetInsertionPoint            ' Get user selected point
                                If IsEmpty(PickPt) Then                        ' Valid point
                                    MsgBox "Please pick an insertion point before running macro.", _
                                           vbExclamation
                                Else
                                    FormSelectNotes.Show                       ' Show user form
                                End If
                            Else
                                MsgBox "Current document is not a drawing." & Chr(13) & Chr(13) _
                                       & "Please load/activate a SolidWorks " & Chr(13) _
                                       & "drawing and try again.", vbExclamation
                            End If
                        Else
                            MsgBox "No active drawing found in SolidWorks." & Chr(13) & Chr(13) _
                                   & "Please load/activate a SolidWorks " & Chr(13) _
                                   & "drawing and try again.", vbExclamation
                        End If
                    End Sub
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                • Re: Drawing Note Macro No Longer Working in SW2016
                  Christian Chu

                  I copied your codes and pasted into a new macro and it works just fine (no error )

                  I created a form "FormSelectNotes", picked a point on the dwg and run the macro - see att. image - I also attached the macro here !!! Good luck

                   

                  Capture.JPG