object with python tag from cammand plugin[SOLVED]
On 02/02/2015 at 02:17, xxxxxxxx wrote:
Hi, I got stuck a little bit with my command plugin. The command part really works well, but I would also like to generate an object with a python tag from it. I would be really thankful about a hint in the right direction. Thanks, Volker.
On 02/02/2015 at 03:29, xxxxxxxx wrote:
it depends on what you´re going to do.
It seems to me that an object plugin might be the better choice?
But you can insert an object within the init values function from your dialog class, or through a button click within the command function from your dialog class.
def InitValues(self) : doc = c4d.documents.GetActiveDocument() obj = c4d.BaseObject(c4d.Onull) PyTag = obj.MakeTag(c4d.Tpython) print PyTag[c4d.TPYTHON_CODE] doc.InsertObject(obj)
def Command(self, id, msg) : if id == YOUR_BUTTON_ID: doc = c4d.documents.GetActiveDocument() obj = c4d.BaseObject(c4d.Onull) PyTag = obj.MakeTag(c4d.Tpython) print PyTag[c4d.TPYTHON_CODE] doc.InsertObject(obj)
from the Elbe
On 02/02/2015 at 05:24, xxxxxxxx wrote:
Hi Martin, thanks for the quick response. Yes, I am struggling with if it is either a command or object plugin. But since most of the functionality will be commands, I thought that a command plugin is the way to go. The one object I am creating needs more than a few lines of code. With 'PyTag=obj.MakeTag(c4d.Tpython)' and 'PyTag[c4d.Tpython]="Sample Code"' I could create a tag and assign a string with code to it. But the object needs more than a line of code. How could I read the code for the python tag from a file, module or a function? Thanks and best wishes from the Elbe too.
On 02/02/2015 at 06:28, xxxxxxxx wrote:
Of course i could read a file the python way with "tag_code = open('sampleCode', 'r')" and "py_tag[c4d.TPYTHON_CODE] = tag_code.read()"! But I guess there must be a c4d kind of way.
On 02/02/2015 at 06:31, xxxxxxxx wrote:
when you initialize your icons, pictures for Bitmap buttons.etc., you can load a python file with your code for the python tag, too ( e.g. placed in your res folder) :
path, fn = os.path.split(__file__) tagpath = os.path.join(path, "res", "PYTHON_Tag.pyp")
Within your init function you can read this file like:
doc = c4d.documents.GetActiveDocument() obj = c4d.BaseObject(c4d.Onull) PyTag = obj.MakeTag(c4d.Tpython) with open(tagpath,'r') as f: content = f.read().replace('\n', '') f.close() PyTag[c4d.TPYTHON_CODE] = content print PyTag[c4d.TPYTHON_CODE] doc.InsertObject(obj) c4d.EventAdd()
This Thread might be interesting for you , too
On 02/02/2015 at 06:36, xxxxxxxx wrote:
you knew it already
On 02/02/2015 at 06:58, xxxxxxxx wrote:
Thanks Martin, glad to hear that I wasn't on the wrong track. Thanks a lot for the help.
On 02/02/2015 at 09:44, xxxxxxxx wrote:
the Python API does not include any special functions to read generic files, one has to use the default Python functions.
On 03/02/2015 at 01:44, xxxxxxxx wrote:
I am still confused with the principles of the c4d python sdk, that's why I thought that there should be a better or a c4d kind of way. But my plugin works very well and I am enjoying using Python inside of c4d. I guess it needs some time to get used to it. I wish that there would be a kind of overview how everything works together in c4d.
Two last questions came up:
The code inside the python tag, which I generated together with a camera from my command plugin, is visible to everyone. When I protect the source code, the python tag editor will be "binary", unreadable too? Can I disable the visibility of the code completly?
Can I change the icon of the python tag to a special user one?
Thanks a lot for the help one this forum! Cheers, Volker
On 03/02/2015 at 02:19, xxxxxxxx wrote:
Python code will always be visible to everyone. The only exception are protected Python plugins. Tools like the Python Tag are build to be used by artists and to allow fast development. Hiding a Python Tag's Python code is not intended. So protecting the source code of a Python plugin has no effect on any Python Tag. Also, the protection of Python plugins is build to prevent "accidental" editing of the source file; it cannot guarantee that nobody else is able to read the source code.
The icon of the Python Tag cannot be changed. In fact, the icon is an indicator if there was an error while handling the Python code or not.
For questions no longer related to this thread's original topic please open a new thread. Thanks.
On 03/02/2015 at 02:29, xxxxxxxx wrote: