Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

get/set useprop maxscript question
show user profile  jpedleham
HI, Im working with some revit BIM data in max 2017 and im trying to write some scripts to deal with some of that data that gets dumped into the User defined properties. I see there are get/set methods for userprops but i cant figure out how to create a new one? If i just try to set a new one it returns undefined

Any ideas (Garp) :D

read 344 times
10/12/2016 12:05:31 PM (last edit: 10/12/2016 12:05:31 PM)
show user profile  Garp
To set induvidual properties one by one, you use setUserProp().
For example
setUserProp $Box001 #prop1 "what?"
setUserProp $Box001 #prop2 42

automatically formats the output to
prop1 = "what?"
prop2 = 42

You can get the same result with setUserPropBuffer(), except that there is no automatic formatting and it overwrites whatever properties were already there.
setUserPropBuffer $Box001 "prop1 = \"what?\"\r\nprop2 = 42\r\n"
Note the escape character sequences to get the proper formatting(\" for double quotes inside a double-quotted string, \r\n for carriage return plus new line).

The whole thing is just a mean to pass raw text around, really.

read 340 times
10/12/2016 1:20:24 PM (last edit: 10/12/2016 1:25:12 PM)
show user profile  jpedleham
Youre awesome thanks garp :D
We use stingray a fair bit and stingray as far as i can tell grabs the properties in that window and can display them in engine so its quite useful in that aspect.

Does this work for creating new properties then?

Thanks for your help!
read 329 times
10/12/2016 1:42:29 PM (last edit: 10/12/2016 1:42:29 PM)
show user profile  Garp
It works to create any text. The key = value syntax is just a convention between the code that sets the property and the code that reads it.
You can do setUserPropBuffer $ "once upon a time" if you want.

read 328 times
10/12/2016 2:01:36 PM (last edit: 10/12/2016 2:01:36 PM)
show user profile  jpedleham
So im trying to build a reference code from some bim data with this script but its not working.

for obj in selection do
refcode = getuserprop #Type
ss = substring refcode 1 3 = ss + "-"
fd = getuserprop #fdcode
append fd

but it says no getuserprop function for "OBJ NAME HERE"
read 326 times
10/12/2016 2:35:49 PM (last edit: 10/12/2016 2:47:43 PM)
show user profile  Garp
Try getuserProp obj . . . instead of

read 313 times
10/12/2016 3:05:38 PM (last edit: 10/12/2016 3:05:38 PM)
show user profile  jpedleham
im getting no ""substring"" function for undefined :/
read 310 times
10/12/2016 3:17:26 PM (last edit: 10/12/2016 3:21:07 PM)
show user profile  jpedleham
It seems to be something about the property type.

for obj in selection do
refcode = getuserprop obj "Type" as string
ss = substring refcode 1 3 = ss + "-"
fd = getuserprop obj "fdcode" as string
append fd


This works up to the point where i set 'fd' at which point it does nothing but if i remove the 'as string' from fdcode it throws an error about unable to convert 1234 to string. Right now though it doesnt add the four digits i need to the end of the first 3 and the hyphen.


I got it working by removing the append as follows

for obj in selection do
refcode = getuserprop obj "Type" as string
ss = substring refcode 1 3
fd = getuserprop obj "fdcode" as string = ss + "-" + fd
read 306 times
10/12/2016 3:30:28 PM (last edit: 10/12/2016 3:33:31 PM)
show user profile  jpedleham
Another query with this function. My models have cost data in the properties field and i want to iterate through my scene and add up the cost of each item. Some of them however might not have the cost data associated with them so id need to check that and then if they have no cost, add a zero cost into the properties. I tried this code

select geometry
totalcosting = 0
for obj in $ do
local iconcost = getuserprop obj #cost
if iconcost == undefined do
setuserprop obj #cost 0.00
cost = getuserprop obj #cost

totalcosting = totalcosting + cost
messagebox (totalcosting as string)
totalcosting = 0

I get a 'maxscript error - could not display details' popup and i have no idea why...
read 285 times
10/13/2016 4:30:49 PM (last edit: 10/13/2016 4:55:44 PM)
show user profile  Garp
Not sure what goes wrong in your code but this should work:

read 272 times
10/13/2016 6:54:58 PM (last edit: 10/13/2016 6:54:58 PM)
show user profile  jpedleham
Odd isnt it. Thanks Garp! You should charge for this stuff haha
read 260 times
10/13/2016 11:18:57 PM (last edit: 10/13/2016 11:18:57 PM)
#Maxforums IRC
Open chat window