XRAY not working in ObjectPlugin

On 11/09/2013 at 11:08, xxxxxxxx wrote:

I'm trying to set the XRay parameter of a sphere created with an ObjectPlugin.
However, it is not working in R13, R14 or R15?
Note: Changing the radius in working.

Here is the code:

import c4d, os, sys
from c4d import bitmaps, documents, gui, modules,  plugins, utils
  
PXRAY = 1027
PPREVIEWSIZE = 1028
  
class C4DEnvironment(plugins.ObjectData) :
  
    def Init(self, op) :
        op[PXRAY] = False
        op[PPREVIEWSIZE] = 150
        return True
        
    def GetVirtualObjects(self, node, hierarchyhelp) :
    
        doc = documents.GetActiveDocument()
       
        c4dnull = c4d.BaseObject(c4d.Onull)
        c4dnull[c4d.ID_BASELIST_NAME] = "C4Dome"
  
        preview = c4d.BaseObject(c4d.Osphere)
        preview.InsertUnder(c4dnull)
  
        preview[c4d.ID_BASEOBJECT_XRAY] = node[PXRAY]   
        preview[c4d.PRIM_SPHERE_RAD] = node[PPREVIEWSIZE]
  
        return c4dnull
            
if __name__ == "__main__":
  
    pluginstr = "XRAY TEST"
  
    path, file = os.path.split(__file__)
    bmp = bitmaps.BaseBitmap()
    bmp.InitWith(os.path.join(path, "res", "lonlatsweep.tif"))
  
                                
    okyn = plugins.RegisterObjectPlugin(id          = 102972625, 
                                 str         = pluginstr,
                                 g           = C4DEnvironment,
                                 description = "c4de",               #link naar res directory, etc.
                                 icon        = bmp,
                                 info        = c4d.OBJECT_GENERATOR)
  
    if (okyn) : 
        print pluginstr + " initialized."
    else: print "Error initializing " + pluginstr

And here the res file:

CONTAINER c4de
{
	NAME c4de;
    INCLUDE Obase;
    
	GROUP SETTINGS
	{
        BOOL PXRAY {}
        REAL PPREVIEWSIZE { MIN 0; MAX 1000; STEP 1;}
	}
}

On 12/09/2013 at 00:14, xxxxxxxx wrote:

Some further testing showed that it is working in a TagPlugin.
Could it be that it is not working in a ObjectPlugin due to the fact that the sphere I want to xray is a virtual object?

On 12/09/2013 at 04:29, xxxxxxxx wrote:

Hi Pim,

Yes I think the problem is that the object is a virtual object, I remember
having a similar problem a very while ago. I'll do some research about it.

Best,
Niklas

On 12/09/2013 at 06:01, xxxxxxxx wrote:

the node (the gelistnode representing your plugin) has to be flagged ID_BASEOBJECT_XRAY 
to be drawn in the XRAY pass or the ID_BASEOBJECT_XRAY of your cached children won't have
any effect. Your code should work when you do add

> node[c4d.ID_BASEOBJECT_XRAY] = node[c4d.PXRAY]

to your GVO method.

edit : FYI, you might have to add c4d.OBJECT_POLYGONOBJECT as a plugin flag to your
plugin registration to get the xray thing to show up in your description and therefore get
whole thing to work. If you want to hide it then again you have to do that in your plugins
description.

INCLUDE Obase;
    HIDE ID_BASEOBJECT_XRAY;

On 12/09/2013 at 07:21, xxxxxxxx wrote:

Hi littledevil,

Sorry, I do not fully understand following lines
"FYI, you might have to add c4d.OBJECT_POLYGONOBJECT as a plugin flag to your
plugin registration to get the xray thing to show up in your description and therefore get
whole thing to work. If you want to hide it then again you have to do that in your plugins
description."

I now have this code:

node[c4d.ID_BASEOBJECT_XRAY] = node[PXRAY]        
        preview[c4d.ID_BASEOBJECT_XRAY] = node[PXRAY]

However, the whole GVO object is now XRAY, not just the preview object.

I also included HIDE ID_BASEOBJECT_XRAY;
INCLUDE Obase; was already there.

On 12/09/2013 at 08:03, xxxxxxxx wrote:

What I meant with the quoted part is that without OBJECT_POLYGONOBJECT the xray checkbox
in Obase is hidden by c4d by default ( if I do remember correctly ), so I thought the xray pass
might also be skipped ( which does not seem to be the case from what you have described
in your latest posting ).

About the current problem - I do not think there is a way around. I have written recently a little 
object plugin replacing null objects. Long story short - I thought I could use the display color to
return splines with various colors to draw some stuff into the viewport and have not to care so 
much about caching and speed. It turned out I could not (at least I did not find a way), as all GVO 
children always do inherit the display color of the hosting node in the object manager. I did end 
up drawing everything myself in Draw(). I think the same goes for the XRAY option, all children 
will inherit the nodes settings and their own settings will be overwritten.

And then again, I do not know 100% for sure.

On 12/09/2013 at 08:26, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Could it be that it is not working in a ObjectPlugin due to the fact that the sphere I want to xray is a virtual object?

Try it like this:

import c4d, sys, os  
from c4d import plugins, utils, bitmaps, gui,documents  
  
PLUGIN_ID = 10000008        #be sure to get a unique plugin id from c4dcafe.com  
  
class MyObject(plugins.ObjectData) :  
  
  def __init__(self) :  
      self.SetOptimizeCache(False)  
      self.myMaterial = c4d.BaseMaterial(c4d.Mmaterial)   #A class member reference to a new material  
        
        
  def Init(self, op) :      
      op.SetName("My Object")                      #op is the generator object  
        
      self.InitAttr(op, float, [c4d.P1])           #Init the values you defined in your res file  
      self.InitAttr(op, float, [c4d.P2])           #Init the values you defined in your res file  
        
      return True  
        
        
  def Build(self,op) :  
      doc = documents.GetActiveDocument()      
        
      obj = c4d.BaseObject(c4d.Ocube)  
        
      doc.InsertMaterial(self.myMaterial)           #Insert the new material into the Material Manager  
  
      ttag = c4d.TextureTag()                       #Create a new texture tag  
      ttag.SetMaterial(self.myMaterial)             #Set the referenced material        
      obj.InsertTag(ttag)                           #Add the texture tag to the object in the OM  
        
      return obj.GetClone()          
    
  def GetVirtualObjects(self, op, hierarchyhelp) :  
    
      p1 = op[c4d.P1]                              #Get the value in this gizmo  
      print p1  
        
      p2 = op[c4d.P2]                                 #Get the value in this gizmo      
      if p2 == 1: op[c4d.ID_BASEOBJECT_XRAY]=True  
      else: op[c4d.ID_BASEOBJECT_XRAY]=False          
  
      ret = self.Build(op)                         #Assign a variable to the custom build function so we can use it later   
      ret.InsertUnder(op)                          #Insert the result from it into the OM as child of the generator object  
        
      return ret                                   #The object was built in the custom "Build" function...So that's what we return with the generator  
  
        
if __name__ == "__main__":  
  dir, file = os.path.split(__file__)  
  icon = bitmaps.BaseBitmap()  
  icon.InitWith(os.path.join(dir, "res", "icon.png"))  
  plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="MyObject",  
                              g=MyObject,  
                              description="MyObject", icon=icon,  
                              info=c4d.OBJECT_GENERATOR)

.h file

  
#ifndef _MyObject_H_  
#define _MyObject_H_  
  
enum  
{  
  P1 = 1000,      
  P2 = 1001,  
};  
  
#endif

.res file

CONTAINER MyObject  
{  
  NAME MyObject;  
  INCLUDE Obase;  
  
  GROUP ID_OBJECTPROPERTIES  
  {  
      GROUP  
      {                          
        REAL P1 { UNIT METER; MIN 0.0; }  
        BOOL P2 {  }  
      }  
  }  
    
}

The .str file

STRINGTABLE MyObject  
{   
  MyObject        "My Object";  
  
  P1                 "Value";      
  P2               "x-ray";  
  
}

-ScottA

On 12/09/2013 at 11:36, xxxxxxxx wrote:

Thanks Scott,

I tried your code, but it XRAYS all virtual objects. and not the want I want.
E.g. I simplified the code to generate a cube with a sphere as a child.
Then I tried to xray just the sphere and that is not working.
XRAY op is xray-ing everything
XRAY just the sphere is not working.

    def GetVirtualObjects(self, op, hierarchyhelp) :
       
        cube = c4d.BaseObject(c4d.Ocube)
        sphere = c4d.BaseObject(c4d.Osphere)
        sphere.InsertUnder(cube)
        sphere[c4d.PRIM_SPHERE_RAD] = 150
        
        p2 = op[c4d.P2]                                 #Get the value in this gizmo    
        if p2 == 1: sphere[c4d.ID_BASEOBJECT_XRAY]=True
        else: sphere[c4d.ID_BASEOBJECT_XRAY]=False   
        
        return cube