PDA

View Full Version : How to add attributes to a Tag plugin?


Scott Ayers
09-07-2010, 07:19 PM
Hey Guys,

Using Coffee.
I know how to create dialogs and add attributes (sliders,check boxes, text,etc.) to them for menu plugins. But I can't figure out how to add attributes to tags for tag plug-ins.
I've looked through all of the SDK stuff. But I can't find any examples of how to add custom attributes to the tags themselves.
I think I have to use a BaseContainer in my Edit function. But without seeing an example I'm not really sure if that's right, or how exactly to do it.

Here's a very simple tag plugin example that just turns on the xray attribute:
const var PLUGIN_ID = 12121212; //Just For testing purposes<----DO NOT DIRSTIBUTE THIS ID# publicly!!!

var tagIcon;

class xrayTag : ExpressionPluginTag // the XrayTag's class
{
public:
xrayTag();
GetID();

MultipleAllowed();
DisplayAllowed();

GetIcon();
GetHelpText();

UseMenu();
GetName();

Edit();

Execute(doc, op);
}

xrayTag::xrayTag()
{
// Call parent constructor
super();
}

xrayTag::GetID() { return PLUGIN_ID; }
xrayTag::MultipleAllowed() { return TRUE; }
xrayTag::DisplayAllowed() { return TRUE; }
xrayTag::GetIcon() { return tagIcon; }
xrayTag::GetHelpText() { return "Xray object example"; } // Bubble help text. If option is turned on in the preferences
xrayTag::UseMenu() { return TRUE; }
xrayTag::GetName() { return "XRay object"; } //The text displayed for the tag in the OM/ and lower right corner of UI


xrayTag::Edit()
{
var dlg = TextDialog("Drag the object upwards to see the result", DLG_OK);
}


xrayTag::Execute(doc, op)
{
var doc=GetActiveDocument();
if (!doc) return FALSE;
var obj = GetActiveObject(doc);
var pos = obj->GetPosition();
if(pos.y > 100)
{
obj#ID_BASEOBJECT_XRAY=TRUE;
}
else
{
obj#ID_BASEOBJECT_XRAY=FALSE;
}

EventAdd();
return;
}


/////////
// Main

main()
{
// Get the icon
var fn = GeGetRootFilename();
fn->RemoveLast();
fn->AddLast("xrayicon.tif");

tagIcon = new(BaseBitmap,1,1);
tagIcon->Load(fn);

// Registers the tag
Register(xrayTag);
}


Does anyone have a small example of doing this?
Feel free to edit the code I posted and insert an attribute, or two, for the tag. If that's more convenient.

-ScottA

georgedrakakis
09-09-2010, 11:47 AM
hi,
yesterday i was browsing xs-yann blog ( i talented cinema4d programmer)
and i bumped into this; interface examples (http://www.xsyann.com/?p=52)
i am not a programmer, so i can't tell if it suit's your case.
regards,
george

Scott Ayers
09-09-2010, 03:39 PM
Thanks George,
But those are dialog attribute examples. And I'm looking for a tag with attributes example.

There's tons of dialog examples floating around. But I can't find a single working tag example.
Where the tag has the custom attributes attached to it instead of a pop up dialog.

Basically I'm looking for something like a tag based version of the Rotateit example in the SDK.

tcastudios
09-09-2010, 03:48 PM
AFAIK, you can't add AM attributes to a coffee expression tag plugin.

btw, I see you noted that the ID is for test purposes only.
But be aware of that you can only use the test ID's
1000001 to 1000010 at any time even for yourself.
Any other un registered ID could possible corrupt you c4d files.

Cheers
Lennart

Scott Ayers
09-09-2010, 04:32 PM
Thanks Lennart.
I'm really bummed about not being able to add attributes to tags with Coffee.:sad:
I've seen people do it with python like this: class Rotator_Main(plugins.TagData):

def Init(self, tag): # Initializes the tag's elements and their ID's
tag[1001] = 0.0
tag[1002] = 0.0
tag[1003] = 0.0
return True

def Message(self, tag, type, data):
return True

def Draw(self, tag, op, bd, bh):
return False

def Execute(self, tag, doc, op, bt, priority, flags): # This code executes the task. Sort of like a script would do.
rot = op.GetRot()
rot.x += tag[1001] # Assign a variable to this UI element in the tag
rot.y += tag[1002] # Assign a variable to this UI element in the tag
rot.z += tag[1003] # Assign a variable to this UI element in the tag
op.SetRot(rot)
op.Message(c4d.MSG_UPDATE)
return 0

#def Free(self, tag):
#Code Here

So I had hoped that there was a Coffee equivalent for this.

-ScottA

CGTalk Moderation
09-09-2010, 04:32 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.