On 04/06/2013 at 06:04, xxxxxxxx wrote:
I want to open a texture in my scene.
Looking at the interface, you click Open Texture and then a standard file dialog opens and you can select a file. I want to do this 'automatically'. I already have the filename.
I can simulate OpenTexture using CallCommand or CallButton, but I do not know the ID's for the different dialog fields (to simulate) : "File Name" and "Open".
Are the ID''s part of a OpenTexture DLG or the standard file dialog. If so, which Tool to use for the CallButton?
So something like this
OpenTexture_ID=170001 # Open Texture...
OpenTexture=c4d.plugins.FindPlugin(OpenTexture_ID, c4d.PLUGINTYPE_ANY)
c4d.CallButton(OpenTexture,set filename)
c4d.CallButton(OpenTexture,Open)
Here the complete code of what I''m trying to do.
import c4d, os
from c4d import bitmaps, gui, plugins, utils
### Open Texture ###
PLUGIN_ID = 14500219 #TestID only!!!!!!!!!!!!
GROUPBUTTON = 1030
MY_OPENBUTTON = GROUPBUTTON + 1
def OpenTexture() :
texturename = "studio003.hdr"
#c4d.CallCommand(170001) # Open Texture...
OpenTexture_ID=170001
OpenTexture=c4d.plugins.FindPlugin(OpenTexture_ID, c4d.PLUGINTYPE_ANY)
print "OpenTexture tool: ", OpenTexture
#c4d.CallButton(OpenTexture,c4d.IDS_RM_M_OPENFILE)
#FilesTool_ID=465001626
#FilesTool=c4d.plugins.FindPlugin(FilesTool_ID, c4d.PLUGINTYPE_ANY)
#print "FilesTool: ", FilesTool
#c4d.CallButton(FilesTool,c4d.IDS_RM_M_OPENFILE)
return True
class MyDialog(gui.GeDialog) :
def CreateLayout(self) :
self.SetTitle("Open Texture.")
self.AddButton(MY_OPENBUTTON, flags=c4d.BFH_LEFT, initw=150, name="Open Texture")
return True
def Command(self, id, msg) :
if (id == MY_OPENBUTTON) :
OpenTexture()
return True
return True
class MyOpenTexture(plugins.CommandData) :
dialog = None
def Execute(self, doc) :
if self.dialog is None: self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=200)
def RestoreLayout(self, sec_ref) :
if self.dialog is None: self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
pluginstr = "Open Texture v01"
bmp = bitmaps.BaseBitmap()
dir, f = os.path.split(__file__)
fn = os.path.join(dir, "res/icons", "IconChar.tif")
bmp.InitWith(fn)
plugins.RegisterCommandPlugin(id=PLUGIN_ID,
str=pluginstr,
info=0,
help=pluginstr,
dat=MyOpenTexture(),
icon=bmp)