Activate Camera -A very simple question for a noob
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/08/2011 at 23:44, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Originally posted by xxxxxxxx
Read the Python Tutorial, this is the best place to start. At least until (including) chapter 9.
http://docs.python.org/tutorial/index.htmlTo whet your appetite, call the function.
def **main** () : ResetToEditorCamera(doc) main()
Please note that I have edited the code above, there was something wrong, sorry.
Err, sorry dude. I still have nothing...
import c4d
def main() :
'''
Resets the document camera to the standart editor camera.
'''
# Returns a BaseDraw instance that is hold in the active document
bd = doc.GetActiveBaseDraw()
# Get the standart editor camera from the BaseDraw
cam = bd.GetEditorCamera()
# Set the active camera to the cam we've obtained from the BaseDraw
bd.SetSceneCamera(cam)main()
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/08/2011 at 23:59, xxxxxxxx wrote:
Please put code into a code-block using [*Code][/*Code] (Without the * )
works, whats the problem ? After calling the Skript, you must update C4D by clicking into the Editor. Or call c4d.EventAdd().
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/08/2011 at 01:18, xxxxxxxx wrote:
simply use this code:
import c4d bd = doc.GetActiveBaseDraw() cam = bd.GetEditorCamera() bd.SetSceneCamera(cam)
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/08/2011 at 01:37, xxxxxxxx wrote:
Thanks guys. I'll try that when I get home. Appologies for being a colossal noob.
You've been most helpful.
Also, is there a way to set the active camera to one supplied by a variable, then save that scene file with a unique name Which is also a variable (eg. ProjectName_Cam#.c4d).? Where projectname, it's path and cam# are all variables provided with user data.
For example, if I had 7 cameras in a scene, I could iterate a loop that would first activate the camera 1, then save it off to the renderfarm. Then it would do the same with camera 2,3,4 etc...
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/08/2011 at 01:42, xxxxxxxx wrote:
its hard to describe the basics, but if that is the only thing you want to, take a look at the plugin. "renderelements"
else, you should take a look to the examples of the python api. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/08/2011 at 02:53, xxxxxxxx wrote:
I've got render elements. Great plugin. However from memory it cannot record camera states. I also wish to automate the entire process for many cameras with just 1 button push.
Allow me to explain exactly what I wish to do so you can point me further in the right direction and I won't waste anyones time.
Basically I have already constructed a stereo/autostereo rig using xpresso. I had rigged up a control to change scene cameras using the stage object which was input from link data from an integer user input. Long story short this failed when merging my camera setup to a new scene. I need a better solution to activate various cameras from user data. Enter python.
What I want it a small loader plug in with a simple ui that is capable of 2 main functions (2 buttons).
1. Merge the external camera rig c4d scene into the active document.
2. Batch export the scene 8 times, to 8 separate scenes with unique naming. The only difference in each scene is the active camera 1-8. The logic behind this is that I can put these files to the renderfarm.
This sounds like fairly simple stuff to me. Could I achieve all of this with Python?
Thanks folks
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/08/2011 at 05:14, xxxxxxxx wrote:
As you wish..
Place a file '01.c4d' onto your C:\ local drive and run the script with a new document opened..
Youll find 8 new files on you local drive. Make sure there is an object in 01.c4d.import c4d from c4d.documents import LoadDocument, SaveDocument, GetActiveDocument, InsertBaseDocument def Example() : doc = GetActiveDocument() preset = LoadDocument(r'C:\01.c4d', c4d.SCENEFILTER_OBJECTS) InsertBaseDocument(preset) cam_pr = preset.GetFirstObject().GetClone() doc.InsertObject(cam_pr) for i in xrange(8) : cam_pr.SetAbsPos(c4d.Vector(0, i * 50, 0)) # ... Change whatever you want SaveDocument(doc, r'C:\MySavedFile0' + str(i) + '.c4d', c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT) Example()
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/08/2011 at 18:49, xxxxxxxx wrote:
Thanks nux, Very helpful.
How about these 2 problems...?
1. I actually want to non destructively merge the base camera rig into my working scene rather than just loading it in separately into its own scene. I looked through the sdk, tried the
c4d.documents.MergeDocument
command but it didnt work.Also...
2. I have user data with an integer setting...0-7 which controls which camera is active using the stage object/xpresso. How might i be able to adapt your script to iterate this integer value user data, before saving the scene off. Ive tried some things but i cant access the user data properly!
Much appreciated you guys
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 02:01, xxxxxxxx wrote:
1. How about doing it the other wey round ? Instead of loading the Scene to the Preset, load the Preset to the scene. (That was actually my intention with the naming of the variables).
2. op[c4d.ID_USERDATA, id] # id: the id of the userdata entry
Cheers,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 08:02, xxxxxxxx wrote:
Here's how to Merge a .c4d file:
import c4d, os from c4d import documents def main() : doc = documents.GetActiveDocument() fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'MyFile.c4d') #The actual .c4d file merge = documents.MergeDocument(doc, path, 1) c4d.EventAdd() if __name__=='__main__': main()
Look up the other paths (C4D_PATH_DESKTOP, etc...) you can use in the docs.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 17:26, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Here's how to Merge a .c4d file:
import c4d, os from c4d import documents def main() : doc = documents.GetActiveDocument() fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'MyFile.c4d') #The actual .c4d file merge = documents.MergeDocument(doc, path, 1) c4d.EventAdd() if __name__=='__main__': main()
Look up the other paths (C4D_PATH_DESKTOP, etc...) you can use in the docs.
-ScottA
Thanks Scott, will try that asap. Ill let you know how i go.
One thing I am still struggling with is how to setup that for loop with the user data. Like where do i need to specify the ID. and where do i put 'i' for an integer list type user data setup.
Basically at the moment the user data integer list is set up so ...
0=perspec using nux's little python script tag. (Thanks mate!)
1=cam 1
2=cam 2
3=cam 3 etc...can you specify a for loop where i is between a range say 1-5 for example?
I know Python integration is fairly new to c4d, but I am amazing how little true code examples there are on the net. Who can understand reading an SDK. Half of it isnt even in context. Just raw comands. And it's so brutal when it comes to debugging that somelike me has no chance to find what is wrong with the code.
One thing i can say is how surprised I am of the support you guys have given me already. I know you think im lazy for asking for code, but I guess i learn faster with examples. And reverse engineering code rather than inventing it.
Thanks all.
-
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 20:50, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Here's how to Merge a .c4d file:
import c4d, os from c4d import documents def main() : doc = documents.GetActiveDocument() fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'MyFile.c4d') #The actual .c4d file merge = documents.MergeDocument(doc, path, 1) c4d.EventAdd() if __name__=='__main__': main()
Look up the other paths (C4D_PATH_DESKTOP, etc...) you can use in the docs.
-ScottA
That worked and makes sense thank you.
NUX; i'm going to attempt this for loop thing now from the documentation you posted. Will let you know when i fail....
Has anyone ever got Python to save the entire project including scene file and tex folder? 'Render Elements' does it, so i asked the creator how he did it and he said that there was no easy way. He had to gather all the information in the scene and collect files manually with his code. He basically rewrote the save project command in c4d. It was his understanding that saving a project could not be scriptable because it promts the user every time for a save path, meaning its useless for long loops etc. I would like my script to 'for loop' the scene x amount of times changing a user data entry each time, then save the entire project to it's own folder with it's name also being driven by a user data string variable.
Saving a project through Python seems to be the next hurdle for me now.
Thanks!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 21:03, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Note: Using xrange() is more efficient and should always be used when you do not require a list.
Edit: Made layout more nice.
Your image files are not allowed aparently. What layout are you refering to?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 21:06, xxxxxxxx wrote:
You cannot see the images ?
Ehm, layout ? Do you mean websites ?
Actually, theese are the links:Python Docs: http://docs.python.org/index.html
Xrange function: http://docs.python.org/library/functions.html?highlight=xrange#xrange
Range function: http://docs.python.org/tutorial/controlflow.html#the-range-function
for statement: http://docs.python.org/tutorial/controlflow.html#for-statementsEdit: Using the SaveDocument function works just fine and no dialog appears.
import c4d from c4d.documents import SaveDocument def main() : SaveDocument(doc, 'C:\\foo.c4d', 1, c4d.FORMAT_C4DEXPORT) if __name__=='__main__': main()
You just have to make sure that the file-path is absolute, not relative.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 21:29, xxxxxxxx wrote:
Originally posted by xxxxxxxx
You cannot see the images ?
Ehm, layout ? Do you mean websites ?
Actually, theese are the links:Python Docs: http://docs.python.org/index.html
Xrange function: http://docs.python.org/library/functions.html?highlight=xrange#xrange
Range function: http://docs.python.org/tutorial/controlflow.html#the-range-function
for statement: http://docs.python.org/tutorial/controlflow.html#for-statementsEdit: Using the SaveDocument function works just fine and no dialog appears.
import c4d from c4d.documents import SaveDocument def main() : SaveDocument(doc, 'C:\\foo.c4d', 1, c4d.FORMAT_C4DEXPORT) if __name__=='__main__': main()
You just have to make sure that the file-path is absolute, not relative.
Yeah mate I've got my head around that function now which is great.
However from the SDK there doesnt seem to be an option/flag to make it a 'SAVE PROJECT' function where the entire project folder is saved INCLUDING tex folder, GI files etc.
So I want to iterate the same function as when the user goes File/Save Project...
not sure if i made sense.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 21:58, xxxxxxxx wrote:
Is there something more than textures and GI files ?
Copying the GI files and textures is no problem. It does also seem like cinema 4d does recognize when textures are suddenly relative and no more absolute.Use this function to save as a project, It should work jsut fine.
import c4d from c4d.documents import SaveDocument from os.path import abspath, dirname, split, join, exists, basename, isabs from os import makedirs, mkdir from shutil import copytree, copy def SaveProject(doc, path) : pah = abspath(path) ndir_, name = split(path) ndir_ = join(ndir_, name[:name.rfind('.')]) if not exists(ndir_) : makedirs(ndir_) new_illum = join(ndir_, 'illum') new_tex = join(ndir_, 'tex') dir_ = doc.GetDocumentPath() if dir_: illum = join(dir_, 'illum') if exists(illum) : copytree(illum, new_illum) tex = join(dir_, 'tex') if exists(tex) : copytree(tex, new_tex) for i, texture in doc.GetAllTextures() : if not isabs(texture) : continue copy(texture, join(new_tex, basename(texture))) SaveDocument(doc, join(ndir_, name), 0, c4d.FORMAT_C4DEXPORT) return True # example: SaveProject(doc, 'C:\\foo.c4d')
Cheers,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 22:44, xxxxxxxx wrote:
Absolute genius Nux, and that was quick too! You saved me ages!
Im sure a lot of readers will find this particularly useful too!
Thanks mate.
PS. does the \\ in the filename denote multiplatform? Would this work on a mac for instance? Thanks again.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/08/2011 at 23:32, xxxxxxxx wrote:
Here is something interesting. For some reason this doesnt bring in my one material for the 3Dcam.c4d scene. It is definately there in the file. I've tried flags but it doesnt make a difference...mmm
import c4d, os from c4d import documents def main() : doc = documents.GetActiveDocument() fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'3Dcam.c4d') #The actual .c4d file merge = documents.MergeDocument(doc, path, 1 ) c4d.EventAdd() if __name__=='__main__': main()
EDIT: Wait, replacing the merge = documents.MergeDocument(doc, path, 1 ) to merge = documents.MergeDocument(doc, path, 3 )seemed to work.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 30/08/2011 at 06:26, xxxxxxxx wrote:
Originally posted by xxxxxxxx
PS. does the \\ in the filename denote multiplatform? Would this work on a mac for instance? Thanks again.
The backslash is a character indicating a special character in a string on almost any programmin language. Using \\ defines a simple \. Using \n defines a newline, a tab, etc..
Originally posted by xxxxxxxx
EDIT: Wait, replacing the merge = documents.MergeDocument(doc, path, 1 ) to merge = documents.MergeDocument(doc, path, 3 )seemed to work.
You should use IDs instead of numbers, but i couldn't find that numer to be a 'SCENEFILETER_XX' ID. Sounds weird. May you check the function with the IDs to see which one does work for you ? See the documentation for the IDs under MergeDocument. Thanks.
Np
Cheers,