9 Replies Latest reply on Jul 31, 2014 7:09 PM by Ben Matheson

    Get $PRPSHEET Property from drawing sheet ref part

    Ben Matheson

      Hi

       

      I am looking for code to get a $PRPSHEET property from the refrence part/cfg of a drawing sheet. Google'n around I have found some information but nothing i could get to work.

       

      as simple as possible, from any given drawing sheet I am trying to get $PRPSHEET:"STEP" into a String that i can Debug.Print

       

      Thanks for any help

       

      BenM

        • Re: Get $PRPSHEET Property from drawing sheet ref part
          Matt Martens

          Set swView = swModel.GetFirstView

          Set swView = swView.GetNextView

          Set swRefModel = swView.ReferencedDocument

          "your string variable" = swRefModel.CustomInfo("Revision")

           

          Here is a sample from one of my macros. The swModel is the IModelDoc2 object of the open drawing document. The swView is an IView object and the swRefModel is an IModelDoc2 object. The reason you have to do GetFirstView/GetNextView is the 1st view is actually the sheet format. If the property is configuration specific, you will have to add more code to handle that.

          • Re: Get $PRPSHEET Property from drawing sheet ref part
            Matt Martens

            "your string variable" = swRefModel.CustomInfo2(swRefModel.ConfigurationManager.ActiveConfiguration.Name, "Revision")

              • Re: Get $PRPSHEET Property from drawing sheet ref part
                Ben Matheson

                EDIT: This works but only for 1 sheet. It apears to be the first sheet I run it from. When I switch sheets The refrence dosn't update. Does this make sences?

                  • Re: Get $PRPSHEET Property from drawing sheet ref part
                    Ben Matheson

                    I think i am doing somthing fundamentally wrong because now this is just returning "00" over and over again. 00 was the correct value for one of the sheets but it seems to be stuck.

                     

                    anyway, in a drawing i should be able to switch sheets run and it should return the same value as $PRPSHEET:"STEP". "STEP" is a configuration spesific property

                     

                    This is what I've been working with:

                     

                    Option Explicit

                        Dim swApp               As SldWorks.SldWorks

                        Dim swModel             As SldWorks.ModelDoc2

                        Dim swModelDocExt       As SldWorks.ModelDocExtension

                        Dim swExportData        As SldWorks.ExportPdfData

                        Dim swCustPrpMgr        As SldWorks.CustomPropertyManager

                        Dim Checker             As Object

                        Dim swView              As SldWorks.View

                        Dim stepno              As String

                        Dim swRefModel          As SldWorks.ModelDoc2

                       

                       

                    Sub main()

                        Set swApp = Application.SldWorks

                        Set swModel = swApp.ActiveDoc

                      

                      

                        Set swView = swModel.GetFirstView

                        Set swView = swView.GetNextView

                        Set swRefModel = swView.ReferencedDocument

                        stepno = swRefModel.CustomInfo2(swRefModel.ConfigurationManager.ActiveConfiguration.Name, "STEP")

                      

                        Debug.Print stepno

                      

                      

                     

                    End Sub

                      • Re: Get $PRPSHEET Property from drawing sheet ref part
                        Matt Martens

                        That's because no matter what sheet you are on, the first view of the model stays the same. In order to get just the views of a certain sheet, you need to obtain the ISheet object using IDrawingDoc::GetCurrentSheet and get the views associated with that sheet using ISheet::GetViews. It returns an array of IView objects, so you will have to separate them into individual objects for the IView::ReferencedDocument and subsequent actions.

                         

                        By the way, have you tried looking through the API help. All of this is in there along with examples and other things.

                          • Re: Get $PRPSHEET Property from drawing sheet ref part
                            Ben Matheson

                            Thanks Matt,The above information is good, I'm sure i will get this work

                             

                            Yes, I have been looking in there a lot. I'm just not able to get this to work. It is definetly lack of experience/skill on my part.

                              • Re: Get $PRPSHEET Property from drawing sheet ref part
                                Ben Matheson

                                So I have made progress and I'm very close to getting this. This is the code

                                 

                                 

                                '----------------------------------------

                                Option Explicit

                                 

                                 

                                Dim swApp                   As Object

                                Dim swModel                 As SldWorks.ModelDoc2

                                Dim swDraw                  As SldWorks.DrawingDoc

                                Dim swSheet                 As SldWorks.Sheet

                                Dim swView                  As SldWorks.View

                                Dim swRefModel              As SldWorks.ModelDoc2

                                Dim strStepNo               As String

                                 

                                 

                                 

                                 

                                Sub main()

                                 

                                 

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                                Set swDraw = swModel

                                 

                                 

                                Set swSheet = swDraw.GetCurrentSheet

                                 

                                 

                                 

                                 

                                'Print Current Sheet Name

                                Debug.Print swSheet.GetName

                                 

                                 

                                Set swView = swDraw.GetFirstView

                                Set swView = swView.GetNextView

                                 

                                 

                                'Print name of first view in sheet

                                Debug.Print swView.GetName2

                                 

                                 

                                Set swRefModel = swView.ReferencedDocument

                                strStepNo = swRefModel.CustomInfo2(swRefModel.ConfigurationManager.ActiveConfiguration.Name, "STEP")

                                 

                                 

                                Debug.Print strStepNo

                                 

                                 

                                 

                                 

                                End Sub

                                '--------------------------------------------------

                                 

                                I've got the current view, The first view and the refrence model but I can't figure out how to refrence the correct configuration. The code"" swRefModel.CustomInfo2(swRefModel.ConfigurationManager.ActiveConfiguration.Name, "STEP") ""returns the value from the last open configuration not the configuration refrenced in the first view (swRefModel)

                                  • Re: Get $PRPSHEET Property from drawing sheet ref part
                                    Ben Matheson

                                    OK, I figured it out. There my be a better way to do this but this is what i have come up with, Thanks for the help Matt

                                     

                                     

                                     

                                    '++++++++++++++++++++++++++

                                    Option Explicit

                                     

                                     

                                    Dim swApp                   As Object

                                    Dim swModel                 As SldWorks.ModelDoc2

                                    Dim swDraw                  As SldWorks.DrawingDoc

                                    Dim swSheet                 As SldWorks.Sheet

                                    Dim swView                  As SldWorks.View

                                    Dim swRefModel              As SldWorks.ModelDoc2

                                    Dim strDWGCfgName           As String

                                    Dim strStepNo               As String

                                     

                                     

                                     

                                     

                                    Sub main()

                                     

                                     

                                    Set swApp = Application.SldWorks

                                    Set swModel = swApp.ActiveDoc

                                    Set swDraw = swModel

                                     

                                     

                                    Set swSheet = swDraw.GetCurrentSheet

                                     

                                     

                                     

                                     

                                    'Print Current Sheet Name

                                    Debug.Print swSheet.GetName

                                     

                                     

                                    Set swView = swDraw.GetFirstView

                                    Set swView = swView.GetNextView

                                     

                                     

                                    strDWGCfgName = swView.ReferencedConfiguration

                                     

                                     

                                     

                                     

                                    'Print name of first view in sheet

                                    Debug.Print swView.GetName2

                                     

                                     

                                    Set swRefModel = swView.ReferencedDocument

                                    'strStepNo = swRefModel.CustomInfo2(swRefModel.ConfigurationManager.ActiveConfiguration.Name, "STEP")

                                    strStepNo = swRefModel.CustomInfo2(strDWGCfgName, "STEP")

                                     

                                     

                                     

                                     

                                    Debug.Print strStepNo

                                     

                                     

                                     

                                     

                                    End Sub