请参考 CIM 开发包中的示例新建自己的开发项目,您也可以直接在示例程序中添加自己的代码。模板的例子位于 examples/CIMExamples/CIMExample 项目的 CIMExampleTemplateUseCase.cpp 中。
下面的例子演示了创建模板的基本流程。这里以创建一个矩形为例。
8. auto uor = ISessionMgr::GetActiveDgnModelP()->GetModelInfo().GetUorPerMeter(); 9. 10. auto library = CIM::CIMTemplate::ITemplateLibrary::Create(); 11. auto category = library->AddCategory(L"UseCase"); 12. auto t = category->AddTemplate(L"rectangle"); 13. 14. auto P0 = t->AddPoint(-1 * uor, -1 * uor); 15. auto P1 = t->AddPoint(-1 * uor, 1 * uor); 16. auto P2 = t->AddPoint(1 * uor, 1 * uor); 17. auto P3 = t->AddPoint(1 * uor, -1 * uor); 18. 19. auto component = t->AddComponent(); 20. component->AddLine(P0->GetName().GetWCharCP(), P1->GetName().GetWCharCP()); 21. component->AddLine(P1->GetName().GetWCharCP(), P2->GetName().GetWCharCP()); 22. component->AddLine(P2->GetName().GetWCharCP(), P3->GetName().GetWCharCP()); 23. component->AddLine(P3->GetName().GetWCharCP(), P0->GetName().GetWCharCP()); 24. 25. auto curve = t->ToCurveVector(); 26. 27. EditElementHandle eeh; 28. 29. if (BentleyStatus::SUCCESS != DraftingElementSchema::ToElement(eeh, *curve, nullptr, true, *ISessionMgr::GetActiveDgnModelP())) 30. { 31. return; 32. } 33. 34. eeh.AddToModel();
其中 ,第1、2、3步创建了模板的存储对象,并指明了模板在模板库中的相对位置。第4步创建了描述模板的顶点坐标。第5步描述了模板的连接方式,本例中定义了4条首尾相连的线段。第6,7步将模板转换成曲线并添加到模型中。