public static List <string> RetrieveSchemas() { DgnECManager Manager = DgnECManager.Manager; DgnModel model = Session.Instance.GetActiveDgnModel(); return((List <string>)Manager.DiscoverSchemasForModel(model, ReferencedModelScopeOption.All, false)); }
private static ECSchema RetrieveSchema(DgnFile File, FindInstancesScope scope) { DgnECManager Manager = DgnECManager.Manager; DgnModel model = Session.Instance.GetActiveDgnModel(); var schemas = (List <string>)Manager.DiscoverSchemasForModel(model, ReferencedModelScopeOption.All, false); var schemaString = schemas.Where(x => x.Contains(schemaName)).FirstOrDefault(); if (schemaString != null) { try { IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); return((ECSchema)schema); } catch (Exception e) { return(null); } } else { return(CreateSchema(File)); } }
/*---------------------------------------------------------------------------------**//** * Create Grouped hole element. * @bsimethod Bentley Systems * /*--------------+---------------+---------------+---------------+---------------+------*/ public static Element CreateElement(DPoint3d start, DPoint3d opposite) { DgnModel model = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel(); //Create Solid shape element from actual start and opposite points. ShapeElement solidShape = CreateShapeElement(model, start, opposite); //Get holes for grouped hole element. ElementAgenda holes; PopulateHolesAgenda(out holes, start, opposite, model); //Create actual grouped hole element with given solid and holes. GroupedHoleElement groupedHoleElement = new GroupedHoleElement(model, solidShape, holes); //Set line color. ElementPropertiesSetter pSetter = new ElementPropertiesSetter(); pSetter.SetColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveColor().Index); pSetter.Apply(groupedHoleElement); //Add fill color. if (PlaceGroupedHoleForm.GetAddFillColor()) { groupedHoleElement.AddSolidFill((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index, false); } return(groupedHoleElement); }
private void InitSiteLocation(DgnModel model) { var site = ExporterHelper.GetSiteInfo(model) ?? SiteInfo.CreateDefault(); txtLongitude.Text = Math.Round(site.Longitude, 6).ToString(CultureInfo.InvariantCulture); txtLatitude.Text = Math.Round(site.Latitude, 6).ToString(CultureInfo.InvariantCulture); txtHeight.Text = Math.Round(site.Height, 6).ToString(CultureInfo.InvariantCulture); txtRotation.Text = Math.Round(site.Rotation, 6).ToString(CultureInfo.InvariantCulture); }
public static IECSchema GetSchema(DgnModel model) { if (model == null) { throw new ArgumentNullException(); } return(GetSchema(model.GetDgnFile())); }
public static List <CellHeaderElement> FindSPDSElementsByInstance(DgnModel model) { if (model == null) { throw new ArgumentNullException(); } DgnFile file = model.GetDgnFile(); DgnFileOwner fileOwner = new DgnFileOwner(file); IECSchema Schema = null; { // todo Правильная инициализация схемы: Schema = DgnECManager.Manager?.LocateDeliveredSchema( ECHelper.SCHEMA_NAME, VrnMajor, VrnMinor, SchemaMatchType.LatestCompatible, file); } if (Schema == null) { return(null); } IECClass commonClass = Schema.GetClass(ECCLASS_COMMON_NAME); ECQuery query = new ECQuery(commonClass); var modelConn = DgnModelRepositoryConnection.CreateConnection( new DgnECConnectionOptions(), fileOwner, model); var instColl = DgnECManager.Manager.FindDgnECInstances(modelConn, query); if (instColl == null) { return(null); } List <CellHeaderElement> resList = new List <CellHeaderElement>(); foreach (var item in instColl) { Element element; if (DgnECManager.TryGetElementInfo(modelConn, item.InstanceId, out element)) { if (element is CellHeaderElement) { resList.Add(element as CellHeaderElement); } } } return(resList); }
/*---------------------------------------------------------------------------------**//** * Calculates points from start and opposite points and creates a shape * @bsimethod Bentley Systems * /*--------------+---------------+---------------+---------------+---------------+------*/ private static ShapeElement CreateShapeElement(DgnModel model, DPoint3d start, DPoint3d opposite) { DPoint3d[] points = new DPoint3d[5]; points[0] = points[1] = points[3] = points[4] = start; points[2] = opposite; points[1].X = opposite.X; points[3].Y = opposite.Y; ShapeElement shape = new ShapeElement(model, null, points); return(shape); }
public static DgnAttachment AsDgnAttachmentOf(this DgnModel model, DgnModel owner) { if (owner == null || model == owner) { return(null); } foreach (DgnAttachment attach in owner.GetDgnAttachments()) { if (attach.GetDgnModel() == model) { return(attach); } } return(null); }
public NodeUpdateResult WriteItems ( NodeUpdateContext updateContext, [DgnModelProvider, Replicatable] object ElementsToWriteTo, [Replicatable] string ItemTypeLibraryName, [Replicatable] string ItemTypeName, [Replicatable(-1, true)] string[] PropertyName, [Replicatable(-1, true)] string[] PropertyValue ) { try { DgnFile dgnFile = Session.Instance.GetActiveDgnFile(); DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); Feature feat = (Feature)ElementsToWriteTo; long eleID = feat.Element.ID; Bentley.DgnPlatformNET.Elements.Element ele = dgnModel.FindElementById(new ElementId(ref eleID)); ItemTypeLibrary itl = ItemTypeLibrary.FindByName(ItemTypeLibraryName, dgnFile); ItemType itemType = itl.GetItemTypeByName(ItemTypeName); CustomItemHost customItemHost = new CustomItemHost(ele, false); IDgnECInstance ecInstance = customItemHost.GetCustomItem(ItemTypeLibraryName, ItemTypeName); if (ecInstance == null) { ecInstance = customItemHost.ApplyCustomItem(itemType); } for (int i = 0; i < PropertyName.Length; i++) { ecInstance.SetString(PropertyName[i].ToString(), PropertyValue[i].ToString()); } ecInstance.WriteChanges(); } catch (Exception ex) { return(new NodeUpdateResult.TechniqueException(ex)); } return(NodeUpdateResult.Success); }
/// <summary> /// Gets the ids of all visible model objects that can be converted to Speckle /// </summary> /// <param name="model"></param> /// <param name="converter"></param> /// <returns></returns> public static List <string> ConvertibleObjects(this DgnModel model, ISpeckleConverter converter) { var objs = new List <string>(); if (model == null) { return(new List <string>()); } var graphicElements = model.GetGraphicElements(); var elementEnumerator = (ModelElementsEnumerator)graphicElements.GetEnumerator(); var elements = graphicElements.Where(el => !el.IsInvisible).Select(el => el).ToList(); foreach (var element in elements) { if (converter.CanConvertToSpeckle(element) && !element.IsInvisible) { objs.Add(element.ElementId.ToString()); } } objs = graphicElements.Where(el => !el.IsInvisible).Select(el => el.ElementId.ToString()).ToList(); return(objs); }
/*---------------------------------------------------------------------------------**//** * Calculates start and opposite points of holes and creates them. * @bsimethod Bentley Systems * /*--------------+---------------+---------------+---------------+---------------+------*/ private static void PopulateHolesAgenda(out ElementAgenda holes, DPoint3d start, DPoint3d opposite, DgnModel model) { holes = new ElementAgenda(); //How many holes are required by the user. Possible options are only 1, 2 and 4. int numHoles = PlaceGroupedHoleForm.GetNumberOfHoles(); System.Collections.Generic.List <DPoint3d> holeStarts = new List <DPoint3d>(); System.Collections.Generic.List <DPoint3d> holeEnds = new List <DPoint3d>(); if (1 == numHoles) //One hole in the middle of the shape. { double xFactor = (opposite.X - start.X) / 3; double yFactor = (start.Y - opposite.Y) / 3; holeStarts.Add(new DPoint3d(start.X + xFactor, start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, opposite.Y + yFactor, opposite.Z)); } else if (2 == numHoles) //Two holes. { double xFactor = (opposite.X - start.X) / 5; double yFactor = (start.Y - opposite.Y) / 5; holeStarts.Add(new DPoint3d(start.X + xFactor, start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(start.X + (2 * xFactor), opposite.Y + yFactor, opposite.Z)); holeStarts.Add(new DPoint3d(opposite.X - (2 * xFactor), start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, opposite.Y + yFactor, opposite.Z)); } else //if(4 == numHoles) Four holes. { double xFactor = (opposite.X - start.X) / 5; double yFactor = (start.Y - opposite.Y) / 5; holeStarts.Add(new DPoint3d(start.X + xFactor, start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(start.X + (2 * xFactor), start.Y - (2 * yFactor), opposite.Z)); holeStarts.Add(new DPoint3d(opposite.X - (2 * xFactor), start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, start.Y - (2 * yFactor), opposite.Z)); holeStarts.Add(new DPoint3d(start.X + xFactor, opposite.Y + (2 * yFactor), start.Z)); holeEnds.Add(new DPoint3d(start.X + (2 * xFactor), opposite.Y + yFactor, opposite.Z)); holeStarts.Add(new DPoint3d(opposite.X - (2 * xFactor), opposite.Y + (2 * yFactor), start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, opposite.Y + yFactor, opposite.Z)); } //Create hole elements and populate the agenda. for (int i = 0; i < numHoles; i++) { ShapeElement holeShape = CreateShapeElement(model, holeStarts[i], holeEnds[i]); holes.Insert(holeShape, true); } }
public static bool IsDgnAttachmentOf(this DgnModel model, DgnModel owner) { return(model.AsDgnAttachmentOf(owner) != null); }
public static DgnModelRef AsDgnModelRef(this BCOM.ModelReference model) { return(DgnModel.GetModelRef((IntPtr)model.MdlModelRefP())); }
public NodeUpdateResult PlaceParametricCell ( NodeUpdateContext updateContext, [Replicatable, DgnModelProvider] IPoint PlacementPoint, [Replicatable] IPlane PlacementPlane, [In] string CellLibraryPath, [In] string CellDefinitionName, [In] string CellVariation, [Replicatable(-1, true)] string[] CellVariableNames, [Replicatable(-1, true)] string[] CellVariableValues ) { this.ClearAndErase(updateContext); // Remove old feature if (this.ReplicationIndex == 0 && CellLibraryPath == null || CellDefinitionName == null) { return new NodeUpdateResult.IncompleteInputs(CellLibraryPath, CellDefinitionName); } else { //NEED TO IMPLEMENT A SHARED CELL UPDATE IF UpdateSharedCell == true; THEN ONCE UPDATED SET THE PARAMETER TO FALSE SO THAT THE NEXT PLACED CELL DOESN'T UPDATE THE SHARED CELL AGAIN //Check if cell library is attached and if not attach it if (this.ReplicationIndex == 0 && MSApp.IsCellLibraryAttached == false || MSApp.AttachedCellLibrary.FullName != CellLibraryPath) { MSApp.AttachCellLibrary(CellLibraryPath); } DgnFile activeDgnFile = Session.Instance.GetActiveDgnFile(); DgnModel activeModel = Session.Instance.GetActiveDgnModel(); DgnModel cellModel = null; ParametricCellElement pCell = null; ParametricCellDefinitionElement cellDef = ParametricCellDefinitionElement.FindByName(CellDefinitionName, activeDgnFile); if (cellDef == null) //cell not in active file, load from attached cell library { var opts = CellLibraryOptions.Include3d | CellLibraryOptions.IncludeAllLibraries | CellLibraryOptions.IncludeParametric; var libs = new CellLibraryCollection(opts); foreach (var lib in libs) { if (CellDefinitionName.Equals(lib.Name)) { StatusInt status; cellModel = lib.File.LoadRootModelById(out status, lib.File.FindModelIdByName(lib.Name), true, false, true); break; } } if (null == cellModel) //Cell definition (model) doesn't exist in the cell model file { LsBuilder lsBuilder = new LsBuilder(); Ls ls = lsBuilder.AppendLineLiteral("Error loading cell definition. Check cell definition name and library are correct.").ToLs(); return new NodeUpdateResult.TechniqueFailureMessage(ls); } else { var hdlr = DgnComponentDefinitionHandler.GetForModel(cellModel); var status = hdlr.DefinitionModelHandler.CreateCellDefinition(activeDgnFile); if (ParameterStatus.Success == status) cellDef = ParametricCellDefinitionElement.FindByName(CellDefinitionName, activeDgnFile); else { LsBuilder lsBuilder = new LsBuilder(); Ls ls = lsBuilder.AppendLineLiteral("Error creating cell definition in active file.").ToLs(); return new NodeUpdateResult.TechniqueFailureMessage(ls); } } } try { pCell = ParametricCellElement.Create(cellDef, CellVariation, activeModel); //Cell origin point - adjusted for U.O.R. double uor = MSApp.ActiveModelReference.UORsPerMasterUnit; DPoint3d cellOrigin = DPoint3d.Multiply(uor, PlacementPoint.GetDPoint3d()); pCell.Origin = cellOrigin; DTransform3d dTransform3D = PlacementPlane.GetDTransform3d(); DPlane3d dPlane3D = PlacementPlane.GetDPlane3d(); DMatrix3d dMatrix3D = new DMatrix3d(dTransform3D); pCell.Rotation = dMatrix3D; //pCell.IsInvisible = true; //We don't want multiple elements visible pCell.AddToModel(); //Add to the model so we can assign variables and retrieve the element //Assign custom variables if they exist if (CellVariableNames != null && CellVariableValues != null) { IECClass ecClass = pCell.Parameters.ClassDefinition; IDgnECInstance eci = DgnECManager.FindECInstanceOnElement(pCell, ecClass); for (int i = 0; i < CellVariableNames.Length; ++i) { IEnumerator<IECPropertyValue> props = eci.GetEnumerator(false, true); while (props.MoveNext()) { if (props.Current.Property.DisplayLabel == CellVariableNames[i].ToString()) { props.Current.StringValue = CellVariableValues[i].ToString(); } } } eci.WriteChanges(); } IElement ele = MSApp.ActiveModelReference.GetLastValidGraphicalElement(); SetElement(ele); //Commit as a GC feature pCell.Dispose(); //Clean up the memory of pCell, only 'ele' will be retained } catch (Exception ex) { return new NodeUpdateResult.TechniqueException(ex); } return NodeUpdateResult.Success; } }
public ParametricCellProcessor(IList<Element> elements, DgnModel dgnModel) { this.elements = elements ?? throw new ArgumentNullException(nameof(elements)); this.dgnModel = dgnModel ?? throw new ArgumentNullException(nameof(dgnModel)); }
public NodeUpdateResult DropParametricCellToOrphanCell ( NodeUpdateContext updateContext, [Replicatable, DgnModelProvider] object ParametricCell, [Out, Replicatable] ref string ElementPath ) { try { Feature feat = ParametricCell as Feature; long id = feat.Element.ID; GCModel gcmodel = feat.GCModel(); DgnModel model = Session.Instance.GetActiveDgnModel(); Element element = model.FindElementById(new ElementId(ref id)); if (element is ParametricCellElement instance) { MessageCenter.Instance.StatusMessage = $"Parametric cell: {instance.CellDefinition.CellName}"; List<Element> extracted = new List<Element>(); CellHeaderElement group = (CellHeaderElement)null; int n = 0; try { ParametricCellProcessor processor = new ParametricCellProcessor(extracted, model); ElementGraphicsOutput.Process(instance, processor); group = CellHeaderElement.CreateOrphanCellElement(model, n.ToString(), extracted); group.AddToModel(); IElement fetch = MSApp.ActiveModelReference.GetLastValidGraphicalElement(); this.SetElement(fetch); Bentley.Interop.MicroStationDGN.Element ele = this.GetElement(); string elementPath; DgnTools.TryGetPersistentPath(ele, out elementPath); ElementPath = elementPath.ToString(); } finally { if (null != extracted) { foreach (Element el in extracted) { el.Dispose(); group.Dispose(); } } } } else { LsBuilder lsBuilder = new LsBuilder(); Ls ls = lsBuilder.AppendLineLiteral("Input element is not of the correct type.").ToLs(); return new NodeUpdateResult.TechniqueFailureMessage(ls); } } catch (Exception ex) { return new NodeUpdateResult.TechniqueException(ex); } return NodeUpdateResult.Success; }