void AssyComp2Skel_CallBack::OnCommand() { try { pfcSession_ptr Session = pfcGetProESession(); pfcWindow_ptr Window = Session->GetCurrentWindow(); pfcAssembly_ptr rgAssy = nullptr; pfcSolid_ptr compMdl = nullptr; // === STEP1 - check if an assembly is loaded ... // logFile << __LINE__ << ": STEP1 - check if an assembly is loaded ..." << endl; if (Session->GetCurrentModel()->GetType() != 0) { logFile << "Current model is not an assembly! Aborting ...\n" << endl; return; } else { logFile << "Current Model is of Type: " << Session->GetCurrentModel()->GetType() << " -> Assembly!\n" << endl; rgAssy = pfcAssembly::cast(Session->GetCurrentModel()); } // // *** STEP1 - END // === STEP2 - assemble component ... // pfcModelDescriptor_ptr compMdlDescriptor = pfcModelDescriptor::CreateFromFileName("test_00.prt"); compMdlDescriptor->SetPath(cCurrentPath); pfcRetrieveModelOptions_ptr retrieveMdlOpts = pfcRetrieveModelOptions::Create(); retrieveMdlOpts->SetAskUserAboutReps(xfalse); // --- Modell laden ... compMdl = pfcSolid::cast(Session->RetrieveModelWithOpts(compMdlDescriptor)); // --- Modell einsetzen ... pfcComponentFeat_ptr component = pfcComponentFeat::cast(rgAssy->AssembleComponent(compMdl, 0)); // // *** STEP2 - END // === STEP3 - Create constraints ... // pfcComponentConstraints_ptr constraints = pfcComponentConstraints::create(); pfcComponentConstraint_ptr constraint1 = pfcComponentConstraint::Create(pfcASM_CONSTRAINT_CSYS); // // *** STEP3 - END // === STEP4 - Define Componentpath ... // xintsequence_ptr compPathIds = xintsequence::create(); compPathIds->append(component->GetId()); pfcComponentPath_ptr compPath = pfcCreateComponentPath(rgAssy, compPathIds); logFile << "comppath->FileName: " << compPath->GetLeaf()->GetFileName() << endl; logFile << "comppath->CompID: " << compPath->GetComponentIds() << "\n" << endl; // // *** STEP4 - END // === STEP5 - Define Componentenreference ... // pfcModelItem_ptr compCsys = compMdl->GetItemByName(pfcITEM_COORD_SYS, "T-KSYS"); pfcSelection_ptr compCsysSel = nullptr; try { compCsysSel = pfcCreateModelItemSelection(compCsys, compPath); } xcatchbegin xcatchcip(Ex) logFile << __LINE__ << ": Exception (compCsysSel):\n" << Ex << endl; xcatchend // // *** STEP5 - END // --- Create ASSYPATH ... xintsequence_ptr assyPathIds = xintsequence::create(); assyPathIds->clear(); assyPathIds->set(0, 0); pfcComponentPath_ptr assyPath = nullptr; try { assyPath = pfcCreateComponentPath(rgAssy, assyPathIds); } xcatchbegin xcatchcip(Ex) logFile << __LINE__ << ": Exception (assyPath):\n" << Ex << endl; xcatchend logFile << "assypath->FileName: " << assyPath->GetRoot()->GetFileName() << endl; logFile << "assypath->CompID: " << assyPath->GetComponentIds() << "\n" << endl; // === STEP6 - Define Assemblyreference ... // pfcModelItem_ptr assyCsys = rgAssy->GetItemByName(pfcITEM_COORD_SYS, "B-KSYS"); pfcSelection_ptr assyCsysSel = nullptr; try { assyCsysSel = pfcCreateModelItemSelection(assyCsys, assyPath); } xcatchbegin xcatchcip(Ex) logFile << __LINE__ << ": Exception (assyCsysSel):\n" << Ex << endl; xcatchend // // *** STEP6 - END // === STEP7 - Assy and Comp Constraints ... // constraint1->SetComponentReference(compCsysSel); constraint1->SetAssemblyReference(assyCsysSel); // // *** STEP7 - END // === STEP8 - Constraints ... try { constraints->append(constraint1); } xcatchbegin xcatchcip(Ex) logFile << __LINE__ << ": Exception (constraints):\n" << Ex << endl; xcatchend // // *** STEP8 - END // === STEP9 - Give Constraints to Component ... // try { component->SetConstraints(constraints, assyPath); } xcatchbegin xcatchcip(Ex) logFile << __LINE__ << ": Exception (CONSTRAINTS):\n" << Ex << endl; xcatchend // // *** STEP9 - END pfcRegenInstructions_ptr Regen = pfcRegenInstructions::Create(); Regen->SetRefreshModelTree(true); rgAssy->Regenerate(Regen); component->Regenerate(); Window->Repaint(); } xcatchbegin xcatchcip(Ex) logFile << __LINE__ << ": OTK Exception thrown:\n" << Ex << endl; xcatchend }