26 Replies Latest reply on May 3, 2017 3:57 PM by Corry Schneider

    Linking custom property to drawing view name

    Corry Schneider

      I have a weldment drawing with the assembly in its finished state.

      3 "default" configuration views on page 1, top, front, and right.

      Page 2, BOM with "weldment" configuration in iso view, balloon and weldment callouts galore.

      Page 3+, all the steel parts in their finished states.

      Problem: how do I rename all these views with the correct description from the custom property in the correct configuration of the assembly/part, followed by the view orientation? The goal is to reduce errors by reusing existing data and hyperlinks in the PDF which will take you directly to the desired view.

      Is a macro the best way to do this? If yes, does one already exist, if not, can someone please help me make one?

      Thanks in advance,

        • Re: Linking custom property to drawing view name
          Jim Steinmeyer

          Corry,

          From the way your question is worded I am assuming that you have custom properties created for names of the appropriate views. If not we will have to go a little deeper.

          If you do the first thing you need to do is either double click on the existing view description or create a note if one does not exist. Then with the note active look at the circled icons in the following screen shot. The left icon will insert a hyperlink and the right one will link to custom properties in the model or drawing.

          Capture.PNG

          Now you can select to use properties from either the current document (drawing) or the model. You can select the current view or a different component. and then you can select the desired property. This includes different configurations. Hopefully this will help with your challenges.

          Untitled.png

            • Re: Linking custom property to drawing view name
              Corry Schneider

              True, but I was hoping all I would have to do is click a macro and this task would be accomplished for all 60+ views in the document. As it is I am spending half an hour just renaming the views.

                • Re: Linking custom property to drawing view name
                  Matt Peneguy

                  Corry,

                  I had a macro I kludged together to get a custom property into an annotation a few years ago.  I modified it to overwrite whatever the text selected and set it to the configuration name.  It may help you:

                   

                   

                  Sub main()

                      Dim swApp                       As SldWorks.SldWorks

                      Dim swModel                     As SldWorks.ModelDoc2

                      Dim swSelMgr                    As SldWorks.SelectionMgr

                      Dim swAnnObj                    As Object

                      Dim swAnn                       As SldWorks.Annotation

                      Dim swoNote                     As Note

                   

                   

                      Dim swTextFormat                As SldWorks.TextFormat

                      Dim i                           As Long

                      Dim bRet                        As Boolean

                      Dim j                           As Integer

                     

                     

                     

                     

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swSelMgr = swModel.SelectionManager

                     

                  For j = 1 To swSelMgr.GetSelectedObjectCount2(-1)

                      If swSelMgr.GetSelectedObjectType3(j, -1) = swSelNOTES Then

                          Set swAnnObj = swSelMgr.GetSelectedObject5(j)

                          Set swAnn = swAnnObj.GetAnnotation: Debug.Assert Not Nothing Is swAnn

                         

                          ' Get text format information

                          Debug.Print "File = " & swModel.GetPathName

                          Debug.Print "  " & swAnn.GetName & " <" & swAnn.GetType & ">"

                          For i = 0 To swAnn.GetTextFormatCount - 1

                              Set swTextFormat = swAnn.GetTextFormat(i)

                              ' Change text to be 10mm high, bold, italic, and Comic Sans MS font face

                              'swTextFormat.CharHeight = 0.01

                              ' -------CHANGE POINTS TO 24 FOR TITLES

                              swTextFormat.CharHeightInPts = 24

                              swTextFormat.Bold = True

                              swTextFormat.TypeFaceName = "SWRomnd"

                              bRet = swAnn.SetTextFormat(i, False, swTextFormat): Debug.Assert bRet

                   

                   

                          Next

                          ''#@##################

                     

                          If swAnn.GetType = swAnnotationType_e.swNote Then

                                      Dim swNote As SldWorks.Note

                                      Set swNote = swAnn.GetSpecificAnnotation

                                      Dim myval As Boolean

                                      myval = swNote.SetText("$PRPVIEW:""SW-Configuration Name(Configuration Name)""")

                          End If

                          Set swoNote = swAnn.GetSpecificAnnotation

                          If swoNote.IsBomBalloon() Then

                              swNote.SetBalloon swBalloonStyle_e.swBS_None, swBalloonFit_e.swBF_3Chars

                              swAnn.SetLeader3 swLeaderStyle_e.swNO_LEADER, swLeaderSide_e.swLS_SMART, False, False, False, False

                          End If

                      End If

                     

                  Next j

                   

                   

                   

                   

                  End Sub

              • Re: Linking custom property to drawing view name
                Corry Schneider

                To start, I wrote this code:

                Dim swApp As SldWorks.SldWorks

                Dim swDraw As SldWorks.DrawingDoc

                Dim swView As SldWorks.View

                 

                Sub main()

                Set swApp = Application.SldWorks

                Set swDraw = swApp.ActiveDoc

                Set swView = swDraw.GetCurrentSheet.GetViews()(0)

                 

                swView.SetName2 ("$PRPVIEW:""SW-Configuration Name(Configuration Name)""")

                End Sub

                So yeah, the feature tree shows what I want, the view note says what I want, but the content should say, 42" DIA.

                Am I missing a line to activate the call?

                • Re: Linking custom property to drawing view name
                  Corry Schneider

                  Do we have any updates? I have been working on another project, but I would still like to automate the naming of the views in drawings.