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

    Getting material assignment

    Scheduled Pinned Locked Moved PYTHON Development
    7 Posts 0 Posters 866 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 08/11/2013 at 12:15, xxxxxxxx wrote:

      Using python how can I get a list of objects in the assignment tab of a material

      This is where I'm at:

      myMat = doc.GetActiveMaterial()
          Olink = myMat[c4d.MATERIAL_PAGE_ASSIGNMENT]
          print Olink
      

      However it just returns None.

      Any help is appreciated!

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

        On 08/11/2013 at 21:32, xxxxxxxx wrote:

        Hi,
        Man, Iam glad you posted that cause i had problems in r13 with the ### python sdk , I spent tree days trying to make MatAssignData.GetObject(index, doc) in r13 sdk to work aand by luck I think I read R15 SDK and FOUND  MatAssignData.ObjectFromIndex(doc, Index) which is WORKING, that was I thought at first, but it only returns the texture tag only.

        so here the code, the trick is to use c4d.ID_MATERIALASSIGNMENTS not c4d.MATERIAL_PAGE_ASSIGNMENT.

        import c4d
        from c4d import *
        #HOPE SOMEONE WILL EXPLAIN!!!!
        def main() :
            myDoc=documents.GetActiveDocument()
            myMat = doc.GetActiveMaterial()
            
            Olink = myMat[c4d.ID_MATERIALASSIGNMENTS]
            myCount = Olink.GetObjectCount()
            for i in xrange(myCount) :
                print i, " : ", Olink.ObjectFromIndex(myDoc,i)
        

        If you are a C++, you can try to port this code to python
        BaseMaterial *mat = doc->GetActiveMaterial();
        if(!mat) return TRUE;
        GeData d;
        if(mat->GetParameter(DescLevel(ID_MATERIALASSIGNMENTS),d,0))
        {
             MatAssignData *mad = (MatAssignData* )d.GetCustomDataType(CUSTOMDATATYPE_MATASSIGN);
             if(mad)     GePrint("found it");
             GePrint(LongToString(mad->GetObjectCount())+" objects");
        }

        Have a nice week-end!

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

          On 09/11/2013 at 08:24, xxxxxxxx wrote:

          **Python version
          **

            
          #This script lists all the objects that are listed in a materials "Assignment" option  
            
          import c4d  
          def main() :  
            
            myMat = doc.GetActiveMaterial()  
              
            ObjLink = myMat[c4d.ID_MATERIALASSIGNMENTS]   #The object Assignment option in the material  
            
            myCount = ObjLink.GetObjectCount()  
            for i in xrange(myCount) :  
                tag = ObjLink.ObjectFromIndex(doc,i)      #Gets the tag that's on the object  
                obj = tag.GetObject().GetName()           #Gets the object the texture tag is attached to  
                print obj, tag  
                          
          if __name__=='__main__':  
            main()
          

          **

          C++ version
          **

          //This is an example of getting all the objects that are listed in the material's Assignment link list  
            
          #include "customgui_matassign.h"  
            
            BaseMaterial *mat = doc->GetActiveMaterial();  
            if(!mat) return TRUE;  
            
            GeData d;  
            if(mat->GetParameter(DescLevel(ID_MATERIALASSIGNMENTS), d, DESCFLAGS_GET_0))  
            {  
                 MatAssignData *mad = (MatAssignData* )d.GetCustomDataType(CUSTOMDATATYPE_MATASSIGN);  
            
                 LONG count = mad->GetObjectCount();  //The number of objects assigned this material  
                 for(LONG i=0; i<count ; i++)  
                 {  
                     BaseTag *tag = (BaseTag* )mad->ObjectFromIndex(doc,i);  //Gets the tag that's on the object  
                     BaseObject *obj = tag->GetObject();                    //Gets the object the texture tag is attached to  
                     String objName = obj->GetName();                       //Gets the names of the objects in the material's Assignment list  
                     GePrint(objName);  
                 }  
            }
          

          -ScottA

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

            On 09/11/2013 at 13:22, xxxxxxxx wrote:

            @ScottA,

            stupid Me, yes that the way to solve it.
            But according to sdk, ObjectFromIndex(doc,i)  must return object list no tag list.

            So Thanks a lot for submitting your solution.

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

              On 11/11/2013 at 19:18, xxxxxxxx wrote:

              Thanks for the help guys! This got me what I needed. Also I found out this is the same code that you should use to get any data from an inexclusion list.

              Thanks again!

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

                On 27/02/2017 at 08:41, xxxxxxxx wrote:

                I need the same thing in XPresso(python node). I am new in python.
                I need to get a list of objects from the assignment tab of a material.

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

                  On 28/02/2017 at 02:12, xxxxxxxx wrote:

                  Originally posted by xxxxxxxx

                  I need the same thing in XPresso(python node). I am new in python.
                  I need to get a list of objects from the assignment tab of a material.

                  Hi and Welcome to the forums!

                  Why do you need to access a material assignment from a Python XPresso node?
                  It's not recommended to change the active document from such a node.
                  A Python XPresso node should only manipulate its input data to produce its output(s).

                  Please create a new topic if you have more questions.

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