27 Replies Latest reply on Mar 2, 2019 11:54 AM by Deepak Gupta

    Macro to reset property tab

    Nicolò Bernareggi

      Hi evrybody,

       

      i'm looking for a way to create a macro (or any other system) that reset alla the field of the property tab that i've create to fill the field of my personalized titole block.

       

      i hope you would understand my request! my english is so bad!

      Thanks in advance!

        • Re: Macro to reset property tab
          Fifi Riri

          This macro will delete all Custom properties including the ones created by property tab. Modify it as needed.

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim vConf As Variant

              Dim i As Integer

              ClearCustPrps ""

              For Each vConf In swModel.GetConfigurationNames

                  ClearCustPrps CStr(vConf)

              Next

          End Sub

           

          Sub ClearCustPrps(conf As String)

              Dim swCustPropMgr As SldWorks.CustomPropertyManager

              Dim vPropNames As Variant

              Dim vPropName As Variant

              Set swCustPropMgr = swModel.Extension.CustomPropertyManager(conf)

              If Not swCustPropMgr Is Nothing Then

                  swCustPropMgr.GetAll vPropNames, Empty, Empty

                  If Not IsEmpty(vPropNames) Then

                      For Each vPropName In vPropNames

                          swCustPropMgr.Delete vPropName

                      Next

                  End If

              End If

          End Sub

            • Re: Macro to reset property tab
              Nicolò Bernareggi

              thank you! but if i paste the code inside a new macro nothing happend!!!

               

              where i'm wrong??

                • Re: Macro to reset property tab
                  Fifi Riri

                  The model needs to be rebuild.

                  I modified the above macro with a rebuild function:

                   

                  Option Explicit

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Sub main()

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Dim vConf As Variant

                      Dim i As Integer

                      ClearCustPrps ""

                      For Each vConf In swModel.GetConfigurationNames

                          ClearCustPrps CStr(vConf)

                      Next

                      swModel.EditRebuild3

                  End Sub

                   

                  Sub ClearCustPrps(conf As String)

                      Dim swCustPropMgr As SldWorks.CustomPropertyManager

                      Dim vPropNames As Variant

                      Dim vPropName As Variant

                      Set swCustPropMgr = swModel.Extension.CustomPropertyManager(conf)

                      If Not swCustPropMgr Is Nothing Then

                          swCustPropMgr.GetAll vPropNames, Empty, Empty

                          If Not IsEmpty(vPropNames) Then

                              For Each vPropName In vPropNames

                                  swCustPropMgr.Delete vPropName

                              Next

                          End If

                      End If

                  End Sub

              • Re: Macro to reset property tab
                Mithilesh Kapre

                Looks like you want to empty all fields in the Custom Property Pane (under task pane) as below.

                I don't see a way to do that

                • Re: Macro to reset property tab
                  Amen Allah Jlili

                  This is possible but definitely is not worth the investment (Through Windows API). The only thing you can set from the API that is Property Tab Builder related is the template according to my knowledge.

                  • Re: Macro to reset property tab
                    Nicolò Bernareggi

                    I'm sorry if i'm disappeared but the question has fall down in office...but now i was thinking if isn't possible delete the custom property of the drawing (made by property tab builder) if the solution can be the copy of the property from an empty file?

                    What do you think?

                    Is it always difficult to realize?

                    • Re: Macro to reset property tab
                      Amen Allah Jlili

                      What's the error message. Are you sure you have an active document?

                        • Re: Macro to reset property tab
                          Nicolò Bernareggi

                          Yes i have the drawing opened (.slddrw) with the model (.sldprt) inside.

                          this is the error:

                          Capture.JPG

                            • Re: Macro to reset property tab
                              Amen Allah Jlili

                              That explains it. The macro is trying to get the configuration names to delete all properties in all configurations, meanwhile, your active document is a drawing which doesn't have configurations.

                              Try this:

                               

                               

                              Option Explicit
                              
                              
                              Dim swApp As SldWorks.SldWorks
                              Dim swModel As SldWorks.ModelDoc2
                              Sub main()
                                  Set swApp = Application.SldWorks
                                  Set swModel = swApp.ActiveDoc
                                  Dim vConf
                                  ClearCustPrps ""
                                  
                                  If swModel.GetType = SwConst.swDocumentTypes_e.swDocASSEMBLY Or swModel.GetType = SwConst.swDocumentTypes_e.swDocPART Then
                                  
                                      For Each vConf In swModel.GetConfigurationNames
                                          ClearCustPrps CStr(vConf)
                                      Next      
                                  End If
                              End Sub
                              
                              
                              
                              
                              Sub ClearCustPrps(conf As String)
                                  Dim swCustPropMgr As SldWorks.CustomPropertyManage
                                  Dim vPropNames As Variant
                                  Dim vPropName As Variant
                                  Set swCustPropMgr = swModel.Extension.CustomPropertyManager(conf)
                                  If Not swCustPropMgr Is Nothing Then
                                      swCustPropMgr.GetAll vPropNames, Empty, Empty
                                      If Not IsEmpty(vPropNames) Then
                                          For Each vPropName In vPropNames
                                              swCustPropMgr.Delete vPropName
                                          Next
                                      End If
                                  End If
                              End Sub
                              
                              
                              
                              
                              
                                • Re: Macro to reset property tab
                                  Nicolò Bernareggi

                                  no way...launched don't give me back errors but nothing happen at the property maded by property tab builder

                                    • Re: Macro to reset property tab
                                      Amen Allah Jlili

                                      Hm. Sorry I was just pointing why the posted macro didn't work. I don't think that is possible to do what you want in the property tab.

                                      Best,

                                      Amen Jlili

                                      SOLIDWORKS API / PDM API Developer

                                      www.cadsharp.com

                                      • Re: Macro to reset property tab
                                        Deepak Gupta

                                        Are you looking to delete properties from model or drawing?

                                          • Re: Macro to reset property tab
                                            Nicolò Bernareggi

                                            sorry i thought that i already had replied you...yes...i'm trying to reset the custom property in a drawing

                                              • Re: Macro to reset property tab
                                                Fifi Riri

                                                It needs to be rebuild for the Tab builder to update

                                                 

                                                Option Explicit
                                                Dim swApp As SldWorks.SldWorks
                                                Dim swModel As SldWorks.ModelDoc2
                                                Sub main()
                                                    Set swApp = Application.SldWorks
                                                    Set swModel = swApp.ActiveDoc
                                                    Dim vConf As Variant
                                                    Dim i As Integer
                                                    ClearCustPrps ""
                                                    If swModel.GetType = SwConst.swDocumentTypes_e.swDocASSEMBLY Or swModel.GetType = SwConst.swDocumentTypes_e.swDocPART Then
                                                        For Each vConf In swModel.GetConfigurationNames
                                                            ClearCustPrps CStr(vConf)
                                                        Next
                                                    End If
                                                    swModel.EditRebuild3
                                                End Sub
                                                Sub ClearCustPrps(conf As String)
                                                    Dim swCustPropMgr As SldWorks.CustomPropertyManager
                                                    Dim vPropNames As Variant
                                                    Dim vPropName As Variant
                                                    Set swCustPropMgr = swModel.Extension.CustomPropertyManager(conf)
                                                    If Not swCustPropMgr Is Nothing Then
                                                        swCustPropMgr.GetAll vPropNames, Empty, Empty
                                                        If Not IsEmpty(vPropNames) Then
                                                            For Each vPropName In vPropNames
                                                                swCustPropMgr.Delete vPropName
                                                            Next
                                                        End If
                                                    End If
                                                End Sub
                                                
                                                
                                                
                                                
                                                
                                                  • Re: Macro to reset property tab
                                                    Nicolò Bernareggi

                                                    great!! it works! thank you!

                                                    but it works only for the fields that are "open" look at the image in the post of Mithilesh Kapre posted on 30-ott-2018 20.49...for example it works on Project Name, Folder Name, Description, Part Number...but don't resets the fileds with a "dropdown menu" like Designer, Detailed by and also te date...

                                                     

                                                    Is it possible to work also on these?

                                                      • Re: Macro to reset property tab
                                                        Deepak Gupta

                                                        Nicolò Bernareggi wrote:

                                                         

                                                        great!! it works! thank you!

                                                        but it works only for the fields that are "open" look at the image in the post of Mithilesh Kapre posted on 30-ott-2018 20.49...for example it works on Project Name, Folder Name, Description, Part Number...but don't resets the fileds with a "dropdown menu" like Designer, Detailed by and also te date...

                                                         

                                                        Is it possible to work also on these?

                                                        Codes works for me i.e. they delete all properties. If I set the codes to blank out the values but keep the property name, that works as well expect in case the property type is a date or yes/no as these can't be reset unless you change the property type.

                                                          • Re: Macro to reset property tab
                                                            Nicolò Bernareggi

                                                            so, if i don't change the property type, it isn't possible delete the fields?

                                                            with "change the property type" you mean for example to change the dropdown menu whit a box where i can type?

                                                             

                                                            Thanks!

                                                              • Re: Macro to reset property tab
                                                                Fifi Riri

                                                                "change the property type" means changing the custom property type itself. (Date to string)

                                                                But instead you could change the fields in the Tab Builder for simple Text box, that should work.

                                                                  • Re: Macro to reset property tab
                                                                    Nicolò Bernareggi

                                                                    it works if I use the "text box"...but I prefer to leave it like a date or a "dropdown menu"!

                                                                      • Re: Macro to reset property tab
                                                                        Deepak Gupta

                                                                        Try these codes (these are not working with Yes/No type)

                                                                         

                                                                        Option Explicit

                                                                        Dim swApp As SldWorks.SldWorks

                                                                        Dim swModel As SldWorks.ModelDoc2

                                                                        Sub main()

                                                                            Set swApp = Application.SldWorks

                                                                            Set swModel = swApp.ActiveDoc

                                                                            Dim vConf As Variant

                                                                            Dim i As Integer

                                                                            ClearCustPrps ""

                                                                            If swModel.GetType = SwConst.swDocumentTypes_e.swDocASSEMBLY Or swModel.GetType = SwConst.swDocumentTypes_e.swDocPART Then

                                                                                For Each vConf In swModel.GetConfigurationNames

                                                                                    ClearCustPrps CStr(vConf)

                                                                                Next

                                                                            End If

                                                                            swModel.EditRebuild3

                                                                        End Sub

                                                                         

                                                                        Sub ClearCustPrps(conf As String)

                                                                         

                                                                            Dim swCustPropMgr As SldWorks.CustomPropertyManager

                                                                            Dim vPropNames As Variant

                                                                            Dim vPropName As Variant

                                                                            Dim vPropTypes As Variant

                                                                            Dim j As Long

                                                                            Dim custPropType As Long

                                                                         

                                                                            Set swCustPropMgr = swModel.Extension.CustomPropertyManager(conf)

                                                                            If Not swCustPropMgr Is Nothing Then

                                                                                swCustPropMgr.GetAll vPropNames, vPropTypes, Empty

                                                                                 

                                                                                If Not IsEmpty(vPropNames) Then

                                                                                    For j = 0 To swCustPropMgr.Count - 1

                                                                                        custPropType = swCustPropMgr.GetType2(vPropNames(j))

                                                                                        swCustPropMgr.Delete vPropNames(j)

                                                                                        swCustPropMgr.Add2 vPropNames(j), custPropType, Empty

                                                                                    Next j

                                                                                End If

                                                                            End If

                                                                         

                                                                        End Sub

                                                • Re: Macro to reset property tab
                                                  Cad Admin

                                                  In some cases, i find it easier to delete the custom property itself, then re-add it back in the same macro.