Custom Attributes code errors

Custom Attributes code errors

donied
Collaborator Collaborator
1,267 Views
9 Replies
Message 1 of 10

Custom Attributes code errors

donied
Collaborator
Collaborator
This is probably a very basic question and I am doing something basic wrong. Sorry if its a stupid question.

I am trying to add a custom attribute to a sphere. I am using code from the MaxScript help. If I create a sphere and call it sphere01 then put the following code in the MaxScript listener from the Help it doesn't work

weaponDataCA = attributes weaponData
(
parameters main rollout:params
(
hitPoints type:#float ui:hits default:10
cost type:#float ui:cost default:100
sound type:#string
)
rollout params "Weapon Parameters"
(
spinner hits "Hit Points" type:#float
spinner cost "Cost" type:#float
dropdownlist sound_dd "Sound" items:#("boom", "sparkle", "zap", "fizzle")
)
)

I get the following error "-- Syntax error: at ), expected <factor>
-- In line: )"

If I put in the same code but put the following line at the end

custAttributes.add $sphere01 weaponDataCA

I get the following error
-- Type error: custAttributes.add requires MSCustAttribDef, got: undefined

I have been searching the help and the web to try and find an answer to this problem.

3ds Max design 2011
0 Likes
1,268 Views
9 Replies
Replies (9)
Message 2 of 10

Steve_Curley
Mentor
Mentor
Firstly, better to put your Max version in your sig rather than having to remember to type it in every time, and always wrap your code inside CODE tags - the forum can make a real mess of code if you don't (it doesn't always, but better to err on the side of caution).

1) No idea why that isn't working for you. I just copy/pasted your code (from a "quote", not from the post) and it executes correctly - no errors.

2) Try Sphere001 - the extra digit is automatic in 2011, previous versions only used 2 digits. Your code line works if you do, though (of course) you must have already successfully executed the prior code or there will be no definition stored for it to use.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 10

donied
Collaborator
Collaborator
Thanks for your feedback Steve.

I could understand it not working if it was my own code. But as it's copied and pasted from the help that has me confused.
0 Likes
Message 4 of 10

Steve_Curley
Mentor
Mentor
Absolutely definitely works here, no errors and you can see the Custom Attibutes in the Modify Panel.

Make certain that everything you see in the image is in your Script Editor - a missing or extra parenthesis somewhere could cause the problem.

And looking at the errors again, the 2nd one is because the Attribute Definition didn't work, rather than the Sphere name being wrong (though that would cause an error too).

Attached the actual .ms you see in the image - try that and see if it works.

cusatt.ms.zip


Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 10

donied
Collaborator
Collaborator
Thanks Steve again for your help. This looks like another pint I owe you.

When I put your code directly into the listener it gives me the errors. But if I run it as a Max script file it works fine. So it's just the way I was doing it.

I just want to say I really appreciate the time you and other people put into this forum. When you work on your own like I do it is great to know you have the back up of people like yourself and the many others who help.
0 Likes
Message 6 of 10

Steve_Curley
Mentor
Mentor
You're welcome, and thanks 🙂

I still don't know why it won't run correctly on your system in the Editor - That's exaclty how I ran it and as you can see it worked fine. Btw - you do mean the actual Script Editor not the Maxscript Listener? Things don't always work quite as expected in the Listener.

Start by commenting out the sphere line and see if it runs. If not, comment out the UI stuff and so on until it does run, then start adding things back until it fails. Perhaps limit it to a single, simple attibute then add the others in. There has to be a reason, it's just a matter of finding it.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 10

donied
Collaborator
Collaborator
The problem was I was putting it directly into the listener. When I put it in the script editor it works fine.
0 Likes
Message 8 of 10

Steve_Curley
Mentor
Mentor
Aha! User error then 😛

Glad you sorted it 🙂

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 9 of 10

donied
Collaborator
Collaborator
Ye. It was pure user error.

But thanks to you I got it sorted and I learned something new.
0 Likes
Message 10 of 10

Steve_Curley
Mentor
Mentor
Another happy customer 😄

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes