大家好,有偿咨询一个关于UF 创建部件的问题:
自己尝试通过UI block选择体创建部件,如果是在单个部件界面是可以创建部件成功,但是如果是在装配树件环境下创建部件始终不成功,很是困惑也找不到原因,想请教高手,感谢!
//这个函数是我自己尝试写的 可以实现在单一部件里面 选择体创建新部件 但是在装配树中设置工作部件却不能新建组件 也不报错 找不到原因
int creat_edit_attr::CreateNewComponentcd(std::vector<TaggedObject*> sheetbody, string strsheetname, tag_t &part_tag)
{
try
{
ListingWindow *lw=theSession->ListingWindow();
lw->Open();
NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());
// ----------------------------------------------
// Gets the file path and name
// ----------------------------------------------
//判断文件的路径
string m_filepath = workPart->FullPath().GetLocaleText();
string s = m_filepath;
std::size_t found1 = s.find_last_of("\\");
m_filepath = s.substr(0, found1 + 1);
string filename = m_filepath + strsheetname + ".prt";
// TODO: add your code here
UF_initialize();
size_t ui = sheetbody.size();
int iconut= static_cast<int>(ui);
const char* new_part_name = filename.c_str();
//推测错误开始位置
//是下面这几行代码对应通过UI block 选择体的tag 转uf tag 除了错误
tag_t * tagObjects = (tag_t *) malloc(iconut * sizeof(tag_t));
for (int i = 0; i < iconut; i++)
{
NXOpen::DisplayableObject *body1 = (NXOpen::DisplayableObject *)(NXOpen::NXObjectManager::Get(sheetbody[i]->Tag()));
tagObjects[i] = body1->Tag();
}
//推测错误结束位置
//新建组件
tag_t parent_part = UF_ASSEM_ask_work_part();
tag_t instance = NULL_TAG;
double origin [3] = { 0.0, 0.0, 0.0 };
double csys_matrix [6] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
int n_objects = iconut;
UF_ASSEM_create_component_part( parent_part,new_part_name, "MODEL", strsheetname.c_str(), 1, -1, origin, csys_matrix, n_objects, tagObjects, &instance );
UF_terminate();
return 1;
}
catch (exception& ex)
{
//---- Enter your exception handling code here -----
creat_edit_attr::theUI->NXMessageBox()->Show("CD创建部件错误提示", NXOpen::NXMessageBox::DialogTypeError, ex.what());
return 0;
}
}