Limit a material to a selection tag



  • On 12/02/2018 at 12:22, xxxxxxxx wrote:

    Hi,

    I created a python script that allows to assign several materials to a mesh object

    The following three lines of code allow this operation:

    textag = c4d.TextureTag()
    textag.SetMaterial(id_material)
    id_objet.InsertTag(textag)
    

    But in addition, I want to limit each material to a selection tag

    For the mesh, I already know the list of the names of this selections.

    At first, I guess I have to extract, for the meh, the list of all selections tag to get their ID

    Then I would have to limit each material to the selection tag

    How to proceed ?



  • On 12/02/2018 at 13:04, xxxxxxxx wrote:

    As it seems, there is no specific function in the API for setting the selection, you need to go through SetParameter.

    A sample can be found in the C++ documentation:

      
        BaseTag* polygonSelection = object->GetTag(Tpolygonselection);   
        if (polygonSelection)   
        {   
          const String selectionName = polygonSelection->GetName();   
          textureTag->SetParameter(DescID(TEXTURETAG_RESTRICTION), selectionName, DESCFLAGS_SET_0);   
        }   
    


  • On 12/02/2018 at 14:37, xxxxxxxx wrote:

    Thank you for these lines of code.

    What helped me is the parameter TEXTURETAG_RESTRICTION

    Under python, we need the ID of the material-tag and the name of the selection.

    It's like that:

     **material_tag_id[c4d.TEXTURETAG_RESTRICTION] = 'name_selection'**
    

    It is true that writing in C ++ is more elegant.

    But python is more flexible than C ++

    Currently, I am rewriting all my coffee scripts, in python !



  • On 13/02/2018 at 05:05, xxxxxxxx wrote:

    Hi,

    glad the solution was already delivered.

    Just adding some info for future readers:

    The code snippet cited by Cairyn is from the TextureTag manual, maybe a good read to get some more context.

    What helped me is the parameter  TEXTURETAG_RESTRICTION

    You can drag any parameter from Attribute Manager to the Command Line (usually found under the Console) to find out about the ID. In this case, drag the "Selection" label from the Texture tag to the command line.
    Another option is to look directly into the resource files in <installation dir>/resource/modules. In this case you'll find c4dplugin/description/ttexture.res.


Log in to reply