×
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

Custom Property to part
4

Custom Property to part

Custom Property to part

(OP)
Hello world,
I know it's easy enough to specify a material in Custom Properties by linking to the part material but does anyone know if it's possible to link the otherway round. In other words can you make the part material dependent upon the material specified in the custom properties. I have the 'Propagator' program that allows me to batch change the material in custom properties but not the material property within the part.
Thanks.

RE: Custom Property to part

Just thought I would mention that your "attachment" is a link to http://www.eng-tips.com/  

We are already here so we kinda don't need a link smile

Flores

RE: Custom Property to part

(OP)
Sorry about that,I didn't realise I'd done it.

RE: Custom Property to part

4
This can be done pretty easily using VBA code embedded in an equation.  Just add the following equation to any part:

CODE

"dummy"= Part.SetMaterialPropertyName2(Part.ConfigurationManager.ActiveConfiguration.Name, "", Part.CustomInfo2("", "Material"))

The "dummy" variable really doesn't do anything.  It's just there to create an equation that is valid for SW.  The VBA code on the right-hand side of the "=" is what sets the material.  This equation will change the material for the currently active configuration to whatever is in the "Material" custom property.  The value in "Material" must match (case-sensitive) a material name in the default .sldmat material database.  If you want to specify a different database, change the first "" to a full path (including .sldmat) inside quotes.  If your custom property for material is named something different from "Material", change the equation to match.

The above equation will reference the part-level custom properties.  You can use configuration-specific custom properties if you want.  Just replace the second "" with

Part.ConfigurationManager.ActiveConfiguration.Name

no quotes.  Each configuration's material will be driven by the configuration-specific "Material" custom property.

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

(OP)
Thanks for the help Handleman,it may be simple to you but as far as I'm concerned it's magic. Is it possible to make this work in "custom properties" instead of "configeration specific".

RE: Custom Property to part

Sure!  Just use the equation as it's posted here in the thread rather than the one in the example file.  Assuming you are using the default material database you can just copy the text above and paste it into a new equation.  If the name of the custom property where you put the material is different, you will have to change "Material" to whatever you are using.  For example, if you put the material into a property called "RawMaterial", your equation would read:

CODE

"dummy"= Part.SetMaterialPropertyName2(Part.ConfigurationManager.ActiveConfiguration.Name, "", Part.CustomInfo2("", "RawMaterial"))

The custom property name is also case-sensitive, by the way, so "rawmaterial" is not the same as "RawMaterial".

 

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

You also may want to note a couple of things.  You can create a part template with this equation already in it if you want to do this often.  Also, if the equation doesn't find the custom property it's looking for, or if the custom property value doesn't match a material name in the database, the material will be changed to "Not Specified".  If you then manually change the material, it will change back to "Not Specified" at the next rebuild.

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

Handleman,

FYI ... the equation in the sample part is reporting a syntax error for SW2009-SP1.

cheers

RE: Custom Property to part

Interesting... I wonder if they closed that loophole.  I did submit the VBA capability in equations to SW as a security hole some time ago.  

Does this equation work?

"dummy"=msgbox("hello")

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

Yes, that appears to work fine.

cheers

RE: Custom Property to part

Hmm, not totally closed then.  Guess I've got some playing to do when we finally get '09 installed.   

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

Finally got '09 installed and I'm testing.  In case anyone's interested, after messing with this for way too long, I got it figured out... sort of.

I was wrong previously when I said that the custom property name is case-sensitive.  It isn't in 2008.  If your property name is "RawMaterial", you can put "RAWMATERIAL" or "rawmaterial" in your equation and it will still work.

Now... here's the really screwy thing for 2009 (at least SP1).  If the case matches exactly between the equation and the custom property, you get the syntax error.  That's right, if the case does match, you get the error.  If the case doesn't match, it works just fine.  So if your property name is "RawMaterial", you can use anything in the equation except "RawMaterial".  "RAWMATERIAL", "rawMATERIAL", "RAWmaterial", as long as the case doesn't match exactly it will work.

I think that's one of the screwiest things I've seen yet.

I've attached the 2009 version, with the equation modified to look for "MatErial".

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

OK, during perusal of the "What's New" document, I figured out what's going on here.  SW09 added the capability of referencing custom properties directly in equations just by typing in the property name in quotes - case sensitive.   Before the equation gets passed to the VBA interpreter, SW looks through it and replaces any exact property name in quotes with its value.  However, you get the syntax error if you try to reference a property that is not entirely numeric.  This seems to happen "before" the equation gets passed to the VBA interpreter.

So, what was happening before was that SW saw the string "Material" in the equation, checked the custom properties, and found a non-numeric value there, which throws up the syntax error.  Because the new custom property referencing capability is case sensitive, it doesn't match "MATERIAL" up with "Material".

-handleman, CSWP (The new, easy test)

RE: Custom Property to part

handleman,

I think you should go work for SolidWorks.

cheers

RE: Custom Property to part

And they should pay you BIG bucks!

RE: Custom Property to part

Thank you, thank you.  I shall cheerfully misinterpret your mocking as a compliment...  winky smile

I have thought about looking into seeing what opportunities might look like at a VAR... Not sure if I could be polite enough to actually deal with end users.  smile

-handleman, CSWP (The new, easy test)

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