View Full Version : SetEditorCamera?
deepshade 09-25-2010, 11:12 AM Taking my very first steps in Python.
One thing I've always wanted to do was to have a way to quickly set the editor camera to a position of one of the scene cameras. Without manually copying the coords
Can't seem to find a way to set the editor camera position?
|
|
donelgreeko
09-25-2010, 12:24 PM
Hi deepshade,
how do you get both camera objects (source and target)? By name, by selection, ...?
To get the camera position, you can use CameraObject.GetRelPos and to set CameraObject.SetRelPos. So in example:
cam_target.SetRelPos(cam_source.SetRelPos())
Cheers, donelgreeko
deepshade
09-25-2010, 01:06 PM
thanks for the feedback.
This is the very first time I've looked at creating anything in Python. Very little experience in COFFEE or the SDKs. Working out how to get off the ground is always the toughest step in any new language.
The plan was to:
Go to the editor camera
Select scene camera in OM
Run script
If scene camera selected
Editor cam has now all the properties of the scene cam
else report error and exit
you can then 'tinker' with the editor cam to experiment with different views angles etc without having to create a new cam or interfere with that particular scene cam
Next stage would be to have a script which runs the reverse process
editor to selected
As I said - very first steps
Working out was needs to be included in the script?
What needs to be defined, called
Then getting used to the syntax
Have written in C many moons ago
PHP a fair bit
I'm sure the fog will eventually clear
Cookbook could do with some more examples of the basic stuff
appreciate the help so far
tcastudios
09-26-2010, 02:52 AM
Also trying to get into Python I took a Coffee script I had that
does a part of what you ask.(Move something to EditorView)
You should be able to do the reverse from this. (Editor to Camera Object).
For simple things as this, coffee is a bit more compact.
What I found was that the Editor Camera and SceneCamera
(Active Camera Object from OM) are truly separated in Python.
The basedraw camera in Coffee is the "same" (the view) so a
object will move into -view- and not in all cases to the Editor Camera.
(That could be elsewhere but the view)
In Python, as I understand it, you need to define what camera
you want to use.
The two scripts below, first Coffee then Python.
Copy all into the corresponding ScriptManagers.
(Copy and Paste can sometimes fail from here
so check if something errors)
The first part of the Python is how to describe the script
as shown at Cineversity.
Cheers
Lennart
COFFEE:
// PlaceAtCamera tcastudios.com 2008/2010 R12
//
// Place selected object at active view
// and transfer camera settings if selected is a camera
if(!object()) return;
var op = object();
var cam = doc->GetRenderBaseDraw()#BASEDRAW_DATA_CAMERA;// Active View/Camera
doc->StartUndo(); // Start the Undo recording
doc->AddUndo(UNDO_OBJECT_REC, op); // Add to Undo
op->SetMg(cam->GetMg());
if(op->IsInstanceOf(Ocamera))
{
doc->AddUndo(UNDOTYPE_CHANGE_SMALL, op); // Add to Undo
op->SetContainer(cam->GetContainer());
}
doc->EndUndo(); // End the Undo recording
Python R12:
"""
PlaceAtCamera
Copyright: tcastudios.com
Written for CINEMA R12.021
Name-US: PlaceAtCamera
Description-US: Place selected object at active view
"""
# Place selected object at active view
# and transfer camera settings if selected is a camera
import c4d
def main():
doc.StartUndo() # Start the Undo buffer
aobj = doc.GetActiveObject() # Selected Object to Move
if aobj is None: # Nothing Selected
return False
edcam = c4d.BaseObject(c4d.Ocamera) # define a camera object
adraw = doc.GetActiveBaseDraw() # Active View
if adraw.GetSceneCamera(doc) is not None: # If Scene Camera
edcam = adraw.GetSceneCamera(doc) # Use Scene Camera
else: # Else
edcam = adraw.GetEditorCamera() # Use Editor Camera
doc.AddUndo(c4d.UNDOTYPE_CHANGE,aobj) # Add to Undo
aobj.SetMg(edcam.GetMg()) # Move Object to Active Cam
if aobj.GetType() == c4d.Ocamera: # If Object is a Camera
doc.AddUndo(c4d.UNDOTYPE_CHANGE_SMALL,aobj)# Add to Undo
aobj.SetData(edcam.GetData()) # Copy the BaseContainer To it
aobj.Message(c4d.MSG_UPDATE) # Update it
c4d.EventAdd() # Make it happen
doc.EndUndo() # End the Undo buffer
if __name__=='__main__':
main()
deepshade
09-26-2010, 09:02 AM
Brilliant Lennart
Much appreciated. Getting a few example lines of relevant code is so helpful - getting them commented as well - just great!
cheers
CGTalk Moderation
09-26-2010, 09:02 AM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.