Give value to cus.prop. with equation.
Give value to cus.prop. with equation.
(OP)
Hello,
I want to do the following:
Create a part with prop. "Maakdeel" is yes or no. Then I want to fill the prop. "Artikelnummer" depending on "Maakdeel". If "Maakdeel"=yes then "Artikelnummer"=SLD$PRP:"SW-File Name" else "Artikelnummer"=0
How can i do this?
I want to do the following:
Create a part with prop. "Maakdeel" is yes or no. Then I want to fill the prop. "Artikelnummer" depending on "Maakdeel". If "Maakdeel"=yes then "Artikelnummer"=SLD$PRP:"SW-File Name" else "Artikelnummer"=0
How can i do this?






RE: Give value to cus.prop. with equation.
RE: Give value to cus.prop. with equation.
CODE
The custom properties "Artikelnummer" and "Maakdeel" must already be present in the file for this to work. Upon every rebuild, this equation will set the Artikelnummer property based on the value of Maakdeel.
-handleman, CSWP (The new, easy test)
RE: Give value to cus.prop. with equation.
RE: Give value to cus.prop. with equation.
RE: Give value to cus.prop. with equation.
And for anyone else who may ever stumble across this thread, there are a few red herrings here.
The "IIf" statement doesn't really do a comparison. Its only function is to allow 2 lines of code to be packed into a single line. This is because the IIf statement actually evaluates both the truepart and falsepart when code is executed.
The truepart of the IIf statement always sets "Artikelnummer" to "0". Every time.
The falsepart (which gets evaluated/executed after the truepart) will attempt to set "Artikelnummer" to the desired property value. It will succeed only if "Maakdeel" is "Yes". If "Maakdeel" is anything other than "Yes", the statement will fail. If this were in a VBA macro, it would raise a runtime error. Since it is in an equation, it just causes the equation to fail, giving a result of "???". We don't care about this.
The way it is forced to fail is by forcing part.Extension.CustomPropertyManager([configname]) to fail.
This failure is caused by feeding a non-existent configuration name to CustomPropertyManager(). If you give CustomPropertyManager() a zero-length string ("") you get the custom property manager for the part. If you feed it a configuration name, you get the custom property manager for configuration-specific custom properties. If you feed it a non-existent config name, it will fail. If "Maakdeel" is "Yes", we feed a zero-length string. If "Maakdeel" is not yes, we feed a string of 100 "z"s in a row. This will fail unless you happen to create configuration "zzzzzzzz.....".
The way we get a zero-length string or a string of 100 "z"s is by using the String function together with the result of StrComp. If "Maakdeel" is "Yes", then StrComp of Maakdeel and "Yes" will return zero. This will cause String to return a zero length string. If Maakdeel is not "Yes", StrComp will return a nonzero value. This is multiplied by 100, giving us 100 "z"s in a row.
Oh, and this is unsupported behavior by SolidWorks. It may not work in future versions.
-handleman, CSWP (The new, easy test)
RE: Give value to cus.prop. with equation.
Beautiful explanation! A star for you.
- - -Updraft
P.S. I love the phrase "unsupported behaviour"! I can see using it in choice snarky comments. Thanks for that too!