【OPM C#】Pipeline Manager 的功能在哪个dll中

我想知道Pipeline Manager 中的Edit selected Pipeline修改管线编号的功能在哪个dll中

Parents
  • 用ecx items dump先看看EC模型,然后用EC API查询修改。

  • 管线编号不能通过修改EC class属性修改吗,为什么我用以下代码执行后,管线编号没有被修改。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Bentley.OpenPlantModeler.SDK.AssociatedItems;
    using Bentley.OpenPlantModeler.SDK.Enums;
    using Bentley.OpenPlantModeler.SDK.Utilities;
    using Bentley.OpenPlantModeler.SDK.Components;
    using Bentley.GeometryNET;
    using Bentley.OpenPlantModeler.SDK.ComponentProperties;
    using Bentley.OpenPlantModeler.SDK.Components.PipingComponents;
    using Bentley.OpenPlantModeler.SDK.Components.EquipmentComponents;
    using System.Reflection;
    using Bentley.DgnPlatformNET;
    using Bentley.MstnPlatformNET;
    using Bentley.ECObjects.Schema;
    using Bentley.ECObjects.XML;
    using Bentley.ECObjects;
    using Bentley.GeometryNET;
    using Bentley.DgnPlatformNET.DgnEC;
    using Bentley.DgnPlatformNET.Elements;
    using System.Reflection;
    using Bentley.ECObjects.Instance;
    using Bentley.EC.Persistence.Query;
    using System.IO;
    using System;
    using System.Xml;
    
    namespace AAA
    {
        class pipe
        {
            public static void CreatePipe()
            //public void CreatePipe(Bentley.GeometryNET.DPoint3d pt)
            {
                string specification = "mEX-OPM";
                double nominalDiameter = 150;
    
                double length = 500;
    
                double UorPerMas = 0;
                DPoint3d origin = new DPoint3d(0, 0, 0);
                UorPerMas = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter / 1000;
    
                if (PrepareForPiping(specification, nominalDiameter,"u1","s1"))
                {
                    double length1 = 2000;
                       
                    for (int i = 0; i < 1; i++)
                    {
    
                        //起点管
                        string pbs = "123";
                        PipeComponentData pipe1Data = new PipeComponentData(specification, nominalDiameter);
                        pipe1Data.SetProperty("LENGTH", length1.ToString());
                        pipe1Data.SetProperty("PBS", pbs);//设置自定义属性PBS
                        PipeComponent pipe1 = new PipeComponent(origin, pipe1Data, System.Math.PI * (-90) / 180, DrawingView.ViewFront, false);
                        pipe1.Create();
                        /*
                        double dCoordinateAngle = 0;
                        PipeElbowComponentData elbow1Data = new PipeElbowComponentData(PipeElbowType.PIPE_ELBOW_90_DEGREE, specification, nominalDiameter);
                        PipeElbowComponent elbow1 = new PipeElbowComponent(pipe1.GetEndPoint(1), elbow1Data, System.Math.PI * -90 / 180, System.Math.PI * -(180 + dCoordinateAngle) / 180, System.Math.PI * 90 / 180, false);
                        elbow1.Create();
                        */
                        LocateAndLoadSchema();
                        CreateWidget();
                        UpdateWidget();
                    }
    
                    Bentley.ECObjects.Instance.ECInstanceList pipeInstances = DgnUtilities.FindInstancesAndLoadRelated("PIPE", false, "PIPING_COMPONENT_HAS_PORT", true);
                    if (pipeInstances != null && pipeInstances.Count > 0)
                    {
                        foreach (Bentley.ECObjects.Instance.IECInstance pipeInst in pipeInstances)
                        {
                            if (length > 0.00001)
                            {
                                string name = pipeInst["NAME"].StringValue;
                                string pipeline = pipeInst["LINENUMBER"].StringValue;
                                string spec = pipeInst["SPECIFICATION"].StringValue;
                                string nominalSize = pipeInst["NOMINAL_DIAMETER"].StringValue;
                                string Length = pipeInst["LENGTH"].StringValue;
                                string PBS = pipeInst["PBS"].StringValue;
    
                                //MessageBox.Show(string.Format("{0}", PBS));
    
                                pipeInst["PBS"].StringValue = "321";
                                PBS = pipeInst["PBS"].StringValue;
                                //MessageBox.Show(string.Format("{0}", PBS));
                                pipeInst.ExtendedDataValueSetter.Add(pipeInst["PBS"].StringValue, "333");
                            }
                            
                        }
    
                    }
                }
                
            }
    
            private static LineElement s_widgetLine;
            private static LineElement s_gadgetLine;
            private static IDgnECInstance gadgetInstance;
            private static IDgnECInstance widgetInstance;
            private static IECRelationshipInstance relationshipInstance;
            private static IECSchema ecSimpleSchema;
            private const string schemaName = "OpenPlant_3D.01.08";
            private const string property_Name = "UNIT_NAME";
            private const string schema_widget = "PIPING_NETWORK_SYSTEM";
            private const string schema_gadget = "Gadget";
            private const string GadgetWidgetRelation = @"\GadgetWidgetRelation.xml";
            private const string WidgetGadgetRelation = @"\WidgetGadgetRelation.xml";
            public static LineElement CreateLine(double x1, double y1, double x2, double y2)
            {
                DgnModel activeDgnModel = GetDefaultModel();
                DPoint2d startPoint = new DPoint2d(x1, y1);
                DPoint2d endPoint = new DPoint2d(x2, y2);
                DSegment3d segment3D = new DSegment3d(startPoint, endPoint);
                LineElement lineElement = new LineElement(activeDgnModel, null, segment3D);
                if (null != lineElement)
                    lineElement.AddToModel();
    
                return lineElement;
            }
            public static void LocateAndLoadSchema()//获取ecSimpleSchema
            {
                try
                {
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    string schemaSearchPath = Path.GetDirectoryName(assembly.Location);
                    IECSchemaLocater searchLocater = new SearchPathSchemaFileLocater(schemaSearchPath);
                    if (null == searchLocater)
                        return;
                    ECObjects.AddSchemaLocater(searchLocater);
                    /*ECSchema is data that describes data (i.e. metadata). ECSchema provides a way to express the structure, context, 
                    and to some extent, the meaning of EC data, allowing programmatic understanding, presentation, analysis, and even manipulation of that data.
                    Locates an ECXML Schema */
                    ecSimpleSchema = ECObjects.LocateSchema(schemaName, SchemaMatchType.Exact, null, null);
                    if (null == ecSimpleSchema)
                        MessageBox.Show("ERROR_SCHEMANOTFOUND","test");
                    else
                    {
                        DgnECManager dgnECManager = DgnECManager.Manager;
                        if (null == dgnECManager)
                            return;
                        DgnFile activeDgnFile = Session.Instance.GetActiveDgnFile();
                        SchemaImportStatus schemaImportStatus = dgnECManager.ImportSchema(ecSimpleSchema, activeDgnFile, new ImportSchemaOptions(true));
                        MessageBox.Show("Success_Schema_Import");
                    }
                }
                catch (Exception ex)
                {
                    MessageCenter.Instance.StatusMessage = ex.Message;
                    MessageCenter.Instance.StatusWarning = ex.Message;
                }
            }
            public static void CreateWidget()
            {
                try
                {
                    DgnFile activeDgnFile = Session.Instance.GetActiveDgnFile();// get active dgn file
                    
                    DgnECManager dgnECManager = DgnECManager.Manager;// check if managr is null; if yes return.
                    //load ecschema
                    if (null == ecSimpleSchema)
                    {
                        MessageBox.Show("ERROR_SCHEMANOTFOUND");
                        return;
                    }
                    //create line
                    s_widgetLine = CreateLine(0, 0, -100, 100);
    
                    //Creating widget instance
                    IECClass ecClass = ecSimpleSchema.GetClass(schema_widget);
                    //A DgnECInstanceEnabler enables the creation of IDgnECInstances of a particular IECClass within a DgnFile.
                    DgnECInstanceEnabler widgetEnabler = dgnECManager.ObtainInstanceEnabler(activeDgnFile, ecClass);
                    ECDInstance widgetWipInstance = widgetEnabler.SharedWipInstance;
                    widgetWipInstance.SetAsString(property_Name, "UNIT_NAME");
                    //Creates an IDgnECInstance on the specified element. 
                    
                    widgetInstance = widgetEnabler.CreateInstanceOnElement(s_widgetLine, widgetWipInstance, false);
                    
                    MessageBox.Show("Success_WidgetCreate");
                }
                catch (Exception ex)
                {
                    MessageCenter.Instance.StatusWarning = ex.Message;
                }
            }
    
            public static void UpdateWidget()
            {
                try
                {
                    if (widgetInstance == null)
                    {
                        MessageBox.Show("ERROR_INSTANCENOTFOUND");
                        return;
                    }
                    else
                    {
                        widgetInstance.SetAsString(property_Name, "U1");
                        widgetInstance.WriteChanges();
                        MessageBox.Show("Success_UpdateWidget");
                    }
                }
                catch (Exception ec)
                {
                    MessageCenter.Instance.StatusWarning = ec.Message;
                }
            }
    
            public static DgnModel GetDefaultModel() // get the dgnModel
            {
                DgnFile dgnFile = Session.Instance.GetActiveDgnFile();
                //Get the ModelId of the default model in this file.
                ModelId modelId = dgnFile.DefaultModelId;
                StatusInt statusInt;
                return dgnFile.LoadRootModelById(out statusInt, modelId, true, true, true);
            }
    
            private static bool PrepareForPiping(string specification, double nominalDiameter, string sUnit, string sService)
            {
                List<NamedItem> namedItems = CreateUnitAndService(sUnit, sService);
    
                NetworkSystem pipeline;
                ItemStatus status = NetworkSystem.CreatePipingNetworkSystem(out pipeline, namedItems, specification, nominalDiameter, "1", null);
                if (ItemStatus.Failed != status)
                {
                    if (status == ItemStatus.Success)
                        StandardPreferencesUtilities.SetPipingDiscipline();
                    else if (status == ItemStatus.Duplicate)
                        StandardPreferencesUtilities.SetActivePipingNetworkSystem(pipeline);
    
                    return true;
                }
    
                return false;
            }
    
            private static List<NamedItem> CreateUnitAndService(string sUnit, string sService)
            {
                //Create a new unit.
                NamedItem unit;
                if (ItemStatus.Failed == NamedItem.CreateUnit(out unit, sUnit, null))
                    return null;
    
                //Create a new service.
                NamedItem service;
                if (ItemStatus.Failed == NamedItem.CreateService(out service, sService, null))
                    return null;
    
                List<NamedItem> namedItems = new List<NamedItem>();
                namedItems.Add(unit);
                namedItems.Add(service);
    
                return namedItems;
            }
    
            private DPoint3d GetLocationForNozzle(EquipmentComponent vessel)
            {
                ComponentPropertiesGetter pGetter = new ComponentPropertiesGetter(vessel);
                double height = double.Parse(pGetter.GetPropertyValue("HEIGHT"));
                double headHeight = double.Parse(pGetter.GetPropertyValue("HEAD_HEIGHT"));
    
                DPoint3d location = vessel.Origin;
                location.Z = location.Z + height + headHeight;
    
                return location;
            }
    
            private DPoint3d CreateFlange(string specification, double nominalDiameter, double x, double flangeZ, double boltZ, double gasketZ, NozzleComponent nozzle)
            {
                PipeFlangeComponentData flangeData = new PipeFlangeComponentData(PipeFlangeType.WELD_NECK_FLANGE, specification, nominalDiameter);
                PipeFlangeComponent flange = new PipeFlangeComponent(new DPoint3d(x, 0, flangeZ), flangeData, Math.PI / 2, DrawingView.ViewFront, true);
    
                //Add Bolt.
                Dictionary<string, string> selProps1 = new Dictionary<string, string>();
                selProps1.Add("BOLT_LENGTH", "82.6");
                selProps1.Add("NUMBER_OF_BOLTS", "8");
                flange.AddBolt1(new DPoint3d(x, 0, boltZ), Math.PI / 2, DrawingView.ViewLeft, true, selProps1);
    
                //Add Gasket.
                Dictionary<string, string> selProps2 = new Dictionary<string, string>();
                selProps2.Add("LENGTH", "3.2");
                flange.AddGasket1(new DPoint3d(x, 0, gasketZ), Math.PI / 2, DrawingView.ViewLeft, true, selProps2);
    
                //Add the above nozzle that this Flange will connect to.
                flange.AddComponent1ToConnectTo(0, nozzle, 0);
    
                //Create will take care of connecting this Flange to the nozzle using the bolt and gasket specified.
                flange.Create();
    
                return flange.GetEndPoint(1);
            }
        }
    }
    

  • 先修改了一套管线编号然后生成了一根管

    然后又改了一套管线编号再生成了一根管

    代码如下

    if (PrepareForPiping(specification, nominalDiameter, "u1", "s1"))
                {
                    double length1 = 2000;
    
                    //第一套编号及管
                    Bentley.ECObjects.Instance.ECInstanceList Instances = DgnUtilities.GetInstancesFromDgn("PIPING_NETWORK_SYSTEM", true);
                    if (Instances != null && Instances.Count > 0)
                    {
                        foreach (IDgnECInstance pipeInst in Instances)
                        {
                            pipeInst.SetAsString("PBB", "IWW");
                            pipeInst.SetAsString("PBS", "315001");
                            pipeInst.SetAsString("NUMBER", "1");
                            pipeInst.SetAsString("SPECIFICATION", "mEX-OPM");
    
                            pipeInst.WriteChanges();
                        }
                    }
                    for (int i = 0; i < 1; i++)
                    {
                        PipeComponentData pipe1Data = new PipeComponentData(specification, nominalDiameter);
                        pipe1Data.SetProperty("LENGTH", length1.ToString());
                        PipeComponent pipe1 = new PipeComponent(origin, pipe1Data, System.Math.PI * (-90) / 180, DrawingView.ViewFront, false);
                        pipe1.Create();
                    }
                    //第二套编号及管
                    Instances = DgnUtilities.GetInstancesFromDgn("PIPING_NETWORK_SYSTEM", true);
                    if (Instances != null && Instances.Count > 0)
                    {
                        foreach (IDgnECInstance pipeInst in Instances)
                        {
                            pipeInst.SetAsString("PBB", "CA");
                            pipeInst.SetAsString("PBS", "315001");
                            pipeInst.SetAsString("NUMBER", "2");
                            pipeInst.SetAsString("SPECIFICATION", "mEX-OPM");
    
                            pipeInst.WriteChanges();
                        }
                    }
                    for (int i = 0; i < 1; i++)
                    {
                        origin = new DPoint3d(1000 * UorPerMas, 0, 0);
                        PipeComponentData pipe1Data = new PipeComponentData(specification, nominalDiameter);
                        pipe1Data.SetProperty("LENGTH", length1.ToString());
                        PipeComponent pipe1 = new PipeComponent(origin, pipe1Data, System.Math.PI * (-90) / 180, DrawingView.ViewFront, false);
                        pipe1.Create();
                    }
                }

    我该如何操作让两个管分别在两套管线编号下呢。

    我想要达到的效果是在第一套管线编号及管线已经完成的情况下,如何新建一套管线编号并修改它然后在新建的这套编号下生成管,且新建的管线编号不会对前一套修改。

  • 你修改一个的话,不论改多少遍,还是一个。如果想要两个,需要创建两个。

    创建PIPING_NETWORK_SYSTEM的例子您参考一下:C:\Program Files\Bentley\OpenPlant CONNECT Edition\OpenPlantModeler\SDKExamples\MiscellaneousExample

    Answer Verified By: Dongyu Zhao 

  • 我在创建管线的时候如何让管线在指定的那套管线编号下生成呢

    比如现在我已经成功完成了两套编号的创建

    创建第一根管想让它在第一套编号下生成

    创建第二根管想让它在第二套编号下生成

    创建第三根管又想让它在第一套编号下生成

    这种频繁变化的情况,该如何处理。

    或者管线生成的时候,有没有方法 选择(是选择不是创建)管线编号。

Reply Children
No Data