PDA

View Full Version : Python and layers


hausgross
10-07-2010, 02:54 PM
Hi guys.

I tried to access and create layers in python. Sadly I have absolutely no idea how. Everytime I try something like "lobject = c4d.BaseObject(c4d.Olayer)" the script gives me an allocation error.
Then there's the LayerObject class, but there I do not seem to have possibility to insert it into the document, because doc.InsertObject() only works with a BaseObject which I can not allocate.

Are there any solutions to this? Am I missing something really simple?

And is there any possibility to search for existing layers in the document? I the only methods for getting access to layers seems to be with a selected object and that obviously isn't what I need.

Thanx in advance
Phil

Little_Devil
10-07-2010, 03:02 PM
i think it is not what you are looking for, bute you could use callcommand.

c4d.CallCommand(100004738)

edit : the Olayer baseobject is neither mentioned in the coffee sdk nor in the c++ sdk
(index > baseobject) i guess it is not public.

donelgreeko
10-07-2010, 04:30 PM
Hi, instead of using BaseObject(Olayer) you can use:


import c4d
from c4d import documents
lay = documents.LayerObject()


Unfortunately the way to insert a layer is still not accessible. If you have a layer object which is already attached in the document you can use BaseList2D(layer).InsertAfter(newlayer), that's currently the only way how to get a layer into a document.

Cheers, donelgreeko

Scott Ayers
10-07-2010, 04:53 PM
As long as you're answering layer questions Sebastian.
Could you please help me to figure out how to use your GetLayerData function?:

Here is as far as I can get with: import c4d
from c4d import gui

def main():
obj = doc.GetActiveObject()
lobj = obj.GetLayerObject(doc)
lobj.GetLayerData(doc[what goes in here?, rawdata=False])
print lobj

if __name__=='__main__':
main()


And here's another layer example that uses a LAYER_LINK_: import c4d
from c4d import gui

def main():
obj = doc.GetActiveObject()
layer = obj[c4d.ID_LAYER_LINK]
color = layer[c4d.ID_LAYER_COLOR] = c4d.Vector(0,0,0)# Sets layer color to black
c4d.EventAdd()
print color

if __name__=='__main__':
main()

Could you tell me if there are any other things I could get from layers using the ID_LAYER_LINK code?

Thanks,
-ScottA

hausgross
10-08-2010, 11:03 AM
Thanx for the answers guys. I think I'll postpone my layer scripts. Hopefully it will be fully integrated in the future.

Cheers
Phil

eikonoklastes
03-16-2011, 05:37 AM
import c4d
from c4d import gui

def main():
obj = doc.GetActiveObject()
layer = obj[c4d.ID_LAYER_LINK]
color = layer[c4d.ID_LAYER_COLOR] = c4d.Vector(0,0,0)# Sets layer color to black
c4d.EventAdd()
print color

if __name__=='__main__':
main()


Hi Scott,

I cannot get this code you've posted here to work. Any ideas?

Scott Ayers
03-16-2011, 03:10 PM
Make sure you already have a layer on the selected object before executing that script.

That script just gets the layer that's on the selected object. Then set's it color to whatever you want . In this case black. C4D uses vectors to store RGB & HPB color values.

-ScottA

CGTalk Moderation
03-16-2011, 03:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.