[Closed] User Defined Properties: Find/Replace Editor
Whats up guys, this is something I’ve been after for a long time, and while I’ve seen a few posted in random forums I’ve never seen a solution out there.
So we use the User Defined Properties feature to add alot of unique custom properties to our models that get loaded in our own game engine, everything from floor numbers to visibility.
The problem is with the User Defined dialog in Max, there’s really no way to drill-down into those properties, or do any intelligent editing; it’s pretty much select one at a time, copy/paste.
The other major issue (that I’ve seen referenced before) is that when you select multiple objects with differing property strings, that dialog just shows up blank, so it appears as if you have no properties at all…
So I’m looking for any type of script that would add some advanced, multi-object editing to these properties: find/replace, display in a seperate dialog, select based on properties, etc.
Anyone ever come across this type of script? How tough would it be to write a simple find/replace script to comb through the user defined properties of the selected objects?
Thanks guys, as always any assistance is much appreciated.
gallion311
It’s not very hard at all.
Here’s a small find/replace function to get you started in the right direction. Ask more specific questions and I’ll try to help.
fn findReplaceUserProps prop findStr replaceStr =
(
for o in selection where getUserProp o prop == findStr do setUserProp o prop replaceStr
)
findReplaceUserProps "someparameter" "oldvalue" "newvalue"
Thanks lo, I’m hoping that’ll get me started down the right path.
So I created a new script, pasted in that code and changed the strings to reflect my file.
As a quick example, my object has a property string of:
<Property>
<Identifier>VCE_Set</Identifier>
<String0>Set1</String0>
</Property>
So I edited the script to:
fn findReplaceUserProps prop findStr replaceStr =
(
for o in selection where getUserProp o prop == findStr do setUserProp o prop replaceStr
)
findReplaceUserProps "Set1" "Set1" "StairSet"
So that should change Set1 to StairSet right? (naturally this didn’t do anything)
Although I’m confused the “someparameter” piece, isn’t that the same as “oldvalue”?
it looks like a XML. So the better way is to handle it as XML. Something like:
(
doc = dotnetobject "System.Xml.XmlDocument"
str = dotnetobject "System.IO.StringReader" (getUserPropBuffer $)
doc.Load str
ss = doc.selectnodes "//Property/String0"
ss.item[0].InnerText = "StairSet"
stw = dotnetobject "System.IO.StringWriter"
doc.Save stw
setUserPropBuffer $ (stw.ToString())
)
it makes also some “XML” header but you can ignore it (or delete)…
At least I would do it this way.
I’m not sure what that (XML?) code you pasted is, but if identifier is the name of the property that’s what you should be passing as parameter.
In other words, if in the user properties window you see the line:
VCE_Set = Set1
you should call the function as
findReplaceUserProps "VCE_Set" "Set1" "StairSet"
If you don’t know which property you will be looking for, and want to catch all instances of the “Set1” value of any property, you should use another function by getting the entire user property block and manipulating it. Let me know and I’ll give you a different function to use for that.
(
doc = dotNetObject "system.xml.xmlDocument"
sr = dotnetobject "System.IO.StringReader" (getUserPropBuffer $)
doc.Load sr
ss = doc.SelectSingleNode "//Property/String0"
ss.InnerText = "StairSet"
settings = dotnetobject "System.Xml.XmlWriterSettings"
settings.OmitXmlDeclaration = on
settings.Indent = on
sw = dotnetobject "System.IO.StringWriter"
xw = (dotnetclass "System.Xml.XmlWriter").Create sw settings
doc.Save xw
setUserPropBuffer $ (sw.ToString())
)
that’s better.
I wasn’t even aware you can use XML as user properties. But then again, it’s just a free block of text, so why shouldn’t you be able to do that…
Interesting.
It’s not a right idea to put XML in user properties. It shouldn’t be used this way. But probably some developers think that User Properties is some kind of Free Text Editor that might be used for any correspondence.
As an aid, you can also use this tool I made
http://scripts.subd.nl/?f=JHN_userPropBuffer.ms
It’s a modeless userpropbuffer editor so work around the model object property dialog.
-Johan
Wow, that’s awesome thanks, I certainly appreciate the time.
The script works great denisT; I’d love to take it to the next level with a proper dialog and some textboxes, but I’d imagine that’s a considerable effort compared what you have now?
(I’m no programmer, pure artist here )
Thanks for that script JHU, that’s incredibly helpful to jump around the scene and check my properties. My wishlist items would naturally be focused around this thread: Find function (search for a given string of text and highlight/list the objects containing it), and then the classic Find/Replace.
Great stuff guys, thanks again.
I have been looking all over the place for this and have not been able to find it. I’m looking for a script that will clear all user-defined properties in multiple objects (more than a thousand objects). As you can imagine, it is unreasonable and too time-consuming to go to each individual object’s properties and delete them manually.
The problem started with Max 2012’s new MassFX. It uses PhysX which dumps a bunch of stuff into each object’s user-defined properties and causes all sorts of problems if you delete another object that it was bound by… just a mess.
Would really appreciate (and I’m sure many other’s would too) if someone could help with this.