Velocity plugin (craher)
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/03/2008 at 08:13, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10.5
Platform:
Language(s) : C.O.F.F.E.E ;---------
I pulled this plugin out of a larger plugin I'm making. The plug is made to measure velocity. When you click "Check Velocity" a null and a text spline are created. The null is then animated or placed under some animated object. Then "CALC VELOC" is clicked and the velocity is displayed in the text spline and the plugin window. The time between velocity calculations is set in the "Time Divisions" field. I don't understand why I have to hit enter to set this value even though there is an Init value? My second problem is that pressing enter keeps calling the "Check Velocity" command. My third and most concerning problem is that this plugin crashes Cinema... not initially, but when I start adjusting time divisions and playing with my time scrubber.. PS enter 0 in "time Divisions" to stop the Timer().
const var cPlugName = "velocity1";
const var cPlugHelp = "Calculate velocity";
const var cB8 = "";
const var cB16 = "Check Velocity";
const var cB17 = "CALC VELOC";
const var cB18 = "Time Divisions";
enum
{
eBut,eWriteVeloc,eCalcVeloc,eTimeDiv,eVelDisplay,eStopVCheck
}
const var cPluginID = 2000015;
var gDial;
var sObj,vtObj,mnObj,cvObj,sDoc,VText;
var vtbc,txt,txtw,nulpos1,nulpos2,vdiff,len,timediv,timedivR,vel,mg1,mg2,p1,p2;
var txtone,txtst,point;class VelText
{
public:
WriteVel(sDoc);
MakeNull(sDoc);
CalcVel();
Timer(msg);
}
VelText::WriteVel(sDoc)
{
vtObj=AllocObject(Osplinetext);
vtObj->SetName("Velocity");
sDoc->StartUndo();
sDoc->AddUndo(UNDO_OBJECT_NEW,vtObj);
sDoc->EndUndo();
sDoc->InsertObject(vtObj,NULL,NULL);
println("got here");
EventAdd();
return;
}
VelText::MakeNull(sDoc)
{
mnObj=AllocObject(Onull);
mnObj->SetName("Velocity Tracker");
sDoc->StartUndo();
sDoc->AddUndo(UNDO_OBJECT_NEW,mnObj);
sDoc->EndUndo();
nulpos1=mnObj->GetPosition();
nulpos2=mnObj->GetPosition();
mg1=mnObj->GetMg();
mg2=mnObj->GetMg();
p1=mg1->GetV0();
p2=mg2->GetV0();
sDoc->InsertObject(mnObj,NULL,NULL);
EventAdd();
return mnObj;
}
VelText::CalcVel()
{
var period="."[0];
nulpos2=mnObj->GetPosition();
mg2=mnObj->GetMg();
p2=mg2->GetV0();
vdiff=p2-p1;
len=vlen(vdiff);
vel=len*1000/timedivR;
txtone=vel;
txtst=tostring(txtone);
point=strchr(txtst,period);
txtw=strmid(txtst,0,point+2);
vtbc=vtObj->GetContainer();
txt=vtbc->GetData(PRIM_text_text);
vtbc->SetData(PRIM_text_text,tostring(txtw));
vtObj->SetContainer(vtbc);
//sDoc->InsertObject(vtObj,NULL,NULL);
vtObj->Message(MSG_UPDATE);
gDial->VelDisp(txtw);
EventAdd();
nulpos1=mnObj->GetPosition();
mg1=mnObj->GetMg();
p1=mg1->GetV0();
return;
}
class oDialog : GeDialog
{
public:
oDialog();
CreateLayout();
Init();
Command(vID,vMSG);
WriteVeloc();
CalcVel();
Timer(msg);
VelDisp(txtw);
}
oDialog::oDialog() { super(cPluginID); }
oDialog::CreateLayout()
{
SetTitle(cPlugName);
AddUserArea(5000,BFH_SCALEFIT|BFH_SCALEFIT,0,0);
AddGroupBeginV(eBut,BFH_CENTER,2,"",0);
{
AddButton(eCalcVeloc,0,150,0,cB17);
AddButton(eWriteVeloc,0,150,0,cB16);
AddStaticText(eVelDisplay,BFH_CENTER,0,0,txtw,0);
AddStaticText(0,BFH_CENTER,0,0,cB18,0);
AddStaticText(0,BFH_CENTER,0,0,cB8,0);
AddEditNumberArrows(eTimeDiv,BFH_RIGHT,150,16);
}
AddGroupEnd();
return TRUE;
}
oDialog::Init()
{
SetFloat(eTimeDiv,.2,0,360,.01);
return;
}
oDialog::VelDisp(txtw)
{
SetString(eVelDisplay,tostring(txtw));
return;
}
oDialog::WriteVeloc()
{
sDoc=GetActiveDocument();
if(!sDoc) return FALSE;
VText=new(VelText);
VText->WriteVel(sDoc);
//if(!vtObj) return FALSE;
mnObj=VText->MakeNull(sDoc);
if(!mnObj) return FALSE;
//return;
}
oDialog::CalcVel()
{
timedivR=timediv*1000;
SetTimer(timedivR);
return;
}
oDialog::Timer(msg)
{
VText->CalcVel();
return;
}
oDialog::Command(vID,vMSG)
{
switch (vID)
{
case eWriteVeloc: WriteVeloc();break;
case eCalcVeloc: CalcVel();break;
case eTimeDiv: timediv=GetFloat(vID);break;
case eStopVCheck: CalcVel();break;
}
return TRUE;
}// --- MenuPlugin
class oMenuPlugin : MenuPlugin
{
public:
oMenuPlugin();
GetID();
GetName();
GetHelp();
Execute(doc);
RestoreLayout(secret);
}
oMenuPlugin::oMenuPlugin() { super(); }
oMenuPlugin::GetID() { return cPluginID; }
oMenuPlugin::GetName() { return cPlugName; }
oMenuPlugin::GetHelp() { return cPlugHelp; }
oMenuPlugin::Execute(doc)
{
if (!gDial) gDial=new(oDialog);
gDial->Open(TRUE,-1,-1);
}
oMenuPlugin::RestoreLayout(secret)
{
if (!gDial) gDial=new(oDialog);
gDial->RestoreLayout(secret);
}
main()
{
Register(oMenuPlugin);
txtw="TREES";
} -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/03/2008 at 12:14, xxxxxxxx wrote:
I found the cause of why when I hit enter after clicking in text fields or blank areas that the write velocity function was being called::: I didn't give my enums any values. I set eBut=1000; and that problem went away. I still get crashes sometimes. and I still don't understand why eventhough I set the value of eTimeDiv in Init() it gets sent as NULL unless I click in the text field and hit enter.