cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Translate the entire conversation x

When creating a sketch feature, wfcElement::Create(PRO_E_STD_FEATURE_NAME) is always not correct.

CC_12210022
4-Participant

When creating a sketch feature, wfcElement::Create(PRO_E_STD_FEATURE_NAME) is always not correct.

When I want to create sketch feature,
    wfcElement::Create(PRO_E_STD_FEATURE_NAME) is always not be correctly, It always disappear. 
    The RightPlane can not be obtained!!

Help me!!!!! 😂

 

 

pfcSession_ptr session = pfcGetProESession(); if (session == NULL) { OutputLogMsg("failed to obtain creo session."); return; } wfcWSession_ptr Wsession = wfcWSession::cast(session); // 取得目前模型(確認為零件) pfcModel_ptr model = session->GetCurrentModel(); if (!model || model->GetType() != pfcMDL_PART) { OutputLogMsg("failed to obtain PART model."); return; } // 將模型轉型成 Solid 物件(支援草繪) pfcSolid_ptr solid = pfcSolid::cast(model); wfcWSolid_ptr Wsolid = wfcWSolid::cast(solid); // 檢查目前模型是否為有效的 Solid 物件 if (solid == NULL) { OutputLogMsg("failed to get Solid from current model."); return; } // =============================================== // 嘗試取得名稱為 "TOP" 的基準面 pfcModelItems_ptr Items = solid->ListItems(pfcITEM_FEATURE); pfcModelItem_ptr TopPlane = nullptr; pfcModelItem_ptr RightPlane = nullptr; for (int i = 0; i < Items->getarraysize(); i++) { pfcFeature_ptr feat = pfcFeature::cast(Items->get(i)); if (feat->GetName() == "TOP") { TopPlane = feat; } else if (feat->GetName() == "RIGHT") { RightPlane = feat; } } if (!TopPlane || !RightPlane) { OutputLogMsg("failed to get TOP or RIGHT plane."); return; } xstring treeInfoFile = "C:/temp/ElementTree_Info.txt";  // 建立暫存檔案來儲存Element Tree資訊, 作為查閱之用 // =============================================== // 建立 ElementTree (草繪曲線特徵設定) wfcElements_ptr elems = wfcElements::create(); elems->append(wfcElement::Create(PRO_E_FEATURE_TREE, nullptr, 0)); elems->append(wfcElement::Create(PRO_E_FEATURE_TYPE, pfcCreateIntArgValue(PRO_FEAT_CURVE), 1)); elems->append(wfcElement::Create(PRO_E_CURVE_TYPE, pfcCreateIntArgValue(0), 1)); elems->append(wfcElement::Create(PRO_E_STD_FEATURE_NAME, pfcCreateStringArgValue("QQ_SKET"), 1)); elems->append(wfcElement::Create(PRO_E_STD_SECTION, nullptr, 1)); elems->append(wfcElement::Create(PRO_E_STD_SEC_SETUP_PLANE, nullptr, 2)); elems->append(wfcElement::Create(PRO_E_STD_SEC_PLANE, pfcCreateSelectionArgValue(pfcCreateModelItemSelection(TopPlane)), 3)); elems->append(wfcElement::Create(PRO_E_STD_SEC_PLANE_VIEW_DIR, pfcCreateIntArgValue(1), 3)); elems->append(wfcElement::Create(PRO_E_STD_SEC_PLANE_ORIENT_DIR, pfcCreateIntArgValue(2), 3)); elems->append(wfcElement::Create(PRO_E_STD_SEC_PLANE_ORIENT_REF, pfcCreateSelectionArgValue(pfcCreateModelItemSelection(RightPlane)), 3)); //elems->append(wfcElement::Create(PRO_E_SKETCHER, nullptr, 2)); wfcElementTree_ptr elemTree = Wsession->CreateElementTree(elems); // 建立元素樹,該樹描述了整個特徵的定義 // =============================================== wfcFeatCreateOptions_ptr opts_INCOMPLETE = wfcFeatCreateOptions::create(); opts_INCOMPLETE->append(wfcFEAT_CR_INCOMPLETE_FEAT); wfcWRegenInstructions_ptr regenInstrs = wfcWRegenInstructions::Create(); // 創建重生指令,確保模型在特徵建立後進行更新 wfcWFeature_ptr Wfeature_sketch = Wsolid->WCreateFeature(elemTree, opts_INCOMPLETE, regenInstrs); // 創建草繪曲線特徵 // =============================================== elemTree = Wfeature_sketch->GetElementTree(0, wfcFEAT_EXTRACT_NO_OPTS); // 取得特徵的元素樹 // =============================================== wfcElements_ptr elems_ = elemTree->ListTreeElements(); for (int ii = 0; ii < elems_->getarraysize(); ii++) { if (elems_->get(ii)->GetId() == PRO_E_STD_SEC_PLANE) { elems_->get(ii)->SetValue(pfcCreateSelectionArgValue(pfcCreateModelItemSelection(TopPlane))); } else if (elems_->get(ii)->GetId() == PRO_E_STD_SEC_PLANE_ORIENT_REF) { elems_->get(ii)->SetValue(pfcCreateSelectionArgValue(pfcCreateModelItemSelection(RightPlane))); } } elemTree = Wsession->CreateElementTree(elems_); elemTree->WriteElementTreeToFile(wfcELEMTREE_XML, "C:/temp/ElementTree_Info_2.txt"); // 將元素樹寫入到檔案中, //================================================ // 建立存取 PRO_E_SKETCHER 的元素路徑 (PRO_E_STD_SECTION → PRO_E_SKETCHER) wfcElemPathItems_ptr ElemPathItems = wfcElemPathItems::create(); ElemPathItems->append(wfcElemPathItem::Create(wfcELEM_PATH_ITEM_TYPE_ID, PRO_E_STD_SECTION)); ElemPathItems->append(wfcElemPathItem::Create(wfcELEM_PATH_ITEM_TYPE_ID, PRO_E_SKETCHER)); wfcElementPath_ptr sketchPath = wfcElementPath::Create(ElemPathItems); wfcElement_ptr sketchElement = elemTree->GetElement(sketchPath); wfcSpecialValue_ptr sketchSpvalue = sketchElement->GetSpecialValueElem(); wfcSection_ptr section_sketch = sketchSpvalue->GetSectionValue(); if (section_sketch == nullptr) { OutputLogMsg("failed to get sketch section."); return; } //================================================ pfcPoint2D_ptr center = wfcCreatePoint2D(0.00, 0.00); wfcSectionEntityCircle_ptr circle = wfcSectionEntityCircle::Create(center, 25.00); section_sketch->AddEntity(wfcSectionEntity::cast(circle)); pfcOutline2D_ptr line1 = wfcCreateOutline2D(-10.00, 20.00, 10.00, 20.00); wfcSectionEntityLine_ptr lineEnt1 = wfcSectionEntityLine::Create(line1); section_sketch->AddEntity(wfcSectionEntity::cast(lineEnt1)); pfcOutline2D_ptr line2 = wfcCreateOutline2D(10.00, 20.00, 10.00, -20.00); wfcSectionEntityLine_ptr lineEnt2 = wfcSectionEntityLine::Create(line2); section_sketch->AddEntity(wfcSectionEntity::cast(lineEnt2)); pfcOutline2D_ptr line3 = wfcCreateOutline2D(10.00, -20.00, -10.00, -20.00); wfcSectionEntityLine_ptr lineEnt3 = wfcSectionEntityLine::Create(line3); section_sketch->AddEntity(wfcSectionEntity::cast(lineEnt3)); pfcOutline2D_ptr line4 = wfcCreateOutline2D(-10.00, -20.00, -10.00, 20.00); wfcSectionEntityLine_ptr lineEnt4 = wfcSectionEntityLine::Create(line4); section_sketch->AddEntity(wfcSectionEntity::cast(lineEnt4)); section_sketch->SetIntentManagerMode(true); // 啟用意圖管理器模式, 進行完成截面定義 (在截面section_sketch中建立2D實體) section_sketch->SetIntentManagerMode(false); // 完成截面定義,關閉意圖管理器模式 // =============================================== wfcElements_ptr elements_NEW = Wfeature_sketch->GetElementTree(0, wfcFEAT_EXTRACT_NO_OPTS)->ListTreeElements(); for (int ii = 0; ii < elements_NEW->getarraysize(); ii++) { if (elements_NEW->get(ii)->GetId() == PRO_E_SKETCHER) { elements_NEW->get(ii)->GetSpecialValueElem()->SetSectionValue(section_sketch); break; } } for (int ii = 0; ii < elements_NEW->getarraysize(); ii++) { if (elements_NEW->get(ii)->GetId() == PRO_E_STD_SEC_PLANE) { elements_NEW->get(ii)->SetValue(pfcCreateSelectionArgValue(pfcCreateModelItemSelection(TopPlane))); } else if (elements_NEW->get(ii)->GetId() == PRO_E_STD_SEC_PLANE_ORIENT_REF) { elements_NEW->get(ii)->SetValue(pfcCreateSelectionArgValue(pfcCreateModelItemSelection(RightPlane))); } } wfcElementTree_ptr elemTree_NEW = Wsession->CreateElementTree(elements_NEW); elemTree_NEW->WriteElementTreeToFile(wfcELEMTREE_XML, "C:/temp/ElementTree_Info_3.txt"); // =============================================== wfcFeatCreateOptions_ptr opts_NO_OPTS = wfcFeatCreateOptions::create(); opts_NO_OPTS->append(wfcFEAT_CR_NO_OPTS); Wfeature_sketch->RedefineFeature(NULL, elemTree_NEW, opts_NO_OPTS, regenInstrs);

 

 

 

2 REPLIES 2

Hi @CC_12210022,


Thank you for your question. 

Your post appears well documented but has not yet received any response. I am replying to raise awareness. Hopefully, another community member will be able to help.

Also, feel free to add any additional information you think might be relevant. Like:

 

  1. Have you tried any troubleshooting steps so far? If so, what were they?
  2. What version of the software are you using?

 It sometimes helps to have screenshots to better understand what you are trying to do.

Regards,

Vivek N
Community Moderation Team


 

VIN
12-Amethyst
12-Amethyst
(To:vnamboodheri)

HI,can use ProModelitemByNameInit(); output the "RIGHT" name datum plane.

Announcements

Top Tags