Script to add something from Content Browser?

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
Script to add something from Content Browser?

Is it possible to add objects to the scene from the content browser using a Python/Coffee script?

Or better yet, add an Object Preset or Tag Preset?

Last edited by FantaBurky : 01 January 2013 at 06:11 PM.
 
Old 01 January 2013   #2
What's wrong ith the save object preset and save tag preset commands?
__________________
- www.bonkers.de -
The views expressed on this post are my personal opinions and do not represent the views of my employer.
 
Old 01 January 2013   #3
It would be nice to not have to go through four menues just to add an object/tag. If it was possible to add it through python/coffee, one could just put it in the main interface and even assign a shortcut command which would speed it up even more. Also it opens up more time saving possibilities like automatically moving it to a certain place in 3d space.

Not to say there's anything wrong with the way it currently works. Saving presets is actually one of my favorite features in Cinema 4D.

I found these commands in script log, but it doesn't really help much since it doesn't say which preset it adds:

CallCommand(300000111); // Load Object Preset
CallCommand(300000113); // Load Tag Preset
CallCommand(300000109); // Load Material Preset
 
Old 01 January 2013   #4
Sorry, i was a bit tired here and got your question completely backwards
__________________
- www.bonkers.de -
The views expressed on this post are my personal opinions and do not represent the views of my employer.
 
Old 01 January 2013   #5
You could use MergeDocument(), loading the complete preset
or LoadDocument(), getting a virtual document from the preset
and search and insert a specific object, material or tag.

See the Py SDK for details.

The filename for the CB looks like:
'preset://prime.lib4d/light setups/3 point light stage.c4d'

Note, it's a string not seen by the OS and uppercase is ignored.

Cheers
Lennart
__________________
MSA | OSX | xfiles ...Cinema4D Tools
 
Old 01 January 2013   #6
lennart pointed you already into the correct direction, but please note that / is an
string escape sign in python, so you will have to double type it for every occurrence.

c4d.storage.GeGetC4DPath() -> c4d folder
c4d.storage.GeGetStartupApplication() -> pref folder
 
Old 01 January 2013   #7
Thanks!! That's really helpful =)
 
Old 01 January 2013   #8
I'm afraid "no normal rules" apply when it comes to the Content Browser..
It's a closed file system that Python/COFFEE can't get to via the storage module.
The file base name is actually 'preset:// etc' and using / in the string
works just fine as it is "seen" only by Cinema itself.

I -wish- thou that we could browse the CB for for many reasons.

Cheers
Lennart
__________________
MSA | OSX | xfiles ...Cinema4D Tools
 
Old 01 January 2013   #9
"c4d.documents.MergeDocument" is working great with adding Object Presets, but if I try it with adding Tag Presets it creates a new Null and assigns the tag to that? Any ideas on how to get it to assign the tag to the selected/active object.

Also, adding Material presets don't work with this.
 
Old 01 January 2013   #10
Originally Posted by tcastudios: I'm afraid "no normal rules" apply when it comes to the Content Browser..
It's a closed file system that Python/COFFEE can't get to via the storage module.
The file base name is actually 'preset:// etc' and using / in the string
works just fine as it is "seen" only by Cinema itself.

I -wish- thou that we could browse the CB for for many reasons.

Cheers
Lennart


ay,

i did not realize, tthat you wre speaking of the .lib files directly, have not touched them
yet. should have red your path more carefully. my apologies

Last edited by littledevil : 01 January 2013 at 03:08 AM.
 
Old 01 January 2013   #11
Originally Posted by FantaBurky: "c4d.documents.MergeDocument" is working great with adding Object Presets, but if I try it with adding Tag Presets it creates a new Null and assigns the tag to that? Any ideas on how to get it to assign the tag to the selected/active object.

Also, adding Material presets don't work with this.


as lennart said you could just load the lib into a virtual base document and then
treat it in the way you like. i guess tags are being stored on a null, due to c4ds
node system. you would have to load the lib into a document, get these null out
of the docment, get all tags form the null and then add these tags to your
currently selecetd object. the same goes for materials

you should look into

c4d.documents.BaseDocument (getting object, tag and material (selections))
c4d.BaseObject (inserting tags)
c4d.GeListNode (navigating node trees)
 
Old 01 January 2013   #12
Just to add my 2 cents: \ is the escape character, not /.

Best,
Niklas
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins
 
Old 01 January 2013   #13
I got it working finally (took me a full day, had to read up on a lot of stuff). So I wanted to say thanks again for helping out =) I'm not sure I could have figured it out on my own.

I encountered a problem though, with adding Undo's. I can get it to work with adding tags by adding this line before inserting the tag:

doc.AddUndo(c4d.UNDOTYPE_NEW, presetTag)

But, when I add a CallCommand (to deselect everything in the end) after, suddenly I have to hit Undo for every object it adds a tag to. So, my question is what's the type and data used for when a CallCommand is executed? I tried a bunch of stuff, before and after this line:

c4d.CallCommand(100004767)

Any ideas?
 
Old 01 January 2013   #14
CallCommand()s are one way wrecking balls that give you
no control of your Undos.
To make your undo stack controlled (between your StartUndo() EndUndo()
you need to make them by yourself i.e. using the MODELING_COMMANDS found
in the SDK instead.
Or in this case for each of your selected object make a deselect
like: op.DelBit(c4d.BIT_ACTIVE)

Cheers
Lennart
__________________
MSA | OSX | xfiles ...Cinema4D Tools
 
Old 01 January 2013   #15
Man that works great! Thanks again Lennart =)

I'll have to read up on MODELING_COMMANDS, it looks like it will open up a lot more possibilities. And stay away from CallCommands then. Difficult though, since it's really tempting to just read the script log to easily see what the command is for certain things..
 
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 06:47 AM.


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