[Closed] How can i rename the camera with the file time range
Hi all
Im trying to rename the camera with one button click but i cant . i think my knowledge of maxscript is very poor , im a simple interpreter of the code :(.
I try this …
on btn_head pressed do
(
frs=animationrange.start.frame as integer
fre=animationrange.end.frame as integer
select $*Camera*
renameIt "camera_shot_"+frs"-" + fre
)
What im doing bad ?
Thank you in advance
Alex.
Since you want to add the animationrange start and end frames to an object’s name (a string), you should convert them to strings and not to integers.
Also, I’m not sure of whether you actually created a RenameIt() function or not. If not, you should be aware that you can rename an object using its name property, like so :
$MyCam.name = "MyNewCameraName"
Finally, seems to me you try to rename all selected cameras, and there’s a better way to do that, since your command will also rename cameras targets or any object with “camera” in its name. You should rather check the superclass of the object :
for c in selection where ( superclassof c == camera ) do ( ... )
Oh , yes , the funtion !!
fn renameIt objName = (
global objName
for i in selection do i.name = objName
)
But i dont understand very well what you mean. I put ($MyCam.name = “MyNewCameraName”) in the maxscript listener and i recieve (– Unknown property: “name” in undefined) I donto know how can use this expresion, could you put an example?
The idea is change only one camera , in the shot will be only one camera , but i think will have any name.
Then integer no , string yes ?
so frs=animationrange.start.frame as string ?
Thank you for your comments man , sorry , my english broken
Alex .
There it is !
Simple thing, you don’t need to declare objName. It is already a argument of the function renameIt(), it already exists there. Also, declaring a global variable should be avoided as much as possible
Also, the line $MyCam.name = “MyNewCameraName” uses the dollar sign ($) which is related to selection or name. For example, $MyCam is the object named “MyCam”, $Box001 is the object named “Box001”, etc…
The listener says (– Unknown property: “name” in undefined) because you have no object named “MyCam” in your scene, so the command $MyCam returns undefined, which is the default empty value in Maxscript. And this value doesn’t have a name…
so frs=animationrange.start.frame as string ?
Exactly.
You can’t concatenate strings (“mystring”) and numbers like integers or floats (“3”, “51.12”)…
If you want to make a name, a string with those, you must convert (“cast”) them to strings.
You can even convert them twice, first time as integers, then as strings, so you will get “0” instead of “0.0”.
No problem with your english, mi español no es mucho mejor
Ok , then here is the result:
on btn_head pressed do
(
frs=animationrange.start.frame as string
fre=animationrange.end.frame as string
$Camera001.name = "Camera_shot_" +frs +fre
)
And wake up an error:
>> MAXScript Rollout Handler Exception:
– Unknown property: “name” in undefined <<
Were is the error , in $Camera001.name ?
thanks man for your coments
Alex
The error is that MAXScript doesn’t find an object named “Camera001”. You can either use $, if only the cameras is selected, or $CameraName where cameraname is, well, your camera’s name.
But you should rather use the snippet I gave you before, which is much safer :
for c in selection where ( superclassof c == camera ) do ( c.name = "....." )
This will loop through selected objects and change the name of the cameras only.
Enjoy this little toy:
try(destroydialog camera_range_rollout) catch()
rollout camera_range_rollout "Camera Range Name" width:200
(
local basename = "Camera"
local pattern = "%_(%:%)"
edittext basename_ed "Base Camera Name:" text:basename width:191 pos:[4,2] labelOnTop:on
button rename_bt "Rename" width:191 pos:[4,42] tooltip:"Rename selection to the Animation Range"
on basename_ed entered text do if text.count > 0 do basename = text
on rename_bt pressed do undo "Rename" on
(
nodes = for node in selection where iskindof node camera collect node
if nodes.count > 0 do
(
name = stringstream ""
format pattern basename (animationrange.start.frame as integer) (animationrange.end.frame as integer) to:name
nodes.name = name as string
)
)
)
createdialog camera_range_rollout
i hope it answers this thread main question
edit small bug was fixed
Ey !! thanks for yours comments man ! works perfectly.
I did some adjusts in the code, i would like do one click and select camera auto, and rename auto.
try(destroydialog camera_range_rollout) catch()
rollout camera_range_rollout “Camera Range Name” width:200
(
local basename = “Camera_shot”
local pattern = “%_(%-%)”
–edittext basename_ed “Base Camera Name:” text:basename width:191 pos:[4,2] labelOnTop:on
button rename_bt “Rename” width:191 pos:[4,42] tooltip:“Rename selection to the Animation Range”
--on basename_ed entered text do if text.count > 0 do textbase = text
on rename_bt pressed do undo "Rename" on
(
select $camera_shot_
nodes = for node in selection where iskindof node camera collect node
if nodes.count > 0 do
(
name = stringstream ""
format pattern basename (animationrange.start.frame as integer) (animationrange.end.frame as integer) to:name
nodes.name = name as string
)
)
)
createdialog camera_range_rollout
Thanks again !
Alex.