OpenRoads Designer CONNECT Edition SDK Help

Place a cell in plan or profile model with scaling

The below code snippet shows how to place a cell in plan or profile model with scaling. The scaling factor defines here the size of the cell.


//Required References
using System;
using System.Diagnostics;
using Bentley.DgnPlatformNET;
using Bentley.MstnPlatformNET;
using Bentley.GeometryNET;
using Bentley.Interop.MicroStationDGN;
using Bentley.CifNET.GeometryModel.SDK;
using BMI = Bentley.MstnPlatformNET.InteropServices;

public bool PlaceACellInPlanOrProfileWithScaling()
        {
        
            DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
            if (dgnModel.IsPlanModel() || dgnModel.IsProfileModel())
            {
                //Set the parameters for cell creation
                string cellName = "Arrow - PvtMrk - Left";
                double scale = 1.0;
                DPoint3d dpOrigin = new DPoint3d(1000, 1000, 0);
                Angle angle = Angle.FromDegrees(0.0);

                //Place cell in active model
                CellElement cell1 = PlaceCellFromLibrary(cellName, dpOrigin, angle.Radians, scale);
                if (cell1 != null)
                {
                    return true;
                }
            }
            return false;
        }


public CellElement PlaceCellFromLibrary(string cellName, DPoint3d origin, double xyRotationRadians, double scale)
        {
            CellElement cellElement = null;
            try
            {
                //Create origin point
                Bentley.Interop.MicroStationDGN.Point3d iopOrigin = new Bentley.Interop.MicroStationDGN.Point3d
                {
                    X = origin.X,
                    Y = origin.Y,
                    Z = origin.Z
                };
                //create scale point
                Bentley.Interop.MicroStationDGN.Point3d iopScale = new Bentley.Interop.MicroStationDGN.Point3d
                {
                    X = scale,
                    Y = scale,
                    Z = scale
                };
                //create rotation matrix
                Bentley.Interop.MicroStationDGN.Matrix3d iopRotation = BMI.Utilities.ComApp.Matrix3dFromAxisAndRotationAngle(2, xyRotationRadians);

                //Create cell element
                cellElement = BMI.Utilities.ComApp.CreateCellElement2(cellName, ref iopOrigin, ref iopScale, true, ref iopRotation);
                if (cellElement != null)
                {
                    //Add cell to active model
                    BMI.Utilities.ComApp.ActiveModelReference.AddElement(cellElement);
                }
                return cellElement;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                return cellElement;
            }
        }