plugin tag works just for 1 object
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/11/2012 at 06:42, xxxxxxxx wrote:
Hi there,
I working in a smal plugin tag that switches the object it is asigned to to invisible or to visible. everything is working but:
if I , for example, have 2 cubes in a scene. and i put the tag on one of them everything is fine. if I put the tag on both of them the tag only works for one cube (the one that is highest in the object manager). the other one is not affected. of corse I am missing something.. but obviosly I dont know what ;.(so my init is this:
def Init(self, node) : tag = node data = tag.GetDataInstance() # set camera dependent priority=c4d.PriorityData() priority.SetPriorityValue(c4d.PRIORITYVALUE_CAMERADEPENDENT,True) node[c4d.EXPRESSION_PRIORITY]=priority # put in values for the user data data.SetBool(TIMELINEONOFF, True) data.SetBool(CAMONOFF, True) return True
my execute is something like this (shorted)
def Execute(self, tag, doc, op, bt, priority, flags) : visible = 1 # set visibility if visible == 0: op[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]=1 else: op[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]=2
and my register is this:
okyn = plugins.RegisterTagPlugin(id=PLUGIN_ID, str="FS_preview_acelerator", info=c4d.TAG_VISIBLE|c4d.TAG_EXPRESSION, g=fs_pa, description="fs_pa", icon=bmp) print "fs_preview_accelerator initialized, v01: ", okyn
commends ar highly welcome
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/11/2012 at 07:02, xxxxxxxx wrote:
Hi Jops,
first of all, please see this thread for why you should follow the naming-conventions of Cinema 4D
symbols (you're missing prefixes for TIMELINEONOFF and CAMONOFF).Second, are you sure that is really the content of your Execute() method?
visible = 1
This should make if visible == 0: evalute to False always.
Next, why are you not using one of the constants defined in the Cinema 4D module? (MODE_ON,
MODE_OFF, MODE_UNDEF)Last but not least, there is a method for setting the visibility of an object, called SetEditorMode()
or SetRenderMode().Cheers,
Niklas -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/11/2012 at 08:04, xxxxxxxx wrote:
Hi Niklas,
thanks once again for your response.
I know, that my code looks awfull.
My progress in learning python must look rediculous but that happens If you just have 1 Day max per month. never the less I want to realize my ideas. And I do. It takes a while, it looks awfull, it sticks to no conventions. but (as the projects are smal) they work. thats not beautifull but I cant do better (at least for now)I have no idea of constants already defined by cinema just not jet learned. I still have problems of understanding classes, initialistaion and the rest of this objectbased stuff.
I now use the method, as you said (was it wrong the way I did it (it wasnt object oriented right?))
for the naming conventions... I will have a look at them, thats a good thing.
my execute is just a shortend version (as mentioned) and therefore doesn't make much sense
again sorry for that code (not bad willing, just disabillity) but I wrote it. it took me quite some time, and it works with the exeption of what I explained and that I cant solve. and unfortunately havent seen a answer to it in your post
and to disgust you even a bit more here is the whole code
best regards
Jopsimport c4d import os import sys from c4d import gui, plugins, bitmaps PLUGIN_ID = 1000010 frame = 0 TIMELINEONOFF = 1001 CAMONOFF = 1000 offset = (0.0,0.0,0.0) zoom = 0,0 class fs_pa(plugins.TagData) : # anfang_ layout inizialisieren def Init(self, node) : tag = node data = tag.GetDataInstance() # set camera dependent priority=c4d.PriorityData() priority.SetPriorityValue(c4d.PRIORITYVALUE_CAMERADEPENDENT,True) node[c4d.EXPRESSION_PRIORITY]=priority # put in values for the user data data.SetBool(TIMELINEONOFF, True) data.SetBool(CAMONOFF, True) return True # Ende_ layout inizialisieren def Execute(self, tag, doc, op, bt, priority, flags) : global frame, offset, zoom data = tag.GetDataInstance() cframe = doc.GetTime().GetFrame(doc.GetFps()) visible = 1 draw = doc.GetActiveBaseDraw() cam = draw.GetSceneCamera(doc) coffset = cam.GetOffset() czoom = cam.GetFocus() print coffset print czoom OnOffTimeline = data.GetBool(TIMELINEONOFF) OnOffCam = data.GetBool(CAMONOFF) # evaluate timeline if OnOffTimeline: if cframe != frame: visible = 0 frame = cframe # evaluate camera if OnOffCam: # movement if coffset != offset: visible = 0 offset = coffset #zoom if czoom != zoom: visible = 0 zoom = czoom # set visibility if visible == 0: op.SetEditorMode(c4d.MODE_OFF) else: op.SetEditorMode(c4d.MODE_UNDEF) # ende hier den code rein return c4d.EXECUTIONRESULT_OK if __name__ == "__main__": bmp = bitmaps.BaseBitmap() dir, file = os.path.split(__file__) bitmapfile = os.path.join(dir, "res", "Icon.tif") #print bitmapfile result = bmp.InitWith(bitmapfile) if not result: print "Error loading bitmap!" okyn = plugins.RegisterTagPlugin(id=PLUGIN_ID, str="FS_preview_acelerator", info=c4d.TAG_VISIBLE|c4d.TAG_EXPRESSION, g=fs_pa, description="fs_pa", icon=bmp) print "fs_preview_accelerator initialized, v01: ", okyn
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/11/2012 at 08:13, xxxxxxxx wrote:
Originally posted by xxxxxxxx
(you're missing prefixes for TIMELINEONOFF and CAMONOFF).
so they are suppoed to be named TTIMELINEONOFF and TCAMONOFF
as they are used in a tag?best wishes
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/11/2012 at 11:58, xxxxxxxx wrote:
Hi Jops,
_
> >> I know, that my code looks awfull._
Well, you're learning, as everyone here is. You'll write more clear code by time for sure.> >> I still have problems of understanding classes, initialistaion and the rest of this objectbased
>>> stuff.
I can really really recommend the official Python tutorial. It allows you to dive in very quickly. It
is easy to understand and starts from bottom up. Once I was starting out with Python, I read it
although I have been trying to write Python for about a month already (and had over a year
experience with COFFEE). It helped me a lot understanding the mechanisms of Python and of
OOP programming in general._> >> I now use the method, as you said (was it wrong the way I did it (it wasnt object oriented
>>> right?)) _
Not necessarily because of that reason (it actually was kind of OOP, however), but it is- easier to read
- I don't know about the internals of Py4D, but it could be possible that there is a reason
the method was implemented (either just for convenience, or maybe it does some
additional actions).
> >> for the naming conventions... I will have a look at them, thats a good thing. _
It's not just for making it easier to read (because you immediately know what the symbol
belongs to), but also prevents naming collisions (as I stated in the thread linked above).
_
> >> my execute is just a shortend version (as mentioned)
I must have missed that, sorry.> >> and unfortunately havent seen a answer to it in your post
That is due to the fact that there was no direct answer in my post. I think the problem lies
in the Execute() method, therefore it's a good thing that you have posted the complete code
now. As I didn't read it was the "shortened" version, I was wondering if this is really the complete code.> >> so they are suppoed to be named TTIMELINEONOFF and TCAMONOFF
No. Symbols in Cinema 4D are prefixed with what they belong to (also mentioned in the thread
linked above). Like MSG_~, PRIM_~, COLOR_~, SPLINECONTROL_~. Therefore, it is recommended
to prefix your symbols with PLUGINNAME_~. This avoids name-collisions and is easier (especially
for others) when reading your code.
Description-symbols are embedded into the c4d module (that's why names can collide). When your
plugin is installed, you can do "print c4d.TIMELINEONOFF" for example, and it will yield 1001 in
the console.Unfortunately I currently cannot see the issue directly from the code. Is it possible that
you upload the complete plugin-folder (including resource files) somewhere? If you want, I can
try to find the issue and correct your code.Just FYI, the way you store the information (frame, offset, zoom) is not OOP style.
Best,
Niklas -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/11/2012 at 01:56, xxxxxxxx wrote:
Hi Niklas,
thanks a lot for this response. kind words and good information
thanks to your information I now understand the need of prefix naming for Symbols and corrected them in the code.
I uploaded everything adn sent you the link via PM
also best
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2012 at 01:43, xxxxxxxx wrote:
Hi Jops,
I've recieved the message, thank you.
It's rather simple, but it didn't occurr to me earlier. As I already said, the
way you store the frame, offset and zoom data is not OOP style. And that is
actually why your plugin doesn't behave the way you want it.When tags are executed in Cinema 4D, they are invoked one after another. (Ok,
sometimes even parallel, but not every tag at once!) When the tag on the first
object is being executed, it does its stuff and checking, etc. AND (now comes
the fatal thing) : It sets the global information of the last frame, offset and zoom.The problem here is the word global. When the first tag was executed,
the frame, offset and zoom values are already updated, and therefore, all other
tags will work on different data than the first tag.However, it's rather easy to solve. In general, it's considered
bad style using globals in Python (and many other languages as well). They
cannot be ommited sometimes, but their use can be reduced.You can imagine the current situation like the following : Every tag is a pupil
in school, and they all have to do the same task.
- What you are doing, is let them solve it on the chalkboard. And after the
first pupil has solved it, all other pupils don't have to do it anymore.
- What a teacher should do, if all pupils must do the work on their own, is
to give each pupil their own sheet.Transferred to the world of OOP programming: Store the information in the
Tag-instance instead of in the global scope.class TagPlugin(c4d.plugins.TagData) : def __init__(self) : super(TagPlugin, self).__init__() self.last_frame = -1 # etc.. def Execute(self, tag, doc, op, bt, priority, flags) : frame = doc.GetTime().GetFrame(doc.GetFps()) if frame != self.last_frame: # ... self.last_frame = frame # etc..
Some other notable things:
- visible = 1, Rather use a boolean, like visible = True
- Rather use implicit boolean checking, like if not visible:
- I personally prefer spaces rather than tabs. This way, you have more control
over the look of your code.
- Class names are usually CamelCase. It's not a must, but widely accepted in
the community.
- It's very unusual to write variable-names CamelCase with the first letter
being uppercase. CamelCase with starting with a lowercase letter (mostly found
in Java) or even underscore separated variable names (and all lowercase, the
more Pythonic way) are more conform.
- As I already stated, you don't have to define your description symbols in the
plugin-file. They are embedded in the c4d module. You can
write data.GetBool(c4d.FSPA_TIMELINEONOFF).See the PEP8 for information about the Python style-guideline
(which, again, is not a must, just a guideline).Best,
Niklas -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2012 at 02:04, xxxxxxxx wrote:
Hi Niklas,
wow fantastic response! thanks you.
it will take a while till I got my head around this all (and corrected it in the codebest regards
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2012 at 04:59, xxxxxxxx wrote:
Hi Niklas,
again thanks a lot. I managed to make all the corrections but
data.GetBool(c4d.FSPA_TIMELINEONOFF) doesnt work... I dont think that ists a big problem. i will just stick to the way I got it workingnow I will integrate some more features and userdata.
I am quite hopefull that I can handle it from here. my plan is to make the plug public in the near future on my website.never the less, if you want to have a look at the final code...I will send it to you.
I hope to get done todaybest regards
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2012 at 05:27, xxxxxxxx wrote:
Hi Jops,
> >> data.GetBool(c4d.FSPA_TIMELINEONOFF) doesnt work... I dont think that ists a big problem
Sorry, forgot to tell you about it. That may be due to the symbolcache Cinema 4D generates. If
you change your plugin resource, Cinema might not be able to detect this and the symbolcache
won't change. The symbols in this file are loaded and then embedded into the c4d module, instead
of parsing all resources once again (which would delay startup time). You can manually delete the
file from your plugin while developing, but make sure your plugin does not delete it when you have
released it.The file is located at %appdata%/MAXON/Cinema 4D RXX/prefs. It is called coffeesymbolcache in
R12 and symbolcache in R13+.Best,
Niklas -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/11/2012 at 03:16, xxxxxxxx wrote:
Hi Niklas,
but then it seems to me that handling the way I do is more stable?
if I release a new version of the plugin I have to take care about the cache on every computer the former version was installed?best regards
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/11/2012 at 03:58, xxxxxxxx wrote:
Hi Niklas,
my plugin is not running on the renderfarm
is there something I have to care about?I uploaded the current version.
best regards
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/11/2012 at 04:01, xxxxxxxx wrote:
ok maybe I have to explain something... that might be the root of the problem.
I have to find out If the scene is rendered in the picturefiewer or in the editorview. therefor I check:
if doc == documents.GetActiveDocument() :
this works fine for the picturemanager and the editor view but maybe not for the renderfarm.
the plugin is installes on every client.
best regards
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/11/2012 at 07:42, xxxxxxxx wrote:
You should get the correct doc with:
doc = mytag.GetObject().GetDocument()Cheers
Lennart -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/11/2012 at 05:44, xxxxxxxx wrote:
Thanks lennart,
that was by the way something I was looking for, as GetOrigin doesnt work for a plugin
but:
I actually was looking for a possibility to find out if the szene is rendered in the pictureviewer, the renderfarm or the editorview.
this little function works good for the editor and pictureviewer, but not for the netrender (unfortunatelydef is_render() : # find out if rendered in Pictureviewer if doc == documents.GetActiveDocument() : return True else: return False
best regards
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/11/2012 at 06:18, xxxxxxxx wrote:
ok one step further:
this code works for pictureviewer and batchrender but not for netrender
def is_render() : # find out if rendered in Pictureviewer, batchrender and net if c4d.documents.GetBatchRender().IsRendering() : # finds out if batchrender return False if doc == documents.GetActiveDocument() : # finds out if pictureviewer return True else: return False
so maybe someone knows how I can find out If the scene is rendering with netrender?
thanks a lot
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/11/2012 at 08:12, xxxxxxxx wrote:
Have you tried to call c4d.CheckIsRunning(c4d.CHECKISRUNNING_EDITORRENDERING) and c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/11/2012 at 01:29, xxxxxxxx wrote:
Hi Yannick,
thanks again. unfortunately I didnt find it in the SDK searching for render and rendering
but now you told be thanks
c4d.CheckIsRunning(c4d.CHECKISRUNNING_EDITORRENDERING)
not working ... but I dont need it anywayc4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)
working for pictureviewer and netrender but not for batchrenderso to include batchrender the function looks loke this:
def is_rendering() : if c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING) or c4d.documents.GetBatchRender().IsRendering() : return True else: return False
it seems to work. great!
thank you all for the help
Jops -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/11/2012 at 03:22, xxxxxxxx wrote:
again... thanks a lot to all that helped me.
I published the Plugin Fs_preview_accelerator on my website.
http://www.webarts.net (english button is in the upper right corner.best regards
Jops