选择瓶盖位置,可以自动标注一个带箭头的符号到瓶盖。
//创建符号
int UserSymbolCreate(ProDrawing drawing,ProName sym_name,ProVector pos)
{
ProError status;
ProDtlsymdef symdef;
ProDtlsyminstdata sym_data;
ProDtlsyminst sym_inst;
ProDtlattach attach;
ProDtlvartext vartext;
ProPath sym_def_path;
ProLine var_text_prompt;
ProLine var_text_replace;
ProStringToWstring(sym_def_path,"C:\\Users\\Public\\Documents\\symbol");
ProStringToWstring(var_text_prompt,"CAP");
status=ProDrawingDtlsymdefRetrieve(drawing,sym_def_path,sym_name,PRO_VALUE_UNUSED,PRO_B_TRUE,&symdef);
//分配data
status=ProDtlsyminstdataAlloc(drawing,&sym_data);
status=ProDtlsyminstdataDefSet(sym_data,&symdef);
//分配attach
status=ProDtlattachAlloc(PRO_DTLATTACHTYPE_FREE,NULL,pos,NULL,&attach);
status=ProDtlsyminstdataAttachtypeSet(sym_data,PROSYMDEFATTACHTYPE_FREE);
status=ProDtlsyminstdataAttachmentSet(sym_data,attach);
//分配text
status=ProDtlvartextAlloc(var_text_prompt,var_text_replace,&vartext);
status=ProDtlsyminstdataVartextAdd(sym_data,vartext);
//创建该符号
status=ProDtlsyminstCreate(drawing,sym_data,&sym_inst);
status=ProDtlsyminstShow(&sym_inst);
ProDtlattachFree(attach);
ProDtlvartextFree(vartext);
ProDtlsyminstdataFree(sym_data);
return PRO_TK_NO_ERROR;
}
ProError SymbolMenuAction()
{
ProError status;
ProMdl drawing;
ProVector pos;
ProMouseButton button;
ProName sym_name,name;
ProStringToWstring(sym_name,"symbol");
int pid;
status=ProWindowCurrentGet(&pid);
status=ProMdlCurrentGet(&drawing);
if (status!=PRO_TK_NO_ERROR)
{
return status;
}
status=ProMdlNameGet(drawing,name);
if (status!=NULL)
{
return status;
}
status=ProMdlInit(name,PRO_MDL_DRAWING,&drawing);
if (status!=NULL)
{
return status;
}
status=ProMessageDisplay(L"MESSAGE.txt","user pick the symbol position");
if (ProMousePickGet(PRO_ANY_BUTTON,&button,pos)!=PRO_TK_NO_ERROR)
{
return status;
}
UserSymbolCreate((ProDrawing)drawing,sym_name,pos);
ProWindowActivate(pid);
return PRO_TK_NO_ERROR;
}
void CPart2DDlg::OnBnClickedBtnSymbolAdd()
{
// TODO: 在此添加控件通知处理程序代码
ProError err;
ProDrawing drawing=NULL;
ProMouseButton button_pressed;
ProVector position;
ProModelitem modelitem;
ProSelection* sel;
int n_sel;
//获取当前模型
err=ProMdlCurrentGet((ProMdl*)&drawing);
if (err!=PRO_TK_NO_ERROR)
{
return;
}
//获取用户单击鼠标后获得的坐标位置(即符号将要放置的位置)
if (ProMousePickGet(PRO_ANY_BUTTON,&button_pressed,position)!=PRO_TK_NO_ERROR)
{
return;
}
//选择一个对象(符号所依附的对象)
err=ProSelect((char*)"feature",1,NULL,NULL,NULL,NULL,&sel,&n_sel);
if (err!=PRO_TK_NO_ERROR||n_sel<1)
{
return;
}
//从所选对象中获取模型项
err=ProSelectionModelitemGet(sel[0],&modelitem);
if (err!=PRO_TK_NO_ERROR)
{
return;
}
SymbolMenuAction();
}