7 Replies Latest reply on Jul 9, 2012 10:54 AM by Jean Brun

    Cocatenate and extract one letter from a $prp

    Jean Brun

      Hi all
      In a drawing, to create a barcode, I need to make up a note like  this:

       

      $PRPSHEET:"SW-File Name" & left($PRP:"SW-Sheet  Name",1)

       

      ie, make a note with one $prp value + the first letter of  another $prp value

       

      Is there a way to write that inside a  drawing?

       

      Thanks

        • Re: Cocatenate and extract one letter from a $prp
          Troy Peterson

          You will need to create your own script to do what you want to do...

            • Re: Cocatenate and extract one letter from a $prp
              Jean Brun

              Another way:

              Is there any way, for example in the part, to use some chain processing in a property :

               

              For example:

              short=left("property",1)

               

              Thanks

              JM

                • Re: Cocatenate and extract one letter from a $prp
                  Josh Brady

                  No.  There is no way to parse, modify, etc. custom property linked text in a drawing.  It is possible to do in a part or assembly model, but not a drawing.  You could create a macro that would update the note whenever it is run, but you can't have it automatically update.

                   

                  If you could figure out a way to generate your bar code based solely on information in the part model (like not including the first letter of the sheet name) then it would be possible.

                    • Re: Cocatenate and extract one letter from a $prp
                      Jean Brun

                      Not sure if I understand correctly (English is not my first language) -(or maybe I understand what I would like to)

                       

                      Do you mean that I could, in a part, manipulate property chains and for example make a property from another. I have been trying that without succes so far, either with equations, or by trying to put a "syntaxly correct" VB value for the prop.

                       

                      Would there be a way to have, in a part, for example:

                       

                      property= left($PRP:"SW-Configuration Name", 1)

                       

                      Regards

                      TIA

                      JM

                        • Re: Cocatenate and extract one letter from a $prp
                          Josh Brady

                          Yes.  You have to use VBA and SW API functions inside equations to do it.

                           

                          The following equation will set the configuration-specific property "concat" to the first letter of the configuration name.

                           

                          The property must exist already.  You can change the name of the property to whatever you want - just keep the name split in two pieces. 

                           

                          "dummy"= part.configurationmanager.activeconfiguration.custompropertymanager.set("con" & "cat", left(part.configurationmanager.activeconfiguration.name,1))

                           

                          The equation above will only set the property if it exists already.  If you are not certain that the property exists or not, you can use this equation:

                           

                          "dummy"= iif(true,part.configurationmanager.activeconfiguration.custompropertymanager.delete("con" & "cat"),part.configurationmanager.activeconfiguration.custompropertymanager.add2("con" & "cat",30, left(part.configurationmanager.activeconfiguration.name,1)))

                            • Re: Cocatenate and extract one letter from a $prp
                              Jean Brun

                              Hit the wrong button, sorry.

                               

                              This is the right answer and it works beautifully.

                               

                              Thanks again

                              JM

                              • Re: Cocatenate and extract one letter from a $prp
                                Jean Brun

                                Josh,

                                I used your advice and came out with a working solution (SW2009). The only problem was that the equation would be added only to the current configuration. The solution was to edit the equation in SW -changing nothing, just edit and close- and then the equation was added to all configs.

                                 

                                Then we switched to SW2012:

                                When we apply the equation, it works fine, still to one config. If we edit the equation, we get a syntax error, that I can't find. It works fine if we go through all configs and call the macro for every one. But in some cases we have 40 configs...

                                 

                                Help!

                                 

                                The macro that writes equation:

                                -------------

                                Dim swApp As Object

                                 

                                Dim Part As Object

                                Dim boolstatus As Boolean

                                Dim longstatus As Long, longwarnings As Long

                                 

                                Sub main()

                                 

                                Set swApp = Application.SldWorks

                                 

                                Set Part = swApp.ActiveDoc

                                boolstatus = Part.Extension.SelectByID2("Equations", "EQNFOLDER", 0, 0, 0, False, 0, Nothing, 0)

                                Part.ClearSelection2 True

                                Part.DeleteAllRelations

                                 

                                Part.AddRelation """dummy""= iif(true,part.configurationmanager.activeconfiguration.custompropertymanager.delete(""let"" & ""tre""),part.configurationmanager.activeconfiguration.custompropertymanager.add2(""let"" & ""tre"",30, left(part.configurationmanager.activeconfiguration.name,1)))"

                                End Sub

                                ---------------------------------

                                 

                                The equation written in SW:

                                 

                                "dummy"  = iif ( "true" , "part.configurationmanager.activeconfiguration.custompropertymanager.delete" ( "let" "&" "tre" ) , "part.configurationmanager.activeconfiguration.custompropertymanager.add2" ( "let" "&" "tre" , 30 , left ( "part.configurationmanager.activeconfiguration.name" , 1 ) ) )

                                 

                                (adds the "lettre" config specific property valued with 1st caracter of the config. name)

                                 

                                TIA

                                JM