17 Replies Latest reply on May 1, 2017 12:34 AM by Deepak Gupta

    Custom Properties Template Macro

    Robert Havill

      I have a large number of drawings that I need to change the custom properties template on. I tried to record a macro for it but for some reason it would not record the change (i looked at the code and it showed nothing but the setup). Does anyone know of a way to make a macro that will do this?

        • Re: Custom Properties Template Macro
          Christian Chu

          How about using CusProp Tab Builder which is inlcuded with SW?

          • Re: Custom Properties Template Macro
            Nilesh Patel

            Hi Robert,

             

            Do you just want to change the values of custom properties or the custom properties themselves in the drawing?

             

            Regards,

            • Re: Custom Properties Template Macro
              Artem Taturevych

              Hi Robert,

               

              You might want to look at Custom Properties Manager task in #TASK

               

              Here is the short demo video: http://cloud.ic3d.com.au.s3.amazonaws.com/sharp_task/videos/Sharptask_custo_prop_mgr.mp4

               

              This task allows to add/set, rename, delete properties in a batch.

               

              Please note that Add action will either add or set/change the property value (if it already exists).

               

              Please be careful with batch operations! I would recommend to backup your data before running any batch operations.

               

              Thanks,

              Artem

              • Re: Custom Properties Template Macro
                Deepak Gupta

                Robert, there are currently no API to access to the Custom Property Tab Builder. So your only option is do those changes manually OR use API to just update the properties.

                 

                Please vote for SPR #:542212

                • Re: Custom Properties Template Macro
                  John Stoltzfus

                  Robert Havill - IMO it is always best to control the Custom Properties at the Part or Assembly level, having the Drawing Custom Properties override the Part/Assembly Custom Properties can get messy.  Take a look at the attached macro that was written by Markku Lehtola - This macro will read every custom property that you list in a single folder, so it works well with parts and assemblies that are specific to a project.  What you need to do is change or add the search path and change the custom properties that I have listed in each column.. This macro reads all the Custom Properties that you list and copies them into the spreadsheet, then you can change those values and feed it back to the part/assembly file..

                  • Re: Custom Properties Template Macro
                    Jozef Michálik

                    Hello Robert Havill I have the same problem for a few years (since 2012) waiting for this obvious mistake to be repaired by the API support. Adding a property is not a problem, but the problem is when you want to edit it and you do not have a good user interface (New Task Pain Template with a new added property). And in fact, this concerns mainly the library parts (there is a lot of them). I have to go over 50,000 parts by hand. And it sucks.

                      • Re: Custom Properties Template Macro
                        Deepak Gupta

                        Is that a custom property and same for all files? If yes then you can use SW Document Manager (you would have to request for the free key) and can add that property without opening the files.

                         

                        And in case of configuration, you can a use a macro to add that.

                         

                        You can also try this free and awesome tool called to batch add/update properties. #TASK

                          • Re: Custom Properties Template Macro
                            Jozef Michálik

                            Thanks for the link to #TASK   
                            Actually, I'd rather use a macro ...


                            But to better explain why I would like to change Task Pain Template with Macro. Our company supplies all over the world, and so we need multilingual documentation
                            . See the preview on the picture.

                             

                            Vlastnosti.jpg

                             

                            Now imagine that we need documentation in Chinese or Russian language. In fact, you add a new property, but how do you define its value when you do not have a Chinese or a Russian keyboard. You need a list of values from which you just select a value (combo box)

                            Finally we are trying to solve this by using a macro that according to one property value finds and writes the others. But still when you need sth  to change, it´s a problem. (You must copy from database and paste.) We try to avoid this doing it manually by using export xml from our 3DExperience database. The macro we are using is right here. I hope it can help someone.

                             

                             

                            Dim swApp As SldWorks.SldWorks

                            Dim swModel As SldWorks.ModelDoc2

                            Dim NazovSL As String

                            Dim NazovAN As String

                            Dim NazovNE As String

                            Dim NazovFR As String

                            Dim NazovRU As String

                             

                             

                            Sub main()

                             

                                    Set swApp = Application.SldWorks

                                    Set swdoc = swApp.ActiveDoc

                                    Set swConfigMgr = swdoc.ConfigurationManager

                                    Set ActiveConfig = swConfigMgr.ActiveConfiguration

                                    Set OpenDoc = swApp.ActiveDoc()

                             

                                    ActConfigName = ActiveConfig.Name

                                               

                                    NazovSL = swdoc.GetCustomInfoValue(ActConfigName, "Nazov")

                             

                                         If NazovSL = "" Then

                                           swApp.SendMsgToUser ("Zadaj Názov dielu! ")

                                           End

                                      End If

                             

                                    ReadXml ("D:\#Kniznica_SolidWorks\_System\Názov Dielu.xml")

                             

                                    value = swdoc.DeleteCustomInfo2(ActConfigName, "NazovA")

                                    value = swdoc.AddCustomInfo3(ActConfigName, "NazovA", swCustomInfoText, NazovAN)

                                   

                                    value = swdoc.DeleteCustomInfo2(ActConfigName, "NazovN")

                                    value = swdoc.AddCustomInfo3(ActConfigName, "NazovN", swCustomInfoText, NazovNE)

                                   

                                    value = swdoc.DeleteCustomInfo2(ActConfigName, "NazovF")

                                    value = swdoc.AddCustomInfo3(ActConfigName, "NazovF", swCustomInfoText, NazovFR)

                                   

                                    value = swdoc.DeleteCustomInfo2(ActConfigName, "NazovR")

                                    value = swdoc.AddCustomInfo3(ActConfigName, "NazovR", swCustomInfoText, NazovRU)

                               

                            End Sub

                             

                            Private Sub ReadXml(ByVal Your_file)

                               

                                Dim xmlDoc 'this is MSXML2.DOMDocument

                                Set xmlDoc = CreateObject("MSXML2.DOMDocument")

                                If Not xmlDoc.Load(Your_file) Then

                                    MsgBox xmlDoc.parseError.reason

                                Else

                                   

                                 Dim xmlNode  'this is a MSXML2.IXMLDOMElement

                                

                                 For Each xmlNode In xmlDoc.childNodes

                                    Call recurseNodes(xmlNode)

                                 Next

                                End If

                               

                               

                            End Sub

                            Private Sub recurseNodes(ByVal xmlNode)

                                Dim TheSubNode

                                If xmlNode.hasChildNodes Then

                                

                                    For Each TheSubNode In xmlNode.childNodes

                                        If TheSubNode.baseName = "Názov_x0020_Dielu" Then

                                               If TheSubNode.childNodes.Item(1).text = NazovSL Then

                                                    NazovAN = TheSubNode.childNodes.Item(2).text

                                                    NazovFR = TheSubNode.childNodes.Item(3).text

                                                    NazovNE = TheSubNode.childNodes.Item(4).text

                                                    NazovRU = TheSubNode.childNodes.Item(5).text

                                               End If

                                            End If

                                        Call recurseNodes(TheSubNode)

                                    Next

                                End If

                            End Sub