测试代码
int CeShi::apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
UF_initialize();
char msg[99];
/////设置在制图中可见
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
Drawings::BaseView *baseView1(dynamic_cast<Drawings::BaseView *>(workPart->DraftingViews()->FindObject("TOP@1")));
std::vector<Layer::StateInfo> stateArray1(256);
stateArray1[0] = Layer::StateInfo(1, Layer::StateVisible);
stateArray1[1] = Layer::StateInfo(2, Layer::StateVisible);
stateArray1[2] = Layer::StateInfo(3, Layer::StateVisible);
//stateArray1[4] = Layer::StateInfo(5, Layer::StateVisible);
workPart->Layers()->SetObjectsVisibilityOnLayer(baseView1, stateArray1, true);
////////////////////
std::vector<Layer::StateInfo > stateArray2(256) ;
workPart->Layers()->GetVisibilitiesInView(workPart->DraftingViews()->FindObject("TOP@1"),stateArray2 );///Gets the visibility of all layers in a specified view.获得视图中图层的可见性
std::vector<Edge *> stass;
int layerX = stateArray2[9].Layer;
int layerS = stateArray2[4].State; //State { StateWorkLayer=0, StateSelectable=1, StateVisible=0, StateHidden=3 }
sprintf(msg,"%d",layerS);///这就得到了在制图中某个图层的可见与否。
uc1601(msg,1);
/*
/////测试属性
tag_t attrTag =NULL_TAG;
UF_ATTR_ask_part_attribute(&attrTag);
UF_ATTR_value_t value1;
value1.type = UF_ATTR_string;
value1.value.string = "a55bc";
UF_ATTR_assign(attrTag,"字符",value1);
/////测试表达式
//tag_t num1; //数量1
//UF_MODL_create_exp_tag("num_1=1",&num1);
//UF_MODL_edit_exp("num_1=110");
//UF_MODL_delete_exp("num_1");
///测试对象所在的图层
Session *theSession = Session::GetSession();
//Part *workPart(theSession->Parts()->Work());
Part* workPart;//定义工作部件
workPart = theSession->Parts()->Work();//获取工作部件
theSession->ListingWindow()->Open();
std::vector<int> BodyTagVector;//对象TAG容器
BodyTagVector.clear();
//遍历工作部件所有体的显示属性
BodyCollection* bodys = workPart->Bodies();
for(BodyCollection::iterator ite = bodys->begin(); ite != bodys->end(); ite++)
{
Body* bodys = (*ite);
BodyTagVector.push_back(bodys->Tag());
//获得对象信息
UF_OBJ_disp_props_s dispprops;
UF_OBJ_ask_display_properties(bodys->Tag(), &dispprops); //获取对象的显示属性(图层, 颜色, 隐藏状态, 线宽, 字体, 高亮状态)
sprintf(msg, "体的TAG: %d", bodys->Tag());
theSession->ListingWindow()->WriteLine(msg);
sprintf(msg, "体的图层:%d", dispprops.layer);
theSession->ListingWindow()->WriteLine(msg);
sprintf(msg, "体的颜色:%d", dispprops.color);
theSession->ListingWindow()->WriteLine(msg);
sprintf(msg, "体的隐藏状态:%d", dispprops.blank_status);
theSession->ListingWindow()->WriteLine(msg);
}
*/
UF_terminate();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
CeShi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}