AnsweredAssumed Answered

Can we add attribute to temporary bodies?

Question asked by Mahadev Dharme on Sep 13, 2019

I have created one temporary body, and tried to add attribute to it. But CreateInstance5() method return null.

What is the problem? The code is as follow.

 

CComPtr<IModelDoc2> modelDoc;
SwApp->get_IActiveDoc2(&modelDoc);

CComPtr<IModeler> modler;
SwApp->IGetModeler(&modler);

 

double dblData[9];

// cone X Y Z Face Center
dblData[0] = 0;
dblData[1] = 0.3;
dblData[2] = 0;

// cone X Y Z Axis (rotation)
dblData[3] = 0;
dblData[4] = 0;
dblData[5] = 1;

// cone Base Radius , cone Top Radius, cone Height
dblData[6] = 0.2;
dblData[7] = 0;
dblData[8] = 0.3;

 

CComPtr<IBody2> swBody;
modler->ICreateBodyFromCone2(dblData, &swBody);

 

long retVal;
CComPtr<IDispatch> swBodyDisp(swBody);
swBody->Display3(modelDoc, RGB(0, 0, 255), swTempBodySelectOptions_e::swTempBodySelectOptionNone, &retVal);

 

VARIANT_BOOL retval1;
CComPtr<IAttributeDef> attributeDef;
SwApp->IDefineAttribute(L"TestAttributeTest", &attributeDef);
attributeDef->AddParameter(L"TestAttribute", swParamType_e::swParamTypeDouble, 2.0, 0, &retval1);

attributeDef->Register(&retval1);

 

CComPtr<IAttribute> attribute;
attributeDef->CreateInstance5(modelDoc, swBodyDisp, L"TestAttribute", 0, swInConfigurationOpts_e::swAllConfiguration, &attribute);

Outcomes