1、开发环境
Visual Studio 2015 Professional
Open Rail Designer Update 5(orld10050030en)
SDK(orsdk10050030en)
1.1、配置统一的开发环境
1、新建一个名为HelloORD的项目,保存后关闭
2、找到HelloORD文件的路径,用记事本的方式打开HelloORD.csproj文件
3、找到<ItemGroup> ....... </ItemGroup>,添加引用路径,在此,将所有可能用到的ORD开发需要引用的dll文件全部打包,便于后期开展协同开发。
<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>内容复制到相应位置。
<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解决方案文件夹下,注意文件放置路径。
@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为当前路径。
6、以管理员身份打开ORD SDK,输入devenv启动Visual Studio,在近期打开项目中选择HelloORD。
查看引用中的.dll文件有没有出现黄色小叹号,说明配置环境成功。
1.2、添加xml文件
1、浏览到Commands.xml的目录下,将Commands.xml添加到当前解决方案中来。
2、将Commands.xml的文件属性下的生成操作改为嵌入式资源。
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>中的内容。
1.3、添加命令入口
1、添加一个类,取名为MyAddin。
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、设置输入输出
1、应用程序,目标框架改成:4.6.1,输出类型改为:类库
2、生成,目标平台改为:x64,输出路径改为:C:\Program Files\Bentley\OpenRail Designer CONNECT Edition\OpenRailDesigner\Mdlapps ,此路径为OpenRail Designer的默认安装路径,不是安装在此路径下的,可以改到自己的ORD的路径下。
3、调试,将启动操作改为启动外部程序,外部程序路径为C:\Program Files\Bentley\OpenRail Designer CONNECT Edition\OpenRailDesigner\OpenRailDesigner.exe
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)
{
}
}
}