Notifications
Clear all

[Closed] Storing a newly create boxes name in a variable

Hi, I have a script that makes boxes that used unique name to name them all ie box_01, box_02 etc

  1. I’d like to store the latest selected newly created boxes name in a variable
  2. I’d then like to copy the box
  3. Then select the new box and rename it
  4. Then add a projection modifier to the new box
  5. Then recall the variable of the original box and pass it to the projection modifier

I’m sure I have a handle on doing it with fixed names but If I want to created many
boxes and add separate projection modifiers…
The variable only needs to store each name only the one time as I add the projection modifier

So make box, copy box, rename box, add projection mod, recall name(variable) of first box

I hope this makes sense and someone can help

Thanks

2 Replies

The variable would not store the NAME of the object, but its handle. In other words, it will point at the actual scene object you created or copied, not contain a string with whatever you named it.

For example,


 theBox = box name:(uniquename "MyBox_") --create box, name it, store in a variable
 theCopy = copy theBox --create a copy of the first box, store in a variable
 theCopy.name = uniquename (theBox.name + "_Copy_") --rename the copy
 theProj = ProjectionMod() --create a projection modifier
 addModifier theCopy theProj --add to the copy of the box
 theProj.addObjectNode theBox --set the reference geometry to the original box

Listener shows this:

$Box:MyBox_01 @ [0.000000,0.000000,0.000000]
$Box:MyBox_02 @ [0.000000,0.000000,0.000000]
"MyBox_01_Copy_01"
Projection:Projection
OK
true

Hope this will point you in the right direction.

Wow thanks Bobo, I’m learning a lot from your fundamentals dvd but my brain got stuck to the point where even my description of the problem wasn’t entirely accurate, but I finally worked it out thanks to you. I’ve posted the resultant code.

on lpRock pressed do --make low poly, clone it, unwrap and add projection modifier
			try(
					max modify mode
					theBox = myBox -- named box already existed
					theCopy = copy theBox --create a copy of the first box, store in a variable
					theCopy.name = uniquename (theBox.name + "_lp_") --rename the copy
					theCopy.modifiers[#TurboSmooth].iterations = 0
					convertToPoly theCopy
					select theCopy
					theUnw = Unwrap_UVW () 
					addModifier theCopy theUnw
					modPanel.setCurrentObject theCopy.modifiers[#Unwrap_UVW]
					SubObjectlevel = 1 
					theCopy.modifiers[#unwrap_uvw].unwrap2.setIgnoreBackFaceCull off
					theCopy.modifiers[#unwrap_uvw].unwrap6.selectVerticesByNode #{1..216} $
					theCopy.modifiers[#unwrap_uvw].unwrap2.fitRelax 50 0.1
					theCopy.modifiers[#unwrap_uvw].unwrap2.packNoParams()
					theCopy.modifiers[#unwrap_uvw].unwrap6.selectVerticesByNode #{1..216} $
					theCopy.modifiers[#unwrap_UVW].unwrap2.scaleSelectedCenter 0.98 0
					theProj = ProjectionMod() --create a projection modifier
					addModifier theCopy theProj
					theProj.addObjectNode theBox
					theProj.pushValue = 10
					theProj.autowrapCage()
					theProj.addRegisteredProjectionType 1
					theProj.projectProjectionType 1
				)catch()