How to know names of selections with Alembic

On 13/02/2018 at 19:57, xxxxxxxx wrote:


I would like to know if with python we can read the name of the selections for a mesh object, without using the selection tags.

With Python, reading selection tags is very easy by exploring the object tree.
Until now, with the import of files with C4D, the selection tags were displayed in the list of objects.
But I recently discovered the new type of file with Alembic format , very convenient for handling complex scenes just before the final rendering.

C4D imports files in Alembic format, but it doesn't represent selections tags in the usual form, with triangular icons, in the list of objects. 
We can however see these selections in the properties of the object, but under Python they aren't accessible through tags.

In this example, with Marvelous Designer, we see that the mesh selection tags aren't displayed. 
I also have this problem with alembic file exported by Daz Studio 4.10

I can indirectly establish for each object the list of these selections, by previously importing the file in FBX format because C4D uses in this case the usual selection tags. 
But this way of proceeding leads me to go through an intermediate stage.

Even with files imported in Alembic format, it is possible with Python to apply a material to a mesh with a selection, using the following line of code:

 **textag[c4d.TEXTURETAG_RESTRICTION] = selection_name**

This means that C4D does have the correct information about the mesh selections, even if they aren't displayed with the usual tags.

Below a tutorial who show how an user import in C4D an alembic file, for texturing it.
This user use an FBX export to obtains the list of materials.
Then, the application of textures is done manually.
It's clever, but appallingly long and tedious !
It's this procedure that I fully automated with Python, under C4D.
With the FBX file, I build the object tree including the selections.
But I would like to do this without going through an FBX file.

The developers of C4D have certainly, for technical reasons, treated the files in Alembic format in a different way, but it would still be interesting to be able to handle them with Python.

On 14/02/2018 at 02:26, xxxxxxxx wrote:


somehow I have the feeling, I forgot to welcome you in our community.
So, a belated:
Welcome to the Plugin Café forums :slightly_smiling_face:

Indeed the Alembic selection tags are a bit different, unfortunately there's no symbol defined for the Alembic selection tag, so you will need to refer to it by 1036433.
Now, if you have the Alembic selection tag you can request the "real tag" (so basically the actual selection tag) via Message(MSG_GETREALTAGDATA).
Like so:

if tag.GetType() == 1036433: # check for Alembic selection tag
    realtag = {}
    tag.Message(c4d.MSG_GETREALTAGDATA, realtag)
    realSelectionTag = realtag['res']
    print realSelectionTag.GetName()

Note: There's a small glitch in the Python docs. MSG_GETREALTAGDATA returns a BaseSelect, while MSG_GETREALCAMERADATA returns a Baseobject. This will be fixed by an updated documentation, soon.

On 14/02/2018 at 08:22, xxxxxxxx wrote:


I am intrigued when reading your first line of code

How do you get the ID of the tag corresponding to the Alembic object ?

For Alembic objects selection tags aren't visible in the window that lists the objects, but they aren't also accessible in the tree that is retrieved with doc.GetObjects ()

However, I have just found the solution to my problem, by chance.

A simply conversion in objet... B I N G O !!!  :smile: :smile: :smile:

After conversion in objet, selection tags appear in their usual form, with orange triangles.

It's very interesting for programming with Python, because we can then exploit the tree that represents the objects of the scene.

This conversion doesn't have much interest for builders because the Alembic format isn't intended for mesh manipulation.

The Alembic format will be very appreciated by the people who work at the end of the production chain.
We remember the promises concerning the Collada format which was supposed to solve the incompatibility problems between the formats !

However, Collada and FBX remain interesting if they are used throughout the same production chain, which is the case for major studios.

But for other users who work in a traditional way, with softwares and heterogeneous files, the Alembic format is a huge step forward.

I recall here that Blender crashes lamentably when importing some Alembic files, which is all the more regrettable that Alembic isn't a proprietary format !

With C4D, life is Beautiful  :smile:

On 14/02/2018 at 12:39, xxxxxxxx wrote:

My function:

def alembic_selection_tags(obj) :
    #return a list that contains the names of selection tags for an alembic object

ALEMBIC_TYPE = 1028083
    SELECTION_TAG = 5673
    if obj.GetType() != ALEMBIC_TYPE:return []

obj = obj.GetClone()
    doc = c4d.documents.BaseDocument()
    obj = c4d.utils.SendModelingCommand(
        command = c4d.MCOMMAND_MAKEEDITABLE,
        list = [obj],
        doc = doc )
    polygone = obj[0].GetDown()
    Ltag = []
    tag = polygone.GetFirstTag()
    while tag != None:
        if tag.GetType() == SELECTION_TAG:
        tag = tag.GetNext()
    return Ltag

There is probably a simpler and more elegant method

On 15/02/2018 at 02:59, xxxxxxxx wrote:

Hm? Which version of Cinema 4D are you using?
I tested here with R19 and the Alembic selection tags are shown in the Object Manager. So, you can get the ID of the tag easily by dragging it to the Command Line and pressing return on the Command Line.

And then the code looks like so:

    obj = # get your Alembic object here
    tag = obj.GetFirstTag()
    while tag is not None:
        if tag.GetType() == 1036433: # Check for Alembic selection tag
            realtag = {}
            tag.Message(c4d.MSG_GETREALTAGDATA, realtag)
            print realtag['res'].GetName()
            # use the real selection tag...
        tag = tag.GetNext()

Of course you can also do the conversion as shown in your code. There's nothing wrong with it. Especially if you have a use case for the converted object. But performance-wise it's definitely slower.

On 15/02/2018 at 04:45, xxxxxxxx wrote:


I downloaded the demo of the latest version of C4D and saw that the selection tags were visible, which is not the case on older versions.

With this new version, tags of selection are accessible directly by python.