Getting image filename



  • On 12/12/2013 at 08:36, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R15 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    I have defined a FilenameCustomGui to get the image filename.
    Then I drag & drop a image to the field.

        BaseContainer settings;
        settings.SetBool(FILENAME_TEXTURE, true);	
        myHdrfile = (FilenameCustomGui* )AddCustomGui(1009, CUSTOMGUI_FILENAME, "", BFH_SCALEFIT, 0, 0, settings);
    

    Then in the message part, I get the id and try to get the filename, but it is always empty?
    The first part show how it is done in python (and working).
    Also how to put the filename back into the FilenameCustomGui field?

    Int32 MainDialog::Message(const BaseContainer& msg, BaseContainer& result)
    {
      
      // working python code
        //    def Message(self, msg, result) :             #get filename drag&drop to MY_HDRFILE field
        //
        //    #print "Message id: ", msg.GetId()
        //    if (msg.GetId() == c4d.BFM_ACTION) :
        //        cid = msg[c4d.BFM_ACTION_ID]
        //        val = msg[c4d.BFM_ACTION_VALUE]
        //        #print 'Msg ID:', cid, ' Val:', val
        //        if (cid == MY_HDRFILE) : self.SetString(cid, val)
        //    return gui.GeDialog.Message(self, msg, result) 
      
    	switch (msg.GetId())
    	{
    		case BFM_ACTION:
    			Int32 actionId = msg.GetInt32(BFM_ACTION_ID);
      
    			//BaseContainer    action(BFM_ACTION);
    			//String val = msg(action).GetString(BFM_ACTION_VALUE);
      
    			String val = msg.GetString(1009, "ABC");
    			GePrint ("Action ID + value: " + String::IntToString(actionId) + " - " + val);
      
    			break;
    	}
    	return GeDialog::Message(msg, result);
    }
    


  • On 12/12/2013 at 12:30, xxxxxxxx wrote:

    Hi Pim,

    your C++ code does not equal your Python code in its semantics.

    > if (msg.GetLong(BFM_ACTION_ID) == 1009) {
    >
    >     String val = msg.GetString(BFM_ACTION_VALUE);
    >
    >     SetString(1009, val);
    >
    > }

    Though, I don't understand why you would want to do that? The message is triggered when
    the value of the field changes, you don't have to update the value of the field using SetString()
    by yourself.

    Best,
    -Niklas



  • On 12/12/2013 at 14:07, xxxxxxxx wrote:

    Hi Niklas,

    Sorry, I think I was not clear enough.
    Because I drag a hdri file from a lib to the GUI field, it is not recognized by the FilenameCustomGui.
    Only when you select a file by using file selection button you get the filename using the FilenameCustomGui. So not when using drag & drop.
    That is why I use MainDialog::Message to get the value. MainDialog::Message recognizes drag&drop and returns the filename. 
    At least it does in python. In c++ I always get an empty filename?

    Here the complete code.

      
    #include "c4d.h"
    #include "c4d_symbols.h"
    #include "c4d_file.h"
    #include "c4d_painter.h"
    #include "customgui_filename.h"
      
    #define ID_PIM 10009561
      
    class MainDialog : public GeDialog
    {
    private:
    	FilenameCustomGui*  myHdrfile;
      
    public:
    	MainDialog(void);
    	virtual ~MainDialog(void);
      
    	virtual Bool CreateLayout(void);
    	virtual Bool InitValues(void);
    	virtual Bool Command(Int32 id, const BaseContainer& msg);
    	virtual Int32 Message(const BaseContainer& msg, BaseContainer& result);
    };
      
    MainDialog::MainDialog(void)
    {
    	//lastdlg = nullptr;
    }
      
    MainDialog::~MainDialog(void)
    {
    }
      
    Bool MainDialog::CreateLayout(void)
    {
    	GroupBegin(3001, BFH_SCALEFIT, 1, 0, "On/Off", 0,0,0);
    	BaseContainer settings;
        settings.SetBool(FILENAME_TEXTURE, true);	
        myHdrfile = (FilenameCustomGui* )AddCustomGui(1009, CUSTOMGUI_FILENAME, "", BFH_SCALEFIT, 0, 0, settings);
    	GroupEnd();
    	return true;
    }
      
    Bool MainDialog::InitValues(void)
    {
    	return true;
    }
      
    Bool MainDialog::Command(Int32 id, const BaseContainer& msg)
    {
    	switch (id)
    	{
    		case 1009:		//Give hdri link when file selection button is used!
    		{
    			Filename fn;
    			String hdrName;
    			fn = myHdrfile->GetData().GetValue().GetFilename();
      
    			hdrName = fn.GetFileString();
    			GePrint ("Given file: " + hdrName);
    			break;
    		}
      
    	}
    	return true;
    }
      
    Int32 MainDialog::Message(const BaseContainer& msg, BaseContainer& result)
    {
    	switch (msg.GetId())
    	{
    		case BFM_ACTION:
      
    			if (msg.GetInt32(BFM_ACTION_ID) == 1009)	//Give hdri link when drag&drop is used!
    			{
    				String val = msg.GetString(BFM_ACTION_VALUE);	//always returns empty
    				GePrint ("Action value: " + val);
    				//SetString(1009, val);
    			}
    			break;
    	}
    	return GeDialog::Message(msg, result);
    }
      
    class MyPlugin : public CommandData
    {
    private:
    	MainDialog dlg;
      
    public:
    	virtual Bool Execute(BaseDocument* doc);
    	virtual Bool RestoreLayout(void* secret);
    };
      
    Bool MyPlugin::Execute(BaseDocument* doc)
    {
    	return dlg.Open(DLG_TYPE_ASYNC, ID_PIM, -1, -1); 
    }
      
    Bool MyPlugin::RestoreLayout(void* secret)
    {
    	return dlg.RestoreLayout(ID_PIM, 0, secret);
    }
      
    Bool RegisterMyPlugin(void)
    {
    	// be sure to use a unique ID obtained from www.plugincafe.com
    	return RegisterCommandPlugin(ID_PIM, "Pim", 0, AutoBitmap("icon.tif"), String("Pim 1e"), NewObjClear(MyPlugin));
    }
      
    
    


  • On 13/12/2013 at 09:05, xxxxxxxx wrote:

    The data in your customgui gizmo is a Filename type of data.
    So when you request the BFM_ACTION_VALUE in your Message() method. You have to request a Filename type...Not a String type.
    That's why it's not  returning anything.

    Once you have the Filename value. Then you can convert it to a string value
    Give this code a try in your Message() method:

        if(msg.GetId() == BFM_ACTION)   
      {  
          Filename fn = msg.GetFilename(BFM_ACTION_VALUE);  
          String hdrName = fn.GetFileString();  
          GePrint(hdrName);       
      }
    

    -ScottA



  • On 13/12/2013 at 11:39, xxxxxxxx wrote:

    Yes, great, thanks a lot.
    I am beginning to like c++, although there is still a lot to learn.


Log in to reply