Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Property to part 4

Status
Not open for further replies.

swfan

Mechanical
Dec 2, 2008
15
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.
 
Replies continue below

Recommended for you

Sorry about that,I didn't realise I'd done it.
 
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)
 
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".
 
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)
 
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)
 
Handleman,

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

[cheers]
 
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)
 
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)
 
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)
 
 http://files.engineering.com/getfile.aspx?folder=77742b1d-bfe9-490e-8b0c-870de9156d88&file=EqunMatlAssign2009.SLDPRT
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)
 
Thank you, thank you. I shall cheerfully misinterpret your mocking as a compliment... ;-)

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. :)

-handleman, CSWP (The new, easy test)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor