#pragma once
#include <iostream>
#include <iostream>
#include <string>
#include <pfcAsyncConnection.h>
#include <pfcSession.h>
#include <pfcGlobal.h>
#include <Locale.h>
#include <wfcSession.h>
int main()
{
pfcAsyncConnection_ptr conn = pfcAsyncConnection::Connect("", "", "", 1);
if (conn == NULL)
{
throw "Asyn Connection pointer is NULL!";
}
pfcSession_ptr session = conn->GetSession();
session->UIShowMessageDialog("Asynchronous Mode Test!", NULL);
wfcWSession_ptr wSession = wfcWSession::cast(session);
pfcModel_ptr model = wSession->GetCurrentModel();
pfcSolid_ptr solid = pfcSolid::cast(model);
wfcWSolid_ptr wSolid = wfcWSolid::cast(model);
cout << model->GetFullName() << endl;
pfcFeatures_ptr feas = solid->ListFeaturesByType(false, pfcFEATTYPE_COMPONENT);
pfcFeature_ptr fea = feas->get(0);
pfcComponentFeat_ptr comFea = pfcComponentFeat::cast(fea);
xstring modelNameN = model->GetFullName().ToLower();
xstring modelNameX = modelNameN.Substring(1, modelNameN.GetLength());
cStringT modelName = modelNameX.operator cStringT();
cout << modelName << endl;
cout << comFea->GetName() << endl;
pfcModel_ptr model1 = wSession->GetModel(modelNameX, pfcMDL_PART);
cout << model1->GetFullName() << endl;
pfcSolid_ptr solid1 = pfcSolid::cast(model1);
cout << solid1->GetFullName() << endl;
pfcFamilyMember_ptr famMember = pfcFamilyMember::cast(solid1);
pfcFamilyTableRows_ptr famRows = famMember->ListRows();
pfcWindow_ptr win = wSession->GetCurrentWindow();
//pfcRegenInstructions_ptr regeIns = pfcRegenInstructions::Create(false, true, true);
/*regeIns->SetResolveModeRegen(true);
regeIns->SetRefreshModelTree(true);*/
/*wfcWRegenInstructions_ptr wRegeIns = wfcWRegenInstructions::Create();
wRegeIns->SetNoResolveMode(true);
wRegeIns->SetForceRegen(true);
wRegeIns->SetRefreshModelTree(true);*/
for (int i = 0; i < famRows->getarraysize(); i++)
{
pfcFamilyTableRow_ptr famRow = famRows->get(i);
xstring famName = famRow->GetInstanceName();
pfcModel_ptr famModel = famRow->CreateInstance();
pfcCompModelReplace_ptr modelReplace = comFea->CreateReplaceOp(famModel);
cout << modelReplace->GetNewModel()->GetFullName() << endl;
//solid->ExecuteFeatureOps(, NULL);
/*pfcFeatureOperation_ptr feaOpt = pfcFeatureOperation::cast(modelReplace);
pfcFeatureOperations_ptr feaOpts = pfcFeatureOperations::create();
feaOpts->append(feaOpt);
solid->ExecuteFeatureOps(feaOpts, 0);*/
/*solid->Regenerate();
win->Refresh();
win->Repaint();*/
cout << "Test " << endl;
}
}
VB API Test via old method ComponentFeat.CreateReplaceOp() & Solid.ExecuteFeatureOps()
static void Main(string[] args)
{
CCpfcAsyncConnection cCpfcAsync = new CCpfcAsyncConnection();
IpfcAsyncConnection conn = cCpfcAsync.Connect(null, null, null, null);
CMpfcSession cMpfc = new CMpfcSession();
IpfcSession session = cMpfc.GetCurrentSessionWithCompatibility((int)EpfcCreoCompatibility.EpfcC4Compatible);
IpfcBaseSession baseSession = session as IpfcBaseSession;
Console.WriteLine(baseSession.GetCurrentDirectory());
IpfcModel model = baseSession.CurrentModel;
IpfcSolid solid = model as IpfcSolid;//获取MC组件 的Solid
//获取NC solid下的组件特征
IpfcFeatures feas= solid.ListFeaturesByType(true, (int)EpfcFeatureType.EpfcFEATTYPE_COMPONENT);
IpfcComponentFeat comFea = feas[0] as IpfcComponentFeat;//转化为组件特征
string modelName = model.FullName.ToLower().Replace("n", "");
IpfcModel model1 = baseSession.GetModel(modelName, (int)EpfcModelType.EpfcMDL_PART);//NC组件下的部件
IpfcSolid solid1 = model1 as IpfcSolid;//NC组件下的部件 的Solid,用于取族表
IpfcFamilyMember familyMember = solid1 as IpfcFamilyMember;////NC组件下的部件 下的族表实例
IpfcFamilyTableRows famRows = familyMember.ListRows();
IpfcRegenInstructions regeIns =new CCpfcRegenInstructions().Create(true,null,null);
regeIns.RefreshModelTree = true;
regeIns.ResolveModeRegen = true;
regeIns.ForceRegen = true;
foreach (IpfcFamilyTableRow famRow in famRows)
{
string famName = famRow.InstanceName;
IpfcModel famModel = famRow.CreateInstance();
//Console.WriteLine(famModel.CommonName);
IpfcCompModelReplace compModelReplace = comFea.CreateReplaceOp(famModel);//创建替换操作类
//compModelReplace.NewModel = famModel;//指名替换后的新模型
CpfcFeatureOperations replaceOpts =new CpfcFeatureOperations();
replaceOpts.Append(compModelReplace);
solid.ExecuteFeatureOps(replaceOpts, regeIns);
}
conn.Disconnect(1000);
}
Seems don't work , or maybe some mistakes i had, would you mind to show me the right method?