×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Give value to cus.prop. with equation.
6

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?

 

RE: Give value to cus.prop. with equation.

One method would be to use the IF function in a Design Table.

RE: Give value to cus.prop. with equation.

6
Another method would be to use VBA code embedded into an equation.  Go to Tools->Equations and add a new equation.  Paste in this equation:

CODE

"dummy"= IIf(True, part.Extension.CustomPropertyManager("").Set("artikelnummer", "0"), part.Extension.CustomPropertyManager(String(StrComp("Yes", part.Extension.CustomPropertyManager("").Get("maakdeel")) * 100, "z")).Set("artikelnummer", "SLD$PRP:""SW" & "-File Name"""))

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.

(OP)
If I copy this in an euqation. It doesn't work...

 

RE: Give value to cus.prop. with equation.

(OP)
Sorry, it does work! Thank you!!!

RE: Give value to cus.prop. with equation.

Glad it worked for you!

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.

Handleman,

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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources