Open Rail Designer开发基础

1、开发环境

Visual Studio 2015 Professional
Open Rail Designer Update 5(orld10050030en)
SDK(orsdk10050030en)

1.1、配置统一的开发环境

1、新建一个名为HelloORD的项目,保存后关闭


图片.png

2、找到HelloORD文件的路径,用记事本的方式打开HelloORD.csproj文件


图片.png
图片.png

3、找到<ItemGroup> ....... </ItemGroup>,添加引用路径,在此,将所有可能用到的ORD开发需要引用的dll文件全部打包,便于后期开展协同开发。


图片.png
<ItemGroup>
    <Reference Include="Bentley.CifNET.Objects.Data.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.CadSystem.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.CadSystem.Interfaces.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Interfaces.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Formatting.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Geometry.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Mstn.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.LinearGeometry.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.LinearGeometry.ComplexConstructions.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Graphics.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.DomainModel.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Model.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.UI.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.Presentation.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.SDK.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.DgnAccess.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.Tools.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.SnapRules.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Objects.RuleManagement.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.ProjectSettingsModel.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Objects.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Objects.Presentation.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.TerrainModel.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.UI.Tools.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.GeometryModel.Tool.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.UI.Controls.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.UI.Templates.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.UI.CursorPrompt.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.CadSystem.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Dgn.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Objects.Presentation.Controls.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Model.Presentation.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.CifNET.Model.DataAccess.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.CifNET.custommodel.4.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.logging-2.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.TerrainModelNET.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.GeometryNET.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.Platform.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.microstation.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.microstation.wpf.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.microstation.general.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.microstation.interfaces.1.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.ECObjects3.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.EC.Persistence3.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.EC.Controls3.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.ECSystem3.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.general.1.0.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.platform.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.windowing.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.windowing.Win32.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="bentley.ui.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.GeometryNET.Structs.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="Bentley.DGNPlatformNET.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="ustation.dll">
      <Private>false</Private>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>

4、注意到上述路径均为相对路径,为此在这一步需要指定一个绝对路径,以便程序读取上面列出的所有.dll文件。找到第一个<PropertyGroup>......</PropertyGroup>,将<ReferencePath> .......</ReferencePath>内容复制到相应位置。


图片.png
<ReferencePath>$(ORD);$(ORD)\CustomEntity\;$(ORD)\OpenRoads\;$(ORD)Assemblies\;$(ORD)Assemblies\ECFramework\;$(ORD)Assemblies\ECFramework\extensions\;$(ORD)Cif\</ReferencePath>

ORD中有两种方式来
1)配置系统环境指向ORD,这种方式比较麻烦,不适合团队开发。
2)安装SDK,以管理员身份运行SDK,SDK自动初始化ORD路径

5、复制批处理文件openSln.bat文件到HelloORD解决方案文件夹下,注意文件放置路径。


图片.png
@echo off
@echo This batch file should be run from a VS2015 x64 Cross Tools Command Prompt
@echo Make sure that you have already run OpenRoadsDesignerSDKDeveloperShell.bat in
@echo order to set the required environment variables.

IF DEFINED ORDE GOTO checkforvs2015
ECHO ORDE not defined. You need to run OpenRoadsDesignerSDKDeveloperShell.bat first!
GOTO end

:checkforvs2015
IF DEFINED vs140comntools GOTO vardefined
ECHO Visual Studio 2015 is required for this project
GOTO end

:vardefined
rem At this point "vcvarsall.bat x86_amd64" or VS2013 x64 Cross Tools Command Prompt should already have been called
rem in order to compile successfully
@echo devenv.exe -useenv "%~dp0CustomEntity.sln"
start devenv.exe -useenv "%~dp0CustomEntity.sln"

:end

将批处理文件中的dp0CustomEntity.sln改成dp0HelloORD.sln ,其中 dp0为当前路径。


图片.png

6、以管理员身份打开ORD SDK,输入devenv启动Visual Studio,在近期打开项目中选择HelloORD。


图片.png

查看引用中的.dll文件有没有出现黄色小叹号,说明配置环境成功。


图片.png

1.2、添加xml文件

1、浏览到Commands.xml的目录下,将Commands.xml添加到当前解决方案中来。


图片.png

2、将Commands.xml的文件属性下的生成操作改为嵌入式资源。


图片.png

Commands.xml中的源码如下,这些代码是通用的,下次使用仅需改变部分代码。

<?xml version="1.0" encoding="utf-8" ?>
<KeyinTree xmlns="http://www.bentley.com/schemas/1.0/MicroStation/AddIn/KeyinTree.xsd">
  <!--The commands.xml contains 3 main sections. <RootKeyinTable> defines the root of the 
        command table tree. <SubKeyinTables> defines all of the subtrees that appear in the
        tree. <KeyinHandlers> provides a mapping from key-in string to the method that handles
        the key-in.-->

  <!--Define the root. The entry for the root is very similar to an entry in the
        table of subentries. The diference is that the entry for the root is labelled
        RootKeyinTable, but an entry for a subtable is labelled as KeyinTable.-->
  <RootKeyinTable ID="root">
    <Keyword SubtableRef="CUSTOMADDIN"
            CommandClass="MacroCommand" CommandWord="CUSTOMADDIN" >
      <Options Required="true"/>
    </Keyword>
  </RootKeyinTable>

  <!--Define subtables-->
  <SubKeyinTables>
    <KeyinTable ID="CUSTOMADDIN">
      <Keyword CommandWord="TEST"> </Keyword>      
      <Keyword CommandWord="CreateCustomComponent"> </Keyword>    
    </KeyinTable>
  </SubKeyinTables>

  <!--Define a mapping from key-in to the method that handles the key-in.-->
  <KeyinHandlers>
    <KeyinHandler Keyin="CUSTOMADDIN TEST" Function="CustomEntity.AddinKeyin.TEST"/>
    <KeyinHandler Keyin="CUSTOMADDIN CreateCustomComponent" Function="CustomEntity.AddinKeyin.CreateCustomComponent"/>
    
  </KeyinHandlers>
</KeyinTree>

3、上述手动嵌入xml操作在V8i版本中,可以直接识别,但是到了CE版,还需要配置HelloORD.csproj,程序才可以自动加载。

<EmbeddedResource Include="Commands.xml">
      <LogicalName>CommandTable.xml</LogicalName>
      <SubType>Designer</SubType>
    </EmbeddedResource>

复制上面的代码块,替换下图标识<ItemGroup>......</ItemGroup>中的内容。


图片.png

1.3、添加命令入口

1、添加一个类,取名为MyAddin。


图片.png
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloORD
{
    [Bentley.MstnPlatformNET.AddIn(MdlTaskID ="HelloORD")]
    internal class MyAddin : Bentley.MstnPlatformNET.AddIn
    {
        public MyAddin(IntPtr mdlDescriptor) : base(mdlDescriptor)
        {

        }

        protected override int Run(string[] commandLine)
        {
            return 0;
        }
    }
}

1.4、设置输入输出

图片.png

1、应用程序,目标框架改成:4.6.1,输出类型改为:类库


图片.png

2、生成,目标平台改为:x64,输出路径改为:C:\Program Files\Bentley\OpenRail Designer CONNECT Edition\OpenRailDesigner\Mdlapps ,此路径为OpenRail Designer的默认安装路径,不是安装在此路径下的,可以改到自己的ORD的路径下。


图片.png

3、调试,将启动操作改为启动外部程序,外部程序路径为C:\Program Files\Bentley\OpenRail Designer CONNECT Edition\OpenRailDesigner\OpenRailDesigner.exe
图片.png

1.5、 Commands.xml文件

1.命令

1.6、 添加类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloORD
{
    class AddInKeyIn
    {
        public static void Test(string unpared)
        {
            System.Windows.Forms.MessageBox.Show("Hello ORD");
        }
        public static void CreateCustomEntity(string unpared)
        {

        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,372评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,368评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,415评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,157评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,171评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,125评论 1 297
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,028评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,887评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,310评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,533评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,690评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,411评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,004评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,659评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,812评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,693评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,577评论 2 353

推荐阅读更多精彩内容

  • 写了这么多个 C# 项目,是否对项目文件 csproj 有一些了解呢?Visual Studio 是怎么让 csp...
    欲与星辰眠阅读 1,992评论 0 1
  • ORA-00001: 违反唯一约束条件 (.) 错误说明:当在唯一索引所对应的列上键入重复值时,会触发此异常。 O...
    我想起个好名字阅读 5,307评论 0 9
  • 一、简历准备 1、个人技能 (1)自定义控件、UI设计、常用动画特效 自定义控件 ①为什么要自定义控件? Andr...
    lucas777阅读 5,200评论 2 54
  • 点击查看原文 Web SDK 开发手册 SDK 概述 网易云信 SDK 为 Web 应用提供一个完善的 IM 系统...
    layjoy阅读 13,758评论 0 15
  • 今年过年发红包发成了我的一场灾难:我是有社交焦虑的,小红包都能让我没有办法处理,如何回礼?回多少算合适?会不会我回...
    祭司司司阅读 261评论 0 1