RENAME - modifier.classes.name to object.name [SOLVED]

Self explanatory really. Arrays sort of scare me but I'll get them down eventually but I'm sure this is a case where I can collect the Modifiers.name and then send that to the object name resulting in a final result for the objects name to be "Ball_Mod_Noise" "'Ball_Mod_UVW Map" etc.

My efforts so far collect modifiers array:

ModCollect = with printAllElements on sort (for c in modifier.classes collect if c.creatable then (c()).name else c.localizedname) as string

-------------------------------
This code though below works to rename the objects but not good when there are so many modifiers, need something more dynamic. If I could replace uvwmap here with something for the o.name then that would be great.

NewMaxFileName = "MAX"
modPrefix = "_Mod"
for o in objects where classof o.modifiers[1] == uvwmap do o.name = NewMaxFileName + modPrefix + "_UVWMap" as string

= MAX_Mod_UVWMap

Thanks in advance.

-----------------------SOLUTION---------------------------

for o in objects do (
	for m in o.modifiers do (
		if classof m != undefined do (
			o.name = o.modifiers[1].name
		)
	)
)

Probably could be shortened but I'm hapy for now :D

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fajar's picture

Collect object that have modifier and its modifier

fn hasModifier node =
(
	if node.modifiers.count !=0 then return true else return false
)
 
fn thisNodeModifier node =
(
	modName=#()
	modIndex=#()
 
	idx=node.modifiers.count
	while idx > 0 do
	(
		--idMod +=1
		thisMod=node.modifiers[idx]
		append modIndex idx
		append modName thisMod
		idx -=1
	)
	modIndexName= #(node,modName,modIndex)
)
 
fn collectAllMod modStored:5 arr: =
(
	allMods=#()
	if arr == unsupplied do arr=(collectOriginalObject arr:selection)
	local idx = arr.count
	local stops=true 
	local cnt=0
 
	while idx > 0 do
		(
			if (hasModifier arr[idx] == true) and (canConvertTo arr[idx] editable_mesh) do
			(
				appendIfUnique allMods (thisNodeModifier arr[idx])
				cnt +=1
			)
			idx -=1
			if cnt == modStored do idx = 0
		)
	allMods	
)
 
collectAllMod modStored:5 arr:selection 

--arr: array source
--modStored : total amount of object that have modifier that will stored --in array + its modifier

3dwannab's picture

Thanks, I'm sure I'll come back

Thanks, I'm sure I'll come back to this code for future reference. Thanks but I managed to work out a solution.

See scrrenshot of example. It get the first modifier in the stack and appends to the filename. And also names ON or OFF depending on if the modifiers enabled.

NewMaxFileName = getFilenameFile (maxFilename)
separator = "_"
modPrefix = "Mod"
enabled = "_ON"
disabled = "_OFF"
 
		for o in objects do	(
			for m in o.modifiers do (
				if classof m != undefined do (
					if o.modifiers[1].enabled then (
						o.name = NewMaxFileName + seperater + modPrefix + seperater + o.modifiers[1].name + enabled
					)
					if not o.modifiers[1].enabled then (
						o.name = NewMaxFileName + seperater + modPrefix + seperater + o.modifiers[1].name + disabled
					)
				)
			)
		)
AttachmentSize
Screenshot 53.96 KB
3dwannab's picture

Can...

someone tell me why this collected everything in the scene. I wanted to collect just objects with modifiers:

ColMod = for obj in objects where classOf obj.modifiers[1] != undefined collect obj

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.