GetContour() refresh or uncache? How?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 21/10/2011 at 08:32, xxxxxxxx wrote:

How can I have an ObjectPlugin using GetContour()
to always refresh/update?
I have a simple spline generator that makes a spline
and set its points to the points of a point object.
(Similar to the TracerObject in a simple way)

The issue is that when I move any of the points of
the polygon object, the "source", the generated spline does
not update what ever I try.
It only updates if I click something in its AM.

Thing is, if I use GetVirtualObjects() instead, it updates
without problem. (Thou I then don't get a usable spline in return
as it's not seen as a spline object by ie Mograph stuff, Cloners, MoSpline etc)

Below is the very basic what I do and what parts I use.
Where/how do I tell GetCountour not cache itself?

Cheers
Lennart

  
def Init(self,op) :   
    data = op.GetDataInstance()   
    data.SetReal(c4d.ID_SOMETHING,n)   
    return True   
  
#def GetVirtualObjects(self,op,hierarchyhelp) :   
def GetContour(self,op,doc,lod,bt) :   
    bc          = op.GetDataInstance()   
    mysomething = bc.GetReal(c4d.ID_SOMETHING)   
    pointobject = doc.SearchObject("EditedCube")   
    pcount      = pointobject.GetPointCount()   
    spline      = c4d.BaseObject(c4d.Ospline)   
    spline.ResizeObject(pcount,0)   
    spline.SetAllPoints(pointobject.GetAllPoints())   
    spline.Message(c4d.MSG_UPDATE)   
    return spline   
  
plugins.RegisterObjectPlugin()   

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 08:11, xxxxxxxx wrote:

The only thing that comes into my mind is that the cache is optimized. Is it ?
Try using "self.SetOptimizeCache(False)"

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 09:45, xxxxxxxx wrote:

Thanks, nux.
Yea I've tried all I can think of incl SetOptimizeCache() variants.
The original plugin uses a link field for the point object source
and then I can -delete- that object from the document and the
plugin still run as if it is "hard cached" in to the GetContour() function.

As I've mentioned, the cache stuff is new territory for me but reading
the SDK and trying to figure out the concept of it for over a week takes it toll…

I hope maybe someone from Maxon can nudge me towards a solution.

Atm, just to be able to use it I've added a tag to it that simply rewrites
its name to keep it updated, that of coarse makes it slow as molasses:)
as it generates many tens of thousands of segments.

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 12:53, xxxxxxxx wrote:

This might help:http://www.microbion.co.uk/graphics/c4d/cookbook-3.htm

It's written for C++.
But the AddExecution() function is listed as being supported in the Python SDK. So it should be applicable in Python too.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 13:42, xxxxxxxx wrote:

I've just got another idea. Afaik, 'BaseObject.SetDirty()' forces to object to recalculate the cache. (does it ?)
You could simply create an invisible Tag that calls 'op.GetOrigin().SetDirty()'. Anyway, haven't tried it yet, maybe this works. 🙂

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 15:50, xxxxxxxx wrote:

Ah, the Microbion page confirms that GetContour() is a bastard! Thanks Scott.
The solution there isn't exactly pretty and is close to what I've tried
(by "force updating") and doesn't fit the criteria really as it depends on time difference instead of source editing. That is, one can't model the resulting spline
by editing the source (without playing the scene). -And- the redrawing gets very slow..

nux, I'll see what your idea might bring, but it sounds close to what I've tried
(force updating).

Thanks
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 16:27, xxxxxxxx wrote:

Nope, its AM needs a "real" input to refresh the GetContour().

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 16:45, xxxxxxxx wrote:

What about triggering a hidden UserData field in your code to update it instead?

Here's the GetContour() method of the Py-DoubleCircle.pyp SDK example. But with some code added to it that will hide the first UD entry. So the user never sees you using it:

    def GetContour(self, op, doc, lod, bt) :  
      bc = op.GetDataInstance()  
      bp = self.GenerateCircle(bc.GetReal(c4d.PYCIRCLEOBJECT_RAD))  
      if not bp: return None  
      bb = bp.GetDataInstance()  
        
      bb.SetLong(c4d.SPLINEOBJECT_INTERPOLATION, bc.GetLong(c4d.SPLINEOBJECT_INTERPOLATION))  
      bb.SetLong(c4d.SPLINEOBJECT_SUB, bc.GetLong(c4d.SPLINEOBJECT_SUB))  
      bb.SetReal(c4d.SPLINEOBJECT_ANGLE, bc.GetReal(c4d.SPLINEOBJECT_ANGLE))  
      bb.SetReal(c4d.SPLINEOBJECT_MAXIMUMLENGTH, bc.GetReal(c4d.SPLINEOBJECT_MAXIMUMLENGTH))  
        
      DoubleCircleData.OrientObject(bp, bc.GetLong(c4d.PRIM_PLANE), bc.GetBool(c4d.PRIM_REVERSE))  
        
      UD = op.GetUserDataContainer()         #Get the the container for all UD entries  
      for descId, container in UD:           #Loop through all the id's in the container  
        if descId[1].id == 1:                #Gets the first UD entry             
           container[c4d.DESC_HIDE] = True   #Set it to hidden in memory only  
           op.SetUserDataContainer(descId, container) #Execute that hidden setting from memory  
           c4d.EventAdd()  
        
      return bp

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2011 at 17:29, xxxxxxxx wrote:

Thanks Scott you're most kind, but as mentioned
any external forced triggering bogs the setup down severly.
Using GetVirtualObjects() there is no lag at several thousands
of segments of the resulting spline.

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/01/2012 at 15:42, xxxxxxxx wrote:

Any updates on this one?

Why is there no answer from Maxon?

Same here:
https://plugincafe.maxon.net/topic/6058/6220_basic-pygenerator-plugin-please&KW=create+spline&PN=1

Cheers,
André

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 03/02/2012 at 08:00, xxxxxxxx wrote:

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 03/02/2012 at 08:00, xxxxxxxx wrote:

Any news? Still waiting ...

Cheers,
maxx

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 03/02/2012 at 08:44, xxxxxxxx wrote:

Hi maxx,

this seems to work well. However, it is not really satisfying using that hack..

http://www.file-upload.net/download-4083773/GetContour.zip.html

Cheers, Niklas!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/02/2012 at 09:09, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Hi maxx,

this seems to work well. However, it is not really satisfying using that hack..

http://www.file-upload.net/download-4083773/GetContour.zip.html

Cheers, Niklas!

Hy nux, thanx for Code. But as you say, its not really satisfying. As tcastudios wrote, doing this will have severe performance drawbacks ...

Cheers,
André

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/04/2012 at 05:41, xxxxxxxx wrote:

So we have reason to believe that there is no Cache to release for GetContour()
in a similar manner as one can do with GetVirtualObjects() by not returning
a HierarchyHelp ?

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/04/2012 at 07:23, xxxxxxxx wrote:

Hi,

I contacted the developers on this issue.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/04/2012 at 08:47, xxxxxxxx wrote:

Great, thanks Yannick.

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 10/04/2012 at 07:27, xxxxxxxx wrote:

Here's the information I got from the developers.

Splines created though GetContour() are cached. To make this frame dependent CheckDirty() can be overloaded to set the object dirty if a certain condition has changed:

class TestSplineData(plugins.ObjectData) :
    
    def __init__(self) :
        doc = documents.GetActiveDocument()
        self.lastFrame = doc.GetTime().GetFrame(doc.GetFps())
    
    def CheckDirty(self, op, doc) :
        print "CheckDirty()"
        
        frame = doc.GetTime().GetFrame(doc.GetFps())
        if frame != self.lastFrame:
            self.lastFrame = frame
            op.SetDirty(c4d.DIRTYFLAGS_DATA)
    
    def GetContour(self, op, doc, lod, bt) :
        print "GetContour()"
        
        return c4d.BaseObject(c4d.Ospline)

This should only be done if absolutely necessary though, otherwise the spline (and all depending objects) will be rebuilt for every single view-redraw.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 10/04/2012 at 08:13, xxxxxxxx wrote:

Thank you very much,Yannick! That is a big step in the right direction.
I will try to get all In/Excl objects within the CheckDirty() because that is
the "core" issue I have. The generator should update on the list's object's
dirty status.
I'll report how a get (or don't get! it working.

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 10/04/2012 at 10:46, xxxxxxxx wrote:

YES YES! I'm so happy that this is solved, thanks a lot.
I've posted the important parts of one plugin I'm working with.
It needs to get dirty info from objects in a In/Excl List so I
simply could loop them and check the sum against the stored dirty sum.
Then to bypass the potential problems using GetActiveDocument() (for not active document)
I simply treat the current frame as a dirty (Long) value and include it in
the dirty sum!

Could not be happier!

Cheers
Lennart

"""   
splineGLIDE   
Copyright: tcastudios 2012   
Written for CINEMA 4D R13.+   
  
Modified Date: 2012xxxx   
"""   
  
import c4d   
import os   
import webbrowser as w   
from c4d import plugins, utils as u, bitmaps, Vector as v, documents   
from c4d.utils import SplineHelp, SplineLengthData   
  
PLUGIN_ID = 1028358 # PLUGIN ID registered by tcastudios. IF YOU MAKE ANY EDITS YOU MUST GET A NEW PLUGIN ID FROM plugincafe.com!!   
DIRTYSUM = 1027373 # Unique ID from plugincafe.com registered by tcastudios.com (PCLUSTER_MEMO)   
  
class sGLIDE(plugins.ObjectData) :   
     """splineGLIDE Generator"""   
        
     def Init(self, sglide) :   
          data = sglide.GetDataInstance()   
          data.SetReal(c4d.SG_MIX,1.0) # Mix Float   
          data.Set etc……   
          return True   
  
     def CheckDirty(self,op,doc) :   
          obc        = op.GetDataInstance()   
          dirtysumbc = obc.GetContainer(DIRTYSUM)   
          dlist      = obc.GetData(c4d.SG_SOURCES) #InExclude List objects to get dirty from   
          lcount     = dlist.GetObjectCount()   
             
          checksum = doc.GetTime().GetFrame(doc.GetFps()) # Use frame as a dirty integer (Long)   
          for d in xrange(lcount) :   
               checksum += dlist.ObjectFromIndex(None ,d ).GetDirty(c4d.DIRTY_DATA|c4d.DIRTY_MATRIX |c4d.DIRTY_CHILDREN|c4d.DIRTY_CACHE|c4d.DIRTY_SELECT)   
  
          if (checksum != dirtysumbc.GetLLong(0)) :   
               dirtysumbc.SetLLong(0,checksum)   
               obc.SetData(DIRTYSUM,dirtysumbc)        # Store new checksum into Container   
  
     def Construct(self,sglide) :   
          sbc        = sglide.GetDataInstance()   
          myfader    = sbc.GetReal(c4d.SG_MIX)   
          myetc      = sbc.Get etc etc   
          myspline   =   
          myspline   = c4d.BaseObject(c4d.Ospline)   
          # code that do things with spline from In/Excl List objects   
          return     myspline   
  
     def GetContour(self, sglide, doc, lod, bt) :   
          return self.Construct(sglide)   
  
if __name__ == "__main__":   
    path, file = os.path.split(__file__)   
    bmp = bitmaps.BaseBitmap()   
    bmp.InitWith(os.path.join(path, "res", "splineGLIDE.tif"))   
    splineGLIDELoaded = plugins.RegisterObjectPlugin(id=PLUGIN_ID,   
                    str="splineGLIDE",   
                                g=sGLIDE,   
                                description="splineGLIDE",   
                                icon=bmp,   
                                info=c4d.OBJECT_GENERATOR | c4d.OBJECT_ISSPLINE )   
                                   
    if splineGLIDELoaded:   
        print 'splineGLIDE v1 Loaded'   

edit: Don't need to set checksum again for the op.