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
    • Recent
    • Tags
    • Users
    • Login

    Scaling 2d planes to their texture..

    Scheduled Pinned Locked Moved PYTHON Development
    15 Posts 0 Posters 1.1k 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 24/09/2014 at 11:26, xxxxxxxx wrote:

      i'll take a look at that tonight mate cheers..

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

        On 25/09/2014 at 01:09, xxxxxxxx wrote:

        I added the code to a python tag and Cinema said the code ran without problem, but nothing happened to the dimensions of the plane. Did i miss something obvious?

        here is the C4d file..

        http://www.doghouseanimations.com/resizing test code.zip

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

          On 25/09/2014 at 01:21, xxxxxxxx wrote:

          Just saw you edit fella.

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

            On 25/09/2014 at 07:51, xxxxxxxx wrote:

            at the end!

            There are several places where your bitmap can be fund, according to the state of your document (saved or not)or your choice while loading the picture(make a copy or not).
            This script should work in any case.
            Let me know if not.
            cheers
            Martin

              
            import c4d,os  
            from c4d import gui,bitmaps,storage  
            from c4d.modules.render import  InitRenderStruct  
              
              
              
            def main() :  
                
              if op==None:return  
              #not a plane primitive  
              if op.GetType()!=5168:return  
                
                
              doc = c4d.documents.GetActiveDocument()  
              
              if op.GetTag(c4d.Ttexture)== None:  
                  dialog=gui.MessageDialog("Please assign a material to the object",c4d.GEMB_OK)  
                  if dialog== 1:  
                      return  
              else:  
                  TexTag=op.GetTag(c4d.Ttexture)     
                     
              Mat= TexTag.GetMaterial()  
              Shader=Mat[c4d.MATERIAL_COLOR_SHADER]  
              if Shader.GetType() != c4d.Xbitmap:  
                  dialog=gui.MessageDialog("Please insert a picture",c4d.GEMB_OK)  
                  if dialog== 1:  
                      return  
                    
              bitmapPath = Shader[c4d.BITMAPSHADER_FILENAME]  
                
              #if bitmapPath is´nt absolute  
              if not os.path.dirname(bitmapPath) :  
                  #the document has´nt been saved already ->picture in user library  
                  if not doc.GetDocumentPath() :  
                      abspath= c4d.storage.GeGetStartupWritePath()+"/"+"tex"+"/"+bitmapPath  
                  #the picture should be inside the asset´s texture folder      
                  else:  
                      abspath= doc.GetDocumentPath()+"/"+"tex"+"/"+bitmapPath  
                        
              else:  
                  abspath = bitmapPath  
                    
              print abspath   
                   
              bmp = bitmaps.BaseBitmap()      
              if bmp.InitWith(abspath)[0]== c4d.IMAGERESULT_OK:  
                  if bmp != None:  
                      bmpsize     = bmp.GetSize()  
                        
                      op[c4d.PRIM_PLANE_WIDTH]=bmpsize[0]  
                      op[c4d.PRIM_PLANE_HEIGHT]=bmpsize[1]  
                        
                       
                      op.Message(c4d.MSG_UPDATE)  
                      #render the Bitmap if you like  
                      #bitmaps.ShowBitmap(bmp)  
                
              c4d.EventAdd()   
              
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 25/09/2014 at 17:31, xxxxxxxx wrote:

              Thanks for sticking in here with me.

              No joy. Maybe i'm doing something wrong. I dropped this code in a python tag on a plane object with a texture attached. Should that have worked?!

              Am i doing something wrong?

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

                On 25/09/2014 at 17:46, xxxxxxxx wrote:

                Yes, if you use a Python tag, than op is the Python tag and not the assigned object.
                You have to use obj= op.GetObject() instead.
                Have fun!
                Martin

                like:

                  
                import c4d,os  
                from c4d import gui,bitmaps,storage  
                  
                  
                  
                  
                def main() :  
                  obj= op.GetObject()  
                  print obj  
                  if obj==None:return  
                  #not a plane primitive  
                  if obj.GetType()!=5168:return  
                    
                    
                  doc = c4d.documents.GetActiveDocument()  
                  
                  if obj.GetTag(c4d.Ttexture)== None:  
                      dialog=gui.MessageDialog("Please assign a material to the object",c4d.GEMB_OK)  
                      if dialog== 1:  
                          return  
                  else:  
                      TexTag=obj.GetTag(c4d.Ttexture)     
                         
                  Mat= TexTag.GetMaterial()  
                  Shader=Mat[c4d.MATERIAL_COLOR_SHADER]  
                  print Shader  
                  if Shader.GetType() != c4d.Xbitmap:  
                      dialog=gui.MessageDialog("Please insert a picture",c4d.GEMB_OK)  
                      if dialog== 1:  
                          return  
                        
                  bitmapPath = Shader[c4d.BITMAPSHADER_FILENAME]  
                    
                  #if bitmapPath is´nt absolute  
                  if not os.path.dirname(bitmapPath) :  
                      #the document has´nt been saved already ->picture in user library  
                      if not doc.GetDocumentPath() :  
                          abspath= c4d.storage.GeGetStartupWritePath()+"/"+"tex"+"/"+bitmapPath  
                      #the picture should be inside the asset´s texture folder      
                      else:  
                          abspath= doc.GetDocumentPath()+"/"+"tex"+"/"+bitmapPath  
                            
                  else:  
                      abspath = bitmapPath  
                        
                  print abspath   
                       
                  bmp = bitmaps.BaseBitmap()      
                  if bmp.InitWith(abspath)[0]== c4d.IMAGERESULT_OK:  
                      if bmp != None:  
                          bmpsize     = bmp.GetSize()  
                            
                          obj[c4d.PRIM_PLANE_WIDTH]=bmpsize[0]  
                          obj[c4d.PRIM_PLANE_HEIGHT]=bmpsize[1]  
                            
                           
                          obj.Message(c4d.MSG_UPDATE)  
                          #render the Bitmap if you like  
                          #bitmaps.ShowBitmap(bmp)  
                  
                    
                if __name__=='__main__':  
                  main()  
                

                p.s.
                Don´t use EventAdd() than;)

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

                  On 28/09/2014 at 09:51, xxxxxxxx wrote:

                  I can't get this working, i'm going to try again tonight!?

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

                    On 28/09/2014 at 10:54, xxxxxxxx wrote:

                    Hi,

                    be sure to use a plane primitive!!

                    At the beginning of the script we exclude any other objects even a converted plane.

                    like

                        #not a plane primitive  
                      if obj.GetType()!=5168:return
                    

                    because at the end of the script we want to assign the bitmap size to the primitiv values.

                                obj[c4d.PRIM_PLANE_WIDTH]=bmpsize[0]  
                              obj[c4d.PRIM_PLANE_HEIGHT]=bmpsize[1]
                    

                    If this doesn´t work, post a scene file.

                    cheers
                    Martin

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

                      On 28/09/2014 at 16:34, xxxxxxxx wrote:

                      I've tried a couple of ways of applying the code but i can't get it working!?

                      I have been using a plane and i have tired many ways of applying the texture, still no joy.

                      http://www.doghouseanimations.com/resizing test code 3.zip

                      thanks again for your help..

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

                        On 28/09/2014 at 16:39, xxxxxxxx wrote:

                        sorry here is the hyperlink..

                        http://www.doghouseanimations.com/resizing test code 3.zip

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

                          On 28/09/2014 at 17:35, xxxxxxxx wrote:

                          ok,

                          you did not use a regular project structure.
                          The Bitmap is only inside the project folder, but not in a separate "tex" folder like cinema4d usually set it up by default.

                          just create a new folder inside your project folder, name it tex, drag the picture into it and open the scene. works fine!

                          or

                          open the scene and safe it again including the asset. works fine!

                          or

                          There is a Texture Manager inside cinema4d which shows you every path of every texture in your scene
                          Adapt the script to your special needs, if you like
                          Please try to understand those lines by searching the sdk.:

                          abspath= c4d.storage.GeGetStartupWritePath()+"/"+"tex"+"/"+bitmapPath
                          

                          and especially

                          abspath= doc.GetDocumentPath()+"/"+"tex"+"/"+bitmapPath
                          

                          I implemented a print statement for the abspath already, that you can read it in the console window.

                          cheers
                          Martin

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

                            On 28/09/2014 at 17:56, xxxxxxxx wrote:

                            That rocks, you are truly a superstar. I can't believe i missed that!

                            If your ever in Amsterdam there is a beer with your name on it..

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

                              On 29/09/2014 at 06:53, xxxxxxxx wrote:

                              you´re welcome.

                              I still just stumble through the code.
                              But I´ll take you up on the beer.

                              cheers
                              Martin

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