PDA

View Full Version : Script to add something from Content Browser?


FantaBurky
01-18-2013, 05:07 PM
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?

Srek
01-18-2013, 05:44 PM
What's wrong ith the save object preset and save tag preset commands?

FantaBurky
01-18-2013, 06:22 PM
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

Srek
01-18-2013, 09:29 PM
Sorry, i was a bit tired here and got your question completely backwards :)

tcastudios
01-18-2013, 10:00 PM
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

littledevil
01-19-2013, 12:01 AM
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

FantaBurky
01-19-2013, 12:47 AM
Thanks!! That's really helpful =)

tcastudios
01-19-2013, 01:01 AM
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

FantaBurky
01-19-2013, 01:43 AM
"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.

littledevil
01-19-2013, 02:02 AM
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 :)

littledevil
01-19-2013, 02:07 AM
"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)

NiklasR
01-19-2013, 07:48 AM
Just to add my 2 cents: \ is the escape character, not /. ;)

Best,
Niklas

FantaBurky
01-21-2013, 10:22 PM
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?

tcastudios
01-21-2013, 10:39 PM
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

FantaBurky
01-22-2013, 08:10 AM
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..

CGTalk Moderation
01-22-2013, 08:10 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.