Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Limit a material to a selection tag

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 816 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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 ?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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);   
            }   
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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 !

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post