UDF创建

#include #include using namespace std; #include #include #include #include #include #include #include #include // // UDF尺寸 // class UdfDim { public: string Name; double Value; ProUdfVardimType Type; UdfDim() { Name = ""; Value = 0.0; Type = PROUDFVARTYPE_DIM; } UdfDim(const string &name, const double &value, ProUdfVardimType type = PROUDFVARTYPE_DIM) { Name = name; Value = value; Type = type; } }; // // UDF參考 // class UdfRef { public: string Prompt; ProSelection RefItem; ProUdforientation Orientation; UdfRef() { Prompt = ""; RefItem = NULL; Orientation = PROUDFORIENT_NO_FLIP; } UdfRef(const string &prompt, const ProSelection refItem, ProUdforientation orientation = PROUDFORIENT_NO_FLIP) { Prompt = prompt; ProSelectionCopy(refItem, &RefItem); Orientation = orientation; } }; // // UDF數據 // class UdfData { public: string Name; string Path; ProSelection Owner; ProUdfdependency Dependency; ProUdfdimdisplay DimDisplay; vector Dims; vector Refs; UdfData() { Name = ""; Path = ""; Owner = NULL; Dependency = PROUDFDEPENDENCY_INDEPENDENT; DimDisplay = PROUDFDIMDISP_NORMAL; } void AddDim(const UdfDim &dim) { Dims.push_back(dim); } void AddRef(const UdfRef &ref) { Refs.push_back(ref); } }; // // 比較兩個ProAsmcomppath是否相等 // bool IsSameCmppath(const ProAsmcomppath &cmppath1, const ProAsmcomppath &cmppath2) { if (cmppath1.owner != cmppath2.owner) { return false; } if (cmppath1.table_num != cmppath2.table_num) { return false; } for (int i = 0; i < cmppath1.table_num; ++i) { if (cmppath1.comp_id_table[i] != cmppath2.comp_id_table[i]) { return false; } } return true; } // // 創建UDF // ProError CreateUdf(UdfData &udfData, ProGroup *udf, ProUdfCreateOption option = PROUDFOPT_FIX_MODEL_UI_OFF) { ProError status; int i = 0; char temp[PRO_NAME_SIZE]; // UDF所在的檔案路徑 ProAsmcomppath ownerCmppath; ProMdl owner; status = ProSelectionAsmcomppathGet(udfData.Owner, &ownerCmppath); if (status != PRO_TK_NO_ERROR) { return status; } // 準備UDF數據 ProUdfdata data; status = ProUdfdataAlloc(&data); if (status != PRO_TK_NO_ERROR) { return status; } ProName udfName; status = ProUdfdataNameSet(data, ProStringToWstring(udfName, strcpy(temp, udfData.Name.c_str())), NULL); status = ProUdfdataDependencySet(data, udfData.Dependency); status = ProUdfdataDimdisplaySet(data, udfData.DimDisplay); status = ProUdfdataScaleSet(data, PROUDFSCALETYPE_SAME_DIMS, 1.0); // UDF尺寸 ProName dimName; UdfDim udfDim; ProUdfvardim dim; for (i = 0; i < udfData.Dims.size(); ++i) { udfDim = udfData.Dims[i]; status = ProUdfvardimAlloc(ProStringToWstring(dimName, strcpy(temp, udfDim.Name.c_str())), udfDim.Value, udfDim.Type, &dim); status = ProUdfdataUdfvardimAdd(data, dim); } // UDF參考 ProName refPrompt; UdfRef udfRef; ProUdfreference ref; ProBoolean isExternal; ProAsmcomppath refCmppath; for (i = 0; i < udfData.Refs.size(); ++i) { udfRef = udfData.Refs[i]; // 根據ASMCOMPPATH判斷參考是否為外部參考 status = ProSelectionAsmcomppathGet(udfRef.RefItem, &refCmppath); if (status != PRO_TK_NO_ERROR) { return status; } if (IsSameCmppath(refCmppath, ownerCmppath)) { isExternal = PRO_B_FALSE; } else { isExternal = PRO_B_TRUE; } status = ProUdfreferenceAlloc(ProStringToWstring(refPrompt, strcpy(temp, udfRef.Prompt.c_str())), udfRef.RefItem, isExternal, &ref); status = ProUdfdataReferenceAdd(data, ref); status = ProUdfdataOrientationAdd(data, udfRef.Orientation); } // UDF路徑 // 如果沒有指定路徑,PRO/E將從UDF庫中查找UDF bool isPathChanged = false; ProPath currentPath; if (!udfData.Path.empty()) { isPathChanged = true; status = ProDirectoryCurrentGet(currentPath); ProPath udfPath; ProStringToWstring(udfPath, strcpy(temp, udfData.Path.c_str())); ProDirectoryChange(udfPath); } // UDF所在的檔案 ProModelitem mdlItem; status = ProSelectionModelitemGet(udfData.Owner, &mdlItem); if (status != PRO_TK_NO_ERROR) { return status; } status = ProModelitemMdlGet(&mdlItem, &owner); if (status != PRO_TK_NO_ERROR) { return status; } // 創建UDF status = ProUdfCreate((ProSolid)owner, data, &ownerCmppath, &option, 1, udf); if (isPathChanged) { ProDirectoryChange(currentPath); } if (status != PRO_TK_NO_ERROR) { return status; } return PRO_TK_NO_ERROR; } // // UDF測試 // ProError UdfTest() { ProError status; UdfData udfData; // UDF所在的檔案 ProSelection *asmSel; int asmSelCount; status = ProSelect("prt_or_asm", 1, NULL, NULL, NULL, NULL, &asmSel, &asmSelCount); if (status != PRO_TK_NO_ERROR || asmSelCount < 1) { return status; } // 注意: // 在PRO/E中只用調用了ProSelect,在下次調用ProSelect之前需要將選擇的東西用ProSelectionCopy // 複製出去,否則會被下次調用的ProSelect覆寫,導致系統異常 ProSelectionCopy(asmSel[0], &udfData.Owner); // UDF參考 ProSelection *csysSel; int csysSelCount; status = ProSelect("csys", 1, NULL, NULL, NULL, NULL, &csysSel, &csysSelCount); if (status != PRO_TK_NO_ERROR || csysSelCount < 1) { return status; } UdfRef udfRef("csys", csysSel[0]); udfData.AddRef(udfRef); // UDF尺寸 // 注意: // UDF尺寸在製作UDF時,UDF的尺寸必須正確的命名。 // PROMPT必須和DIM_NAME相同 UdfDim udfDim1("x", 5.0); udfData.AddDim(udfDim1); UdfDim udfDim2("y", 3.0); udfData.AddDim(udfDim2); UdfDim udfDim3("z", 0.0); udfData.AddDim(udfDim3); UdfDim udfDim4("x_dim", 10.0); udfData.AddDim(udfDim4); UdfDim udfDim5("y_dim", 20.0); udfData.AddDim(udfDim5); UdfDim udfDim6("x_num", 3, PROUDFVARTYPE_IPAR); udfData.AddDim(udfDim6); UdfDim udfDim7("y_num", 4, PROUDFVARTYPE_IPAR); udfData.AddDim(udfDim7); // UDF其他信息 udfData.Path = "D://PTC//Toolkit"; udfData.Name = "udf"; // 創建UDF ProGroup udf; status = CreateUdf(udfData, &udf); if (status != PRO_TK_NO_ERROR) { MessageBox(NULL, "UDF創建失敗", "失敗", MB_OK); } return PRO_TK_NO_ERROR; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值