getting and setting camera

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  11 November 2013
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:

save scene x
merge camera from file x
viewport.setLayout viewportsettingso
viewport.setCamera activecamera

but it won`t work, can anybody help with this one?
  11 November 2013
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.
  11 November 2013
active camera view - get and set

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
  11 November 2013
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 =
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.
  11 November 2013
70% OF SUCCES activeViewport=activeCamName WOULD BE 100%

I managed what I was tried however some of your commands don't work like:
activeCamName = -- 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.
  11 November 2013
max can't store variables after reset

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
actionMan.executeAction 0 "40005" -- File: Reset File
mergeMAXFile sceneName #noRedraw #AutoRenameDups #useMergedMtlDups #alwaysReparent

select activeCam ---- <----- THIS WON'T WORK AFTER MAX RESET
  11 November 2013
don't work

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 <<
  11 November 2013
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
 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.
  11 November 2013

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.
  11 November 2013
The whole code must look like this:

	sceneName = maxFilePath + maxFileName
	activeCam =
	actionMan.executeAction 0 "40005" -- File: Reset File
	mergeMAXFile sceneName #noRedraw #AutoRenameDups #useMergedMtlDups #alwaysReparent

	activeCamera = (getNodeByName activeCam)
	select activeCamera 
  11 November 2013

so I took code you submit above, pray a little however their was not much hope in me after so many tryouts and pres ctr+e
this is what I received:
-- Error occurred in anonymous codeblock; filename: E:\WORK\doctor\temporary\; position: 71; line: 3
-- Frame:
-- sceneName: "C:\Users\piotr\Documents\3dsMax\scenes\2.max"
-- activeCam: undefined
-- activeCamera: undefined
-- Unknown property: "name" in undefined

So I closed all aplications, restart computer, load some scene with active cameras, insure I have active camera view, Evaluate and.. again Error

What's going on with this ?
Maxscript hightlight error line in editor: activeCam =
  11 November 2013
	sceneName = maxFilePath + maxFileName
	activeCam = getActiveCamera()
	if activeCam != undefined then
		activeCamName =
		resetMaxFile #noPrompt
		mergeMAXFile sceneName #noRedraw #AutoRenameDups #useMergedMtlDups #alwaysReparent

		activeCamera = (getNodeByName activeCamName)
		select activeCamera 
		viewport.setCamera activeCamera
		messagebox "No active camera found" title:""
  11 November 2013

Thank You for your patience and lenience , it works, but only in your configuration so I have to figure out how to adjust my code to this one but finally it works.
There is only one tiny detail I can't figure this out: How to force max to remember active view(in case there is no camera view at all) and then after reset scene select this same active view. For example when I operate on top view and then after reset I want max to jump(select)
this same view(in this case top but it can be others)

Do You know this?
If no, thank You anyway,your code was very helpfull.
  11 November 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:31 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.