[Closed] Adding a custom string property with value
Hi All, I am trying to do something that I thought would be really simple…
Basically I have a script that calls up a rollout with 2 edittext boxes – Name and Value, and an Apply button.
When the user hits apply, it adds two custom string attributes to the selected object called Name and Value, with the intention of pre-filling in the custom attributes with the contents of the two edittext boxes.
The issue is that I can’t seem to pre-fill out the custom string attributes at the time of creation. The script is correctly capturing the values of the original edittext boxes, but won’t put them into the string attributes.
Here is my code:
macroScript AddProperties
category:"VIZ RT"
(
global string nameString
global string valueString
rollout VIZRTAddProperties "VIZ RT - Add Properties"
(
edittext propertyName "Name" fieldwidth:260
edittext propertyValue "Value" fieldwidth:260
button propertyApply "Apply to Selected" width:120 height:30 pos:[45,60]
on propertyApply pressed do (
nameString = propertyName.text
valueString = propertyValue.text
customAttributes=attributes addFileLinks
(
parameters params rollout:ro_addFileLinks
(
pName type:#string ui:stringName
pValue type:#string ui:stringValue
)
rollout ro_addFileLinks "Custom Attributes" width:162 height:77
(
edittext stringName "Name:" text:nameString fieldwidth:110
edittext stringValue "Value:" text:valueString fieldwidth:110
)
)--end attributes
custAttributes.add $ customAttributes
)
button propertyDelete "Delete All Properties" width:120 height:30 pos:[180,60]
on propertyDelete pressed do (
)
)
createDialog VIZRTAddProperties
VIZRTAddProperties.width=325
)
Any idea why this might be the case? I’m fairly new to maxscript so my apologies if I have missed anything obvious.
Hi MickyG.
I’m not an expert at all. I just play with MaxScript and get things work.
So, take my comments as a feeling of mine and not as know-how.
- Defining custom attribs inside a rollout isn’t a good idea, as you redefine them everytime you press the apply button.
- I don’t know why you want those two varables to be ‘global’
- You are not asigning values to your attributes, that are pName and pValue, but to the text property of and editbox in a rollout that doesn’t open in your code.
- If you add attribs to an object that already has these attribs, the object will have this attribs twice (or more) and you won’t be able to use them well.
This next code works, but I’m sure it can be a lot better.
The_addFileLinks_Attribs = attributes addFileLinks
(
parameters params rollout:ro_addFileLinks
(
pName type:#string ui:stringName default:""
pValue type:#string ui:stringValue default:""
)
rollout ro_addFileLinks "Custom Attributes" width:162 height:77
(
edittext stringName "Name:" text:pName fieldwidth:110
edittext stringValue "Value:" text:pValue fieldwidth:110
)
) -- end attributes
rollout VIZRTAddProperties "VIZ RT - Add Properties"
(
edittext propertyName "Name" fieldwidth:260
edittext propertyValue "Value" fieldwidth:260
button propertyApply "Apply to Selected" width:120 height:30 pos:[45,60]
on propertyApply pressed do
(
nameString = propertyName.text
valueString = propertyValue.text
for The_Object in $ do
(
-- Check if the object allready has 'addFileLinks' attributes. If yes, delete them
ct = custAttributes.getDefs The_Object
if ct != undefined do
(
for i in ct do
(
if i==The_addFileLinks_Attribs do
(
custAttributes.delete The_Object The_addFileLinks_Attribs
)
)
)
custAttributes.add The_Object The_addFileLinks_Attribs
The_Object.addFileLinks.pName = nameString
The_Object.addFileLinks.pValue = valueString
) -- end for The_Object in $ do
) -- end on propertyApply
button propertyDelete "Delete All Properties" width:120 height:30 pos:[180,60]
on propertyDelete pressed do
(
)
) -- end rollout
createDialog VIZRTAddProperties
VIZRTAddProperties.width=325