ProMdlLoad加载模板
ProMdlCopy(m_TempleteModelAsm,asmName,&newModel);
//复制模板模型并给新模型赋名
随便给一个元件起始位置,起始位置并不重要因为其位置主要由后期约束来决定
ProMatrix identity_martrix={{1.0,0.0,0.0,0.0},
{0.0,1.0,0.0,0.0},
{0.0,0.0,1.0,0.0},
{0.0,0.0,0.0,1.0}};
//!<将零件添加到组件上
status = ProAsmcompAssemble(assembly,(ProSolid)newModel,identity_martrix,&asmcomp);
//!<初始化约束数组constraints
status = ProArrayAlloc(0,sizeof(ProAsmcompconstraint),1,(ProArray*)&constraints);
//!<初始化约束constraint
status = ProAsmcompconstraintAlloc(&constraint);
1.当为缺省装配时
因为时缺省所以添加一个约束信息就可以完全约束,并且该约束只需要设置其约束类型为缺省即可
status = ProAsmcompconstraintTypeSet(constraint,PRO_ASM_DEF_PLACEMENT);
将约束添加到约束数组中,
status = ProArrayObjectAdd((ProArray*)&constraints,-1,1,&constraint);
status = ProAsmcompConstraintsSet(NULL,&asmcomp,constraints);
2.当装配为坐标系时则需要获取装配子件与父件的坐标系并设置约束信息
其他装配方式大体与该方式相同
(1)根据名称加载坐标系
if(p_type == PRO_MDL_PART)
{
ProStringToWstring(compCsysName,"PRT_CSYS_DEF");
ASSERT_STATUS(status);
}
else
{
ProStringToWstring(compCsysName,"ASM_DEF_CSYS");
}
status = ProModelitemByNameInit ( newModel,PRO_CSYS,compCsysName,&compCsysitem);
也可以遍历特征获得坐标系
(2)获取零件坐标系selection
status = ProSelectionAlloc(NULL,&compCsysitem,&comp_sel);零件
(3)根据c_id_table获取装配父元件坐标系selection
status = ProAsmcomppathInit((ProSolid) parentModel,c_id_table,0,&asmpath);
如果获得组件模型则可以设c_id_table[0]=-1;
status = ProSelectionAlloc(&asmpath,&asmCsysitem,&asm_sel);//!< 组件坐标系
(4)//!<设置约束参照
ProAsmcompconstraintAsmreferenceSet ProAsmcompconstraintCompreferenceSet;
ProAsmcompconstraintTypeSet
ProArrayObjectAdd
ProAsmcompConstraintsSet
最后别忘了释放selection与约束
ProSelectionFree
ProAsmcompconstraintFree