6 Replies Latest reply on Mar 4, 2016 12:26 AM by Deepak Gupta

    How do I use a property from a part/assembly from a drawing?

    Steven Mills

      I need to use a property from a part/assembly while in a drawing, and output it's value as a string. What is the function call for this?

       

      And when there is more than one part/assembly in a drawing, how do I make sure I am using the same one the drawing format of the first sheet is set to? The setting that the red arrow is pointing to in the attached picture.

        • Re: How do I use a property from a part/assembly from a drawing?
          Deepak Gupta

          You need to get the ReferencedDocument and then get the custom property value from model.

           

          Look at these examples

          Get Document Referenced by Drawing View Example (VBA)

          Get Configurations Referenced in View Example (VBA)

           

          And before you do that, you can activate the first sheet and make that as current sheet to fetch view.

            • Re: How do I use a property from a part/assembly from a drawing?
              Steven Mills

              Thank you, that's a good start. But I need what is referenced by the Drawing Sheet Format of the first sheet. What the drawing sheet format looks for when you type $PRPSHEET in a note in it. Not one of the Drawing Views. I highlighted the object in SW that I am talking about in the attached pic.

               

              Also, how do I get a user defined property from that referenced part/assembly? I know the name of the property, in this case "REVISION". Yes, we are putting the revision level on the parts/assemblies themselves instead of the drawings.

                • Re: How do I use a property from a part/assembly from a drawing?
                  Deepak Gupta

                  Steven Mills wrote:

                   

                  Thank you, that's a good start. But I need what is referenced by the Drawing Format of the first sheet. What the drawing format looks for when you type $PRPSHEET in a note in the format. Not one of the Drawing Views.

                   

                  This is usually from the first view inserted.

                   

                  Steven Mills wrote:

                   

                  Also, how do I get a user defined property from that referenced part/assembly? I know the name of the property, in this case "REVISION". Yes, we are putting the revision level on the parts/assemblies themselves instead of the drawings.

                  Here is an example

                   

                  Dim swApp               As SldWorks.SldWorks
                  Dim swModel             As SldWorks.ModelDoc2
                  Dim swDrawModel         As SldWorks.ModelDoc2
                  Dim swDraw              As SldWorks.DrawingDoc
                  Dim swView              As SldWorks.View
                  Dim swCustPrpMgr        As SldWorks.CustomPropertyManager
                  Dim Value               As String
                  Sub main()
                  
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
                  
                  Set swDraw = swModel
                  Set swView = swDraw.GetFirstView
                  Set swView = swView.GetNextView
                  Set swDrawModel = swView.ReferencedDocument
                  
                  Set swCustPrpMgr = swDrawModel.Extension.CustomPropertyManager("")
                  swCustPrpMgr.Get3 "REVISION", False, "", Value
                  Debug.Print Value
                  
                  End Sub
                  
                    • Re: How do I use a property from a part/assembly from a drawing?
                      Steven Mills

                      Usually, but sometimes it is manually overridden, so I need what the Drawing Sheet Format referencing.

                       

                      And that code is exactly what I am looking for I think. Let me try it and see if it works.

                      EDIT: Ok, very basic question from a low-skilled programmer to a higher skilled one. How do I turn line 19 dim Value into a string that I can use on another part of the code? It's kind of useless to me if I can only print it into the immediate window.

                • Re: How do I use a property from a part/assembly from a drawing?
                  Steven Mills

                  Maybe it would help if I show what I have so far. And I am using SW2016. I basically need to populate string "A" with the customProperty "REVISION" property of the part/assembly the drawing sheet format of the first page of a drawing is using.

                   

                  ' Save As PDF.swp --------------------------------------------03/21/2013
                  '
                  ' Description: Macro to save active Drawing file as PDF in the same location
                  '
                  ' Precondition: Any active SolidWorks Drawing file.

                  ' ------------------------------------------------------------------------------
                  ' This macro is provided as is.  No claims, support, refund, safety net, or
                  ' warranties are expressed or implied.  By using this macro and/or its code in
                  ' any way whatsoever, the user and any entities which the user represents,
                  ' agree to hold the authors free of any and all liability.  Free distribution
                  ' and use of this code in other free works is welcome.  If any portion of
                  ' this code is used in other works, credit to the authors must be placed in
                  ' that work within a user viewable location (e.g., macro header).  All other
                  ' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
                  ' without the expressed written consent by the authors.  Use at your own risk!
                  ' ------------------------------------------------------------------------------
                  ' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
                  ' ------------------------------------------------------------------------------

                  Dim swApp As SldWorks.SldWorks
                  Dim swModel As SldWorks.ActiveDoc
                  Dim Path As String
                  Dim A As String
                  Dim Value As String

                  Sub MakePDF()

                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc

                  Dim A As String

                  If swModel Is Nothing Then
                      swApp.SendMsgToUser ("To be used for Drawings only, Open a Drawing first and then TRY!")
                      Exit Sub
                  End If

                  If swModel.GetType <> swDocDRAWING Then
                      swApp.SendMsgToUser ("To be used for Drawings only, Open a Drawing first and then TRY!")
                      Exit Sub
                  End If

                  'A =

                  Path = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6) & " " & A & ".PDF"
                  swModel.SaveAs3 "" & Path & "", 0, 0

                  End Sub