PDA

View Full Version : Change tag(adding)


IlaySHP
07-14-2007, 05:31 PM
i try to make similar plug-in like Change Texture 1.0 by Aaron Matthew.
Change Texture is a simple menu plugin for modifying all texture tags pointing to a specific material to point to a different material.
But it not replace mat-s in model tree, it just add new tag to objects with identical mat-tags.
for example i don't want to add numerious tags(maxwell's tags - metall definition) to 100 objects with chrome-metal mat handly. can i make this automatic? :)
var PLUGIN_ID = 1002816;
var PLUGIN_NAME = "Change Texture";
var m1,m2;

ReplaceMaterial(op,ma1,ma2)
{
var tag,nam;
while (op)
{
nam = op->GetName();
// println(nam);
tag = op->GetFirstTag();
while (tag)
{
if (instanceof(tag,TextureTag))
{
// println(ma1);
if (ma1->IsEQ(tag->GetMaterial()))
{
tag->SetMaterial(ma2);
println("Replaced on: ",nam);
op->Message(MSG_UPDATE);
}
}
tag = tag->GetNext();
}
if (op->GetDown()) { ReplaceMaterial(op->GetDown(),ma1,ma2); }
op = op->GetNext();
}
GeEventAdd(DOCUMENT_CHANGED);
}

class MyDialog : GeModalDialog
{
public:
MyDialog();
CreateLayout();
Command(id,msg);
}
MyDialog::MyDialog() {super();}
MyDialog::CreateLayout()
{
SetTitle("Change Texture 1.0");
AddGroupBeginV(4000,BFH_FIT,2,"Group",0);
{
AddStaticText (4001,BFH_FIT,0,0,"Find Material:",0);
AddEditText (4002,BFH_FIT,160,0);
AddStaticText (4003,BFH_FIT,0,0,"Replace With:",0);
AddEditText (4004,BFH_FIT,160,0);
}
AddGroupEnd();

AddDlgGroup(DR_DLGGROUP_OK | DR_DLGGROUP_CANCEL);
return TRUE;
}
MyDialog::Command(id,msg)
{
switch (id)
{
case 4002: m1 = GetString(id); break;
case 4004: m2 = GetString(id); break;
}
}

class MyMenuPlugin : MenuPlugin
{
public:
MyMenuPlugin();
GetID();
GetHelp();
GetName();
Execute(doc);
}
MyMenuPlugin::MyMenuPlugin() { super(); }
MyMenuPlugin::GetID() { return PLUGIN_ID; }
MyMenuPlugin::GetName() { return PLUGIN_NAME; }
MyMenuPlugin::GetHelp() { return "Help"; }
MyMenuPlugin::Execute(doc)
{
m1 = m2 = "";
var mat1,mat2;
var d = new(MyDialog);
d->Open(-1,-1);
if (!d->GetResult()) { return FALSE; }
println("Replacing: ",m1," with ",m2);
mat1 = doc->FindMaterial(m1);
mat2 = doc->FindMaterial(m2);
if (mat1)
{
if (mat2)
{
var op = doc->GetFirstObject();
var ma1 = mat1->GetMarker();
var ma2 = mat2->GetMarker();
if (!op || !ma1 || !ma2) { return FALSE; }
ReplaceMaterial(op,ma1,ma2);
}
else { TextDialog("Cannot Find 'Replace With': "+m2); }
}
else { TextDialog("Cannot Find 'Find Material': "+m1); }
}

main()
{
Register(MyMenuPlugin);
}

Where can i read about tags in Cinema4D?

CGTalk Moderation
07-14-2007, 05:31 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.