[Closed] getting and setting camera
I have to get current camera name on scene, save scene, reset scene, merge objects from this scene and set in active view on this same camera.
I already menaged all except setting camera.
How can I get active camera name reset scene, merge this camera and set it again as active??
I already did with:
viewportsettingso=viewport.getLayout()
activecamera=getActiveCamera()
save scene x
merge camera from file x
viewport.setLayout viewportsettingso
viewport.activeViewport
viewport.setCamera activecamera
but it won`t work, can anybody help with this one?
When you merg the camera from another file use
mergeMAXFile <filename_string> [] #select
This way the camera, that you want to set as active will be selected after merging, so you can use:
viewport.setCamera selection[1]
But, if the merged camera is target camera, you haveo th check not to set as active camera the target of the merged camera.
Sory, maybe I wasn’t clear enough. I gonna describe it more precise.
I have to get settings of active camera in viewport, reset scene, merge all object back from this scene to empty one and set indentical settings for viewport including camera view. This is not for one specyfic scene so it’s hard to say what is actve camera view name of camera for me. Also I assume that camera will not be selected. It may be multiple cameras on scene. For me is importent to get the name of active camera in viewport, reset scene, merge all objects and set in one of viewport like on inicial scene and have this same view with active camera view from previous scene – not selected
Why you want to load the merge the scene in new scene?
1 – use getactivecamera() to get the active camera.
activeCam = getactivecamera()
(if you wants the camera’s name -> activeCamName = activeCam.name)
2 – select the active camera
3 – invert selection with
max select invert
4 – delete selected objects
delete selection
5 – merge the scene. You will have the active camera with proper settings. The viewports will be with proper settings.
I managed what I was tried however some of your commands don’t work like:
activeCamName = activeCam.name – it gives me error in listner always
but instead I used activeCamName=getactivecamera() – and it’s fine
So I combined some of your ideas with some of mine and it work.
I have active viewport, I know active camera name. After reset I merge all
elements to empty scene and set viewport and set active viewport window.
The only problem I have right now is how to say – max set this view I’m currently in as activeCamName – camera view
It would be great if you could give me a command for that – like: activeViewport=activeCamName (but it’s not correct ofcourse)
Operation I’m dooing may look strange but I try to reset scene and merge all object on clean scene including viewport and camera view.
Max gives me hard time.
I manage to get what I meant to do: set current view to specified camera
viewport.setCamera activeCam
but this time it turn to max don’t store activeCam = getactivecamera() after reseting scene
so I have no more access to activeCam variable. I tried to set activeCam as string but then I can’t
select activeCam or set viewport.setCamera activeCam because it’s a string. Is there any way to “unfreeze” this activeCam = getactivecamera() string beack as value or get eround problem of loosing variable after max reset.(I already tried as global but won’t work to)
Try this code on scene with same camera:
sceneName = maxFilePath + maxFileName
activeCam=activeCam.name
actionMan.executeAction 0 “40005” – File: Reset File
mergeMAXFile sceneName #noRedraw #AutoRenameDups #useMergedMtlDups #alwaysReparent
select activeCam —- <—– THIS WON’T WORK AFTER MAX RESET
It seems that max reset getactivecamera() value after resetting scene and I have to freeze it before reset and unfreeze after reset some how.
I also tried activeCam as float but I get error
MAXScript Rollout Handler Exception:
– Unable to convert: $Target_Camera:Camera001 @ [167.057480,113.824379,103.092728] to type: Float <<
The problem is not in 3ds Max. The problem is hou you uses the maxscript. Do you remember the thread where you asked about getting objects name and what I and PolyTools gives you as answers.
sceneName = maxFilePath + maxFileName
activeCam=activeCam.name
actionMan.executeAction 0 "40005" -- File: Reset File
mergeMAXFile sceneName #noRedraw #AutoRenameDups #useMergedMtlDups #alwaysReparent
select activeCam ---- <----- THIS WON'T WORK AFTER MAX RESET
The code not works because after the reset and merge the activeCam is a string, not an object.
Use this:
activeCamera = (getNodeByName activeCam)
select activeCamera
and activeCamera will hold the camera that you want.
It may be it’s my bad programming issue but I pasted your code to check it on scene with some active camera and I’m not making it up:
Here is your code:
activeCamera = (getNodeByName activeCam)
select activeCamera
Here is what lister said:
– Error occurred in anonymous codeblock; filename: E:\WORK\doctor\visual; position: 41; line: 1
– Frame:
– Unable to convert: undefined to type: String
– Error occurred in anonymous codeblock; filename: E:\WORK\doctor\visual; position: 61; line: 2
– No ““select”” function for undefined
I’m running out of hope with this one.
The whole code must look like this:
(
sceneName = maxFilePath + maxFileName
activeCam = activeCam.name
actionMan.executeAction 0 "40005" -- File: Reset File
mergeMAXFile sceneName #noRedraw #AutoRenameDups #useMergedMtlDups #alwaysReparent
activeCamera = (getNodeByName activeCam)
select activeCamera
)