Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
中国BDN社区
  • Welcome to Bentley Communities
  • Bentley's Communities
  • 中国BDN社区
  • Cancel
中国BDN社区
中国BDN社区-威客 7.2 快速入门
    • Sign In
    • 中国BDN社区-威客
    • +iTwin.js编程
    • +MicroStation CONNECT版SDK的新变化
    • +MicroStation编程技巧
    • -OpenRoads中国版平台开发指南
      • 1 概述
      • 2. 系统基本组成
      • +3. CIM SDK
      • +4 Cim Elements
      • +5 CIMMesh SDK
      • +6 CIMSolid SDK
      • -7 CIM Template
        • 7.1 简介
        • 7.2 快速入门
        • +7.3模板的二次开发
        • 7.4 模板编辑器
        • +7.5 CIM 模板与 OpenBridge Modeler模板的差异
    • +ORD SDK二次开发编程
    • +一步步学习ABD-CE开发
    • +一步步学习MicroStation CE Addin开发
    • 一步步学习MicroStation CE MDL开发
    • +一步步学习ProjectWise编程
    • 中国优先社区二次开发精华帖汇总
    • +学习Microstation交互式工具开发
    • +过期帖,留存仅供参考
    • +非Bentley社区分享的文章
    • C#、C/C++相关的编程知识汇总
    • C#如何实现元素关联Link Set?有做过相关需求的老师指教一下吗

     
     Questions about this article, topic, or product? Click here. 

    7.2 快速入门

            请参考 CIM 开发包中的示例新建自己的开发项目,您也可以直接在示例程序中添加自己的代码。模板的例子位于 examples/CIMExamples/CIMExample 项目的 CIMExampleTemplateUseCase.cpp 中。

            下面的例子演示了创建模板的基本流程。这里以创建一个矩形为例。

    1. 创建模板库
    2. 创建目录
    3. 创建模板对象
    4. 添加点坐标
    5. 创建组件
    6. 转换成曲线
    7. 添加到模型

            

    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步将模板转换成曲线并添加到模型中。

    • Share
    • History
    • More
    • Cancel
    • Li Ma Created by Li Ma
    • When: Fri, Mar 12 2021 2:13 AM
    • Revisions: 1
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies