Get path to textures?

  • On 16/09/2014 at 09:22, xxxxxxxx wrote:

    Hello mates.

    I am woundering how i can get the texture path(s) & filename(s) from the selected material.
    im trying to return a list containing the path+filename foreach channel in the material.
    Anyone got an idea how i can do this ?


    will only reurn the filename, but i need full path + filename
    i tried my luck on c4dcafe, but no one seems to know this.


  • On 16/09/2014 at 09:58, xxxxxxxx wrote:

    You will have to get the document path and add it to your filename. This should do what you want.

    dPath = doc.GetDocumentPath()
    print (dPath+"	ex"+filename)

  • On 16/09/2014 at 10:50, xxxxxxxx wrote:

    Hi and thanks for your reply.
    however im not getting that to work. it only errors on me with.

    NameError: global name 'doc' is not defined

    This is my plugin code.

    import c4d  
    import os  
    from c4d import documents, gui, plugins, bitmaps  
    PLUGIN_ID = 1011310  
    class MyDialog(gui.GeDialog) :  
       def CreateLayout(self) :  
         self.SetTitle("My Plugin")  
         self.GroupBegin(id=1013,  flags=c4d.BFH_SCALEFIT,cols=2, title="Texture")  
         self.GroupBorderSpace(10, 15 ,10 , 5 )  
         self.AddStaticText(id=1003, flags=c4d.BFH_LEFT, name=" Drag the Material here:")  
         self.linkbox = self.AddCustomGui(3000, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT,0 ,0)  
         self.GroupBegin(id=1013,  flags=c4d.BFH_SCALEFIT,cols=1, title="Channels")          
         self.GroupBorderSpace(10, 15 ,10 , 5 )          
         self.AddCheckbox(2001, c4d.BFH_LEFT, 0, 0, 'Color Channel')  
         self.AddCheckbox(2002, c4d.BFH_LEFT, 0, 0, 'Specular Channel')  
         self.AddCheckbox(2003, c4d.BFH_LEFT, 0, 0, 'Normal Channel')  
         return True  
      def Command(self, id, msg) :  
          # Check if its the id of the link box  
          if id == 3000:  
              tex = self.linkbox.GetLink()  
              # check if the link box obj is a material  
              if tex is None or tex.GetType() != 5703:  
                  gui.MessageDialog("No Texture selected")  
                  return -1  
                  filename = tex[c4d.MATERIAL_COLOR_SHADER][c4d.BITMAPSHADER_FILENAME]  
                  #dPath = doc.GetDocumentPath()  
          return True  
    class MyPlugin(plugins.CommandData) :  
      dialog = None  
      def Execute(self, doc) :  
          # Create main dialog  
          if self.dialog is None:  
              self.dialog = MyDialog()  
          return self.dialog.Open( dlgtype = c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=450, defaulth=200, xpos=-1, ypos=-1)  
    if __name__ == "__main__":  
      path, fn = os.path.split(__file__)  
      bmp = bitmaps.BaseBitmap()  
      bmp.InitWith(os.path.join(path, "res/icons", "icon.tif"))  
      okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "MY Plugin", 0, bmp , "OSM", MyPlugin())  
      if okyn:  
          print "MyPlugin started"   

    i got it to work. i had to include this.

    doc = c4d.documents.GetActiveDocument()  
    dPath = doc.GetDocumentPath()  

    Altho i dont like this method since one have to know the name of the texture dir.
    Making the plugin useless on projects where textures are not saved in a common dir, Ie: tex

    but anyway. thanks for your help

Log in to reply