添加项目文件。
This commit is contained in:
43
Mstn.Toolkit/Helpers/SchemaHelper.cs
Normal file
43
Mstn.Toolkit/Helpers/SchemaHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
using Bentley.DgnPlatformNET;
|
||||
using Bentley.DgnPlatformNET.DgnEC;
|
||||
using Bentley.ECObjects.Schema;
|
||||
using Bentley.ECObjects.XML;
|
||||
using Bentley.MstnPlatformNET;
|
||||
|
||||
namespace Mstn.Toolkit.Helpers
|
||||
{
|
||||
public static class SchemaHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 从xml文件中定义ECSchema
|
||||
/// </summary>
|
||||
/// <param name="xmlFilePath"></param>
|
||||
/// <returns></returns>
|
||||
public static IECSchema DefineECSchemaFromXml(string xmlFilePath)
|
||||
{
|
||||
string schemaXml = File.ReadAllText(xmlFilePath);//读取XML文件内容
|
||||
ECSchemaXmlStringReader xmlReader = new ECSchemaXmlStringReader(schemaXml);//声明ECSchema阅读器
|
||||
IECSchema deserializedSchema = xmlReader.Deserialize();//将EC Schema阅读器读取到的信息反序列化
|
||||
return deserializedSchema;//返回ECSchema
|
||||
}
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
/// <param name="testSchema"></param>
|
||||
public static void ImportSchema(IECSchema testSchema)
|
||||
{
|
||||
DgnFile dgnFile = Session.Instance.GetActiveDgnFile();//获得当前激活的文件
|
||||
SchemaImportStatus impStatus = DgnECManager.Manager.ImportSchema(testSchema, dgnFile, new ImportSchemaOptions());//导入ECSchema
|
||||
MessageBox.Show("Schema Import Status:\n" + impStatus);//对话框输出导入是否成功
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user