44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
|
|
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);//对话框输出导入是否成功
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|