Get BaseObject from Linkbox

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/02/2012 at 06:56, xxxxxxxx wrote:

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

---------
I'm trying to get BaseObject(s) from Linkbox of plugin.

Using ResEdit plugin I've made a dialog which has two linkboxes so that I can drag two different objects into them to make a plugin that enables to swap their positions.

For example,

ID of each linkbox : IDC_OBJECT1, IDC_OBJECT2

Members: 
     BaseObject* op1, op2;
     LinkBoxGui* linkbox1;
     LinkBoxGui* linkbox2;

I tried as following:
     linkbox1 = (LinkBoxGui* )FindCustomGui(IDC_OBJECT1, CUSTOMGUI_LINKBOX);

However I don't know how to get the BaseObject from linkbox.
    op1 = ....?

Or is there another way to do this?

Thank you in advance. 🙂

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/02/2012 at 08:15, xxxxxxxx wrote:

Hi,

You can call LinkBoxGui::GetLink() and cast the returned object to a BaseObject:

BaseObject* op = (BaseObject* )linkbox->GetLink(GetActiveDocument(), Xlayer);

This line is from the LayerShaderBrowser example.

Regards,

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/02/2012 at 18:04, xxxxxxxx wrote:

Yannick Puech,  thank you for your answer.

I tried as you guided, but I have still problems.

In my opinion, the problems is caused by the second parameter of GetLink function, Xlayer,  corresponds only for shader instances.

C++ HTML documentation reads:

[BaseList2D](file:///F:/ComputerGraphics/REFERENCES/C4D_SDK/C4DR13SDKHTML20110930/help/pages/c4d_baselist/class_BaseList2D66.html)* GetLink(const [BaseDocument](file:///F:/ComputerGraphics/REFERENCES/C4D_SDK/C4DR13SDKHTML20110930/help/pages/c4d_basedocument/class_BaseDocument59.html)* doc, LONG instance)_<_h4_>_

However, I don't know what I have to put the second parameter, LONG instance, to get the BaseObject instance.

My dialogbox, header files and cpp file look like this:

Dialogbox: http://blog.naver.com/gchoi_acts/130130991792

//==================================
// c4d_symbols.h
//==================================
enum
{
  // Dialog definitions of IDD_SWAP_POSITION start here
  IDD_SWAP_POSITION, // ID of the Dialog Box
  IDC_OBJECT1, // ID of the first linkbox
  IDC_OBJECT2, // ID of the second linkbox
  // Dialog definitions of IDD_SWAP_POSITION end here

// End of symbol definition
  _DUMMY_ELEMENT_
};

//==================================
// SwapPosition.h
//==================================
#include "c4d_gui.h"
class SwapPosition : public GeDialog
{
public:
SwapPosition ();
virtual ~SwapPosition ();

virtual Bool CreateLayout(void);
virtual Bool InitValues(void);
virtual Bool Command(LONG id, const BaseContainer &msg);
virtual LONG Message(const BaseContainer& msg, BaseContainer& result);


void UpdateAll(Bool msg);


void \*lastselected;

private:
LONG lastdirty;
BaseDocument* doc;
BaseObject* op1, op2;
LinkBoxGui* linkbox1, linkbox2;
};

//==================================
// SwapPosition.cpp
//==================================
#include "c4d.h"
#include "c4d_symbols.h"
#include "SwapPosition.h"
...
Bool SwapPosition ::Command(LONG id, const BaseContainer &msg)
{
//## GET USER ENTERED DATA:
switch (id)
{
case IDC_OK:
linkbox1 = (LinkBoxGui* )FindCustomGui(IDC_OBJECT1, CUSTOMGUI_LINKBOX);
if(!linkbox1) return FALSE;
op1 = (BaseObject* )linkbox1->GetLink(GetActiveDocument(), Xlayer);

	linkbox2 = (LinkBoxGui\* )FindCustomGui(IDC_OBJECT2, CUSTOMGUI_LINKBOX);
	if(!linkbox2) return FALSE;
	op2 = (BaseObject\* )linkbox2->GetLink(GetActiveDocument(), Xlayer);


	GePrint("Object Name : " + op1->GetName());  // <======= ERROR OCCURRED
	GePrint("Object Name : " + op2->GetName());  // <======= ERROR OCCURRED
	break;
case IDC_CANCEL:
	break;
default:
	break;
}


return TRUE;

}
...

================================
Thank you for your answer in adavance.

Best regards,
gchoi

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/02/2012 at 18:48, xxxxxxxx wrote:

Try Obase.
If that works. There are other types listed under: OObjectType
Just in case you need to use them some day.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/02/2012 at 19:57, xxxxxxxx wrote:

Thank you for your reply, ScottA.

I've just solved my problem by omitting the second parameter of the membert  function, GetLink and the code looks like this:

//===================================================
// SwapPosition.cpp
//===================================================

...

Bool SwapPosition ::Command(LONG id, const BaseContainer &msg)
{
//## GET USER ENTERED DATA:
switch (id)
{
case IDC_OK:
linkbox1 = (LinkBoxGui* )FindCustomGui(IDC_OBJECT1, CUSTOMGUI_LINKBOX);
if(!linkbox1) return FALSE;
op1 = (BaseObject* )linkbox1->GetLink(GetActiveDocument());
if(!op1) return FALSE;

	linkbox2 = (LinkBoxGui\* )FindCustomGui(IDC_OBJECT2, CUSTOMGUI_LINKBOX);
	if(!linkbox2) return FALSE;
	op2 = (BaseObject\* )linkbox2->GetLink(GetActiveDocument());
	if(!op2) return FALSE;


	GePrint("Object Name : " + op1->GetName());
	GePrint("Object Name : " + op2->GetName());
	break;
case IDC_CANCEL:
	break;
default:
	break;
}


return TRUE;

}

...