I want to add selected objects at selected layer
To my mind it should be in the following way:
- select object
- press the button of script
- select layer from the list of layers
How to add all layers in custom menu If this variant is right?
 Offline
Offline
I want to add selected objects at selected layer
To my mind it should be in the following way:
How to add all layers in custom menu If this variant is right?
Hello for everyone! How to add selected objects at selected layer in layer mager?!!

edit: I restored your image, we will answer the posting tomorrow  [ferdinand]
 [ferdinand]
@mogh I didn't know about this function 
@ferdinand Thank you a lot for your detailed response. I will chek posts which you recommended
Hello guys! Is it real to check everything in layer (objects, materials, tags) and delete layer if its empty?
Script add a null in center of world coordinates. I want to change it, i described what i want to do in pictures.

I added Mike's code, because i wanted to make 2 options for Step 2:
I'm sorry for my English...
@ferdinand , thank you a lot!
When i tried to fix my code i used Mike Udin's example, but i couldn't understand why this code didn't work with multiple objects. I've got next message: "AttributeError: 'NoneType' object has no attribute 'GetAllPoints'".
I supposed my script to set selected objects' axis points in the center for each other. After that the script should create a null between all axis points.
import c4d
def main():
    
    ps = op.GetAllPoints() #Points in Local coordinates List
    m = op.GetMg() #Object Global Matrix
    center = op.GetMp() #Local coordinates center: https://tinyurl.com/wed88cn
    rad = op.GetRad() # Geometry radius: https://tinyurl.com/tb6vn64
    
    center -= c4d.Vector(0,rad.y,0) #Move down axis to lowest point. Comment this line to keep axis in a center 
    
    center *= m #Convert to Global coordinates center
    new_m = c4d.Matrix(m) #Copy matrix
    new_m.off = center #Change its center
    loc_m = ~new_m * m #Get local matrix
    op.SetAllPoints([loc_m.Mul(p) for p in ps])
    op.SetMg(new_m)
    
    op.Message(c4d.MSG_UPDATE)
    c4d.EventAdd()
if name == 'main':
    main()
edit: This topic has been forked from How to fix the bug of objects position in script by @ferdinand
Guys! Please, help. I cannot fix this problem.
The main idea of this script is:
: video
import c4d
def main():
    doc.StartUndo()
    layer = c4d.documents.LayerObject()
    # Set layer name (another option tp set the name)
    # Get the invisible root layer
    layerRoot = doc.GetLayerObjectRoot()
    # Insert the layer under the parent
    layer.InsertUnder(layerRoot)
    name = layer.GetName()
    rvalue = c4d.gui.RenameDialog(name) # rename
    print(rvalue)
    layer [c4d.ID_BASELIST_NAME] = rvalue
    #layer.DelBit(c4d.BIT_ACTIVE)
    null_obj = c4d.BaseObject(c4d.Onull)
    null_obj [c4d.ID_LAYER_LINK] = layer
    null_obj [c4d.ID_BASELIST_NAME] = rvalue
    doc.InsertObject(null_obj)
    doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, layer)
    doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, null_obj)
    s = doc.GetSelection()
    vp = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE)
    for obj in vp:
        print obj
        obj [c4d.ID_LAYER_LINK] = layer
        obj.InsertUnder(null_obj)
        obj_mat_tags = [t for t in obj.GetTags() if t.IsInstanceOf(c4d.Ttexture)]
        for tag in obj_mat_tags:
            mat = tag.GetMaterial()
            print mat
            mat [c4d.ID_LAYER_LINK] = layer
    doc.EndUndo()
    c4d.EventAdd()
if __name__ == '__main__':
    main()
I use r21 version of c4d.
@ferdinand Thank you a lot for your help! I'm really sorry for organization of my post. Could you point out on my mistakes in tagging?
Dear community!
I want to create length port for spline node but I can’t find correct command for it.
How to get id of port in form like this
c4d.GV_PORT_OUTPUT, [c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X]