[Closed] for i = geometry issue
Hi all
I have a simple script that changes object wirecolours based on polycount, it has always worked fine but it seems now I am using Vray fur it has broken? I know this is a broad question but is there any easy way to filter out vray fur objects from the procedure or any objects that would appear in the geometry list but would not have a polycount?
Any help much appreciated.
Thanks
Will
You can filter using classof…
for i in geometry where classof i != VRayFur do print i
Or to avoid similar problems in the future check that the object has the property you are trying to change:
for o in objects where isProperty o #wirecolor do
(
[I]o.wirecolor = red[/I]
)
getTriMeshFaceCount() will work on any object and returns a 2 element array with the first element being the (tri)face count and the second the vertex count.
so you can filter objects where (getTriMeshFaceCount obj)[1] == 0
Hi all
Thanks for all the help, all methods work perfectly and have given me some good ideas on how to make the script a little more robust.
Cheers again, much appreciated.
Will
Just a quick question
Im running this code when a button is pressed in a macroscript
for i in geometry do i.wirecolor = (color (((getUserProp i"VRay_Matte_Alpha") + 1))*(255/2))(((getUserProp i"VRay_Matte_Alpha") + 1)*(255/2))(((getUserProp i"VRay_Matte_Alpha") + 1)*(255/2)))
and getting the error
–No “”+”” function for undefined
However on its own this works fine.
Any ideas???
EDIT —-
Actually it doesnt work fine on its own, but sometimes it works, sometimes it doesnt ???
Are you trying to make each object’s wirecolor a shade of grey dependent on its alpha contribution?
Yeah, thats it really.
I think i have found the issue,
basically you have to selct an object and go vray properties before you can access the properties via maxscript. Bit meh really.
Do this if you have Vray
Quick test,
New scene, create teapots and run this code
for i in geometry do print (getUserProp i"VRay_Matte_Alpha")
you should have a list of undefined
now select all teapots, open vray properties dialogue, then run code again.
This should now return if matt alpha is ticked.
That’s right I remember finding that out myself. It might be worth asking on the Chaos forum whether there is a way of getting VRay to add the user properties automatically.
The ancient Chinese have a saying “Calculate once, assign to variable and use many times”.
for i in geometry do
(
rgbLevel = ((getUserProp i "VRay_Matte_Alpha") + 1)*127.5
i.wirecolor = color rgbLevel rgbLevel rgbLevel
)
lol, true!
I’m not really a scripter and haven’t used maxscript for ages so been creating some really “bad” code trying to get some buttons working.
Cheers still, will update
In regard the Vray issue I don’t think there is a way to batch set the vray object properties but someone suggested to include checking if the value is “undefined” and set that based on the fact that if it is not yet defined then you know the value will be default. Works, just means a bit more code on each button I am making.
That sounds like the best solution and it is neater and should be faster than a try/catch.
I saw your post on the Chaos forum and I don’t know how to close the VRay properties Dialog because it is modal and maxscript appears to pause while it is open so
UIAccessor.CloseDialog 2166444P
doesn’t work. Maybe someone else knows?
You can set the properties even when the user properties is empty, I’ve done this script once to use a button to turn the matte on and off for a couple of objects, the second one go back to the default values:
macroScript MatteOnVray
category:"VRay"
buttonText:"MatteOn"
toolTip: "Turn selection into matte"
(
on execute do (
for i in selection do (
setUserProp i "VRay_Matte_Enable" "True"
setUserProp i "VRay_Matte_Alpha" "-1,000000"
setUserProp i "VRay_Matte_Shadows" "True"
setUserProp i "VRay_Matte_ShadowAlpha" "True"
)
)
)
macroScript MatteOffVray
category:"VRay"
buttonText:"MatteOff"
toolTip: "Turn off matte in selection"
(
on execute do (
for i in selection do (
setUserProp i "VRay_Matte_Enable" "False"
setUserProp i "VRay_Matte_Alpha" "1,000000"
setUserProp i "VRay_Matte_Shadows" "False"
setUserProp i "VRay_Matte_ShadowAlpha" "False"
)
)
)
You can press the button in a new created object with the user properties empty and it will work fine.
I don’t see a big problem putting a test because you only need to test a single properties and if its undefined you assume that’s using the default values. The problem is, the user properties are stored as a string, not a value, so you can’t use this as a number.
Since we use basically matte with -1, 0 and 1 values, and undefined means the default 1, you can use this ugly script:
for i in geometry do (
if getUserProp i "VRay_Matte_Alpha" == undefined then (
i.wirecolor = white
)
if getUserProp i "VRay_Matte_Alpha" == "-1.000000" then (
i.wirecolor = black
)
if getUserProp i "VRay_Matte_Alpha" == "1.000000" then (
i.wirecolor = white
)
if getUserProp i "VRay_Matte_Alpha" == "0.000000" then (
i.wirecolor = gray
)
)
Not very beautifull, but at least it works.
Maybe there is a better way to work with the strings from the userprop like using the execute command, let’s see if we can get some help.
Ah, so instead of opening the properties window just set the properties to their defaults one by one. Another good idea.
for the setting wirecolor based off alpha I used an if else based on Raytracer05’s code he gave below, little bit tidier.
If anyone is interested I can post up the final script. Its not pretty but its so handy seeing all your object properties in the viewport.
Yes, as Dave posted you can assign all properties or just the ones you’re using as I did with the matte buttons.
The funny thing is that none of the codes doing math formulas with the returned user properties was working in my computer. As I find out, my computer uses commas instead of period and in this case it messes up with maxscript, at least you don’t have to worry about this. :banghead:
And I’d like to see the final script, I’m also just a maxscript beginner and we can always learn something from others code.