Jump to content

[Py] Material swap on some Generator objects only shows after viewport redraw


Recommended Posts

I am swapping between 2 materials with a checkbox through a simple python/xpresso setup.

Everything works fine with instant preview except when applied to certain generator objects. Sweep works but Extrude, Lathe and Loft require a forced redraw (A) to display any effects. I tried adding a  c4d.EventAdd() or c4d.DrawViews() after the function but it doesn't seem to have any effect.

 

What's the difference between the way they are rendered and how can I make it work?

 

thanks!

Link to post

...and perhaps state what "instant preview" is. I thought of the IRR at first, but now I have a feeling that it's one of these special preview windows of some external renderer, like Redshift.

(IRR requires a DrawViews first, then an EventAdd to re-render, but as OP states, they tried that already...)

Link to post

sorry, should've added the screenshot right away.

By instant preview I mean c4d's own viewport, no external renderer, no IRR. However, the results remain the same as in the viewport when rendered.

I've connected the same python code to 3 different objectsMoText works and swaps the mat in the viewport, but both Extrude and Sweep do so only after manual redraw (A). (sweep actually worked before, now it doesn't). thanks

Annotation 2020-07-26 121325.png

Link to post

In an XPresso Python node, you normally should not call DrawViews or EventAdd - you're in the middle of the object tree evaluation already. (I think C4D is smart enough to just skip these commands.)

 

You didn't include the C4D file so I can't test (not going to copy all your effort) but my impression is that C4D doesn't know that the objects have changed - the XPresso setup ends with the Python tags, instead of with an object that gets changed explicitly. So, you may want to try SetDirty() on the changed object

obj.SetDirty(c4d.DIRTYFLAGS_DATA)

(Note: May need/want to set the Dirty flag on the object and/or the material tag, just check what is better)

Link to post

Assigning to the object seems to work! Thanks!
So just to understand it better, SetDirty method basically declares the object's latest state and implies a redraw?

Where would I call (in my setup) EventAdd and DrawViews then?

Thanks!

Link to post

Set Dirty tells the system that an object has been changed, and - depending on the flags that you pass - certain aspects of the object need to be refreshed (like the cache, or the dependent objects). In this case, I assume that the problem is that an Extrude is a generator, which has virtual polygon objects cached, so the cache needs to be rebuilt to show the correct color. The system will automatically handle redraws according to that condition.

 

You don't call DrawViews or EventAdd at all. These functions are only needed in plugins or independent scripts to enforce a refresh, not in Python tags, nodes, generators, fields, effectors... (You also don't use Undo there.)

 

At the time when the XPresso tag is evaluated, C4D is already halfway along to a redraw. So, neither function is necessary under the circumstances. (And since your XPresso might be executed in a separate thread, you can't use various functions anyway.) EventAdd doesn't even perform a redraw immediately, but only sends a message to the system that a redraw will be necessary ASAP.

 

----------
Learn more about Python for C4D scripting:
https://www.patreon.com/cairyn

 

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...