How to get layer colour from layer dict?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 08:54, xxxxxxxx wrote:
I can get the layer info
but cannot access the individual elements as per the SDKReturn type:
dict{solo: bool, view: bool, render: bool, manager: bool, locked: bool, generators: bool, expressions: bool, animation: bool, color: Vector}I get an error - dict object has no attribute 'color' ?
help appreciated
import c4d from c4d import gui def main() : doc = c4d.documents.GetActiveDocument() root = doc.GetLayerObjectRoot()#Gets the layer manager LayersList = root.GetChildren() for layers in LayersList: print layers.GetName() if layers.GetBit(c4d.BIT_ACTIVE) : print"Selected Layer: ", layers.GetName() print"Selected Layer Settings: ", layers.GetLayerData(doc) print"Selected Layer Colour: ", layers.GetLayerData(doc).color #this line doesnt work if __name__=='__main__': main()
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 09:55, xxxxxxxx wrote:
After some testing, I could find out that c4d.ID_LAYER_COLOR is the constant you are looking for. Unfortunately there is nothing documented about LayerObjects.
Also, either the iteration over a c4d.BaseContainer is not implemented correctly or the LayerObject uses another container than returned by GetData() internally, as doing so leads to the belive that options of a LayerObject are not accessible for us.
Can someone of Maxon please enlighten me?import c4d def main() : root = doc.GetLayerObjectRoot() layers = root.GetChildren() layer = layers[0] # this wont yield anything to the console for k, v in layer.GetData() : print k, v # but this works print layer[c4d.ID_LAYER_COLOR]
Cheers,
Niklas -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 10:15, xxxxxxxx wrote:
ah - should have learnt by now - if all else fails - look in the description headers
so for my version
print"Layer Colour: ", layers[c4d.ID_LAYER_COLOR]gives me the rgb vector
thanks for looking Niklas
it would be useful to know from Maxon how to use
layers.GetLayerData(doc) ........and get the colour that way -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 10:44, xxxxxxxx wrote:
I don't think you can get the color from BaseList2D.GetLayerData().
I haven't take a look into the header-files. There's a much more convenient way to search for constants in the c4d module.import c4d def getNamesByValue(obj, value) : for k, v in obj.__dict__.iteritems() : if v == value: yield k
@Maxon: Why the heck is GetLayerData implemented in the BaseList2D class? Don't get it.. A LayerObject instance has ** exactly** the same methods and as a BaseObject object...
import c4d def main() : layer = c4d.documents.LayerObject() obj = c4d.BaseObject(c4d.Ocube) layer_attrs = dir(layer) obj_attrs = dir(obj) print print for layer_attr in layer_attrs: if layer_attr not in obj_attrs: print layer_attr print "- " * 20 main()
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 12:41, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Return type:
dict{solo: bool, view: bool, render: bool, manager: bool, locked: bool, generators: bool, expressions: bool, animation: bool, color: Vector}I get an error - dict object has no attribute 'color' ?
print"Selected Layer Colour: ", layers.GetLayerData(doc).color #this line doesnt work
As you've said, the return type of GetLayerData() is a dictionary so you should access the color of a layer by calling the [] operator:
print"Selected Layer Colour: ", layers.GetLayerData(doc)['color']
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 13:00, xxxxxxxx wrote:
Ah lol, I haven't seen that there is actually the color value in the dictionary! Sorry.
Still missing an explanation why the iteration over the BaseContainer of the LayerObject does not work correctly.Cheers,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 13:04, xxxxxxxx wrote:
thanks for the syntax Yannick
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/01/2012 at 13:20, xxxxxxxx wrote:
Nux is right.
There's something not right about the GetLayerData() function.
It doesn't work using a Baselist2D type like it claims it does in the docs:import c4d def main() : root = doc.GetLayerObjectRoot() #Type = 110063 print root.GetType() layer = root.GetDown() #Get the first layer lh = layer.GetListHead() #Type = 110063 print lh.GetType() lh.GetLayerData(doc, True) #Error: BaseList2D has no attribute 'GetLayerData' root.GetLayerData(doc, True) #Error: BaseList2D has no attribute 'GetLayerData' if __name__=='__main__': main()
Here's a working C++ example where GetLayerData() works properly:
//Sets the color of the first layer to white GeListHead *llist = doc->GetLayerObjectRoot(); //Get the root and store it in the GeListHead variable called "llist" if(!llist) return FALSE; LayerObject *layer = (LayerObject* )llist->GetFirst(); //Get the first layer if(layer) { LayerData ldata(*layer->GetLayerData(doc, TRUE)); //Get the layer's container ldata.color = Vector(1.0,1.0,1.0); //Set the layer's color to white in memory only layer->SetLayerData(doc, ldata); //Execute the changes made to the layer layer->Message(MSG_UPDATE); EventAdd(); }
Notice that in the C++ example. The data type used to access the GetLayerData() function is a "LayerData" type.
But in the python SDK. All we seem to have access to is the GeListHead, and LayerObject types.
Without the LayerData type. How are we supposed to use the GetLayerData() function?***Edit- DOH!
The reason why GetLayerData didn't work for me is because I was using R12. And it seems that this is only available in R13.
I hate when that happens.
**
-ScottA