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); }
private ECPropertyReader(Element element, string className) { if (element == null) { throw new ArgumentNullException("element"); } // !проверка, что элемент добавлен в модель if (element.DgnModel == null || element.ElementId == null) { throw new ArgumentException(string.Format( "Couldn't read EC-properties from non-model element")); } this.element = element; using (DgnECInstanceCollection ecInstances = DgnECManager.Manager. GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses)) { ecInst = ecInstances.FirstOrDefault(x => x.ClassDefinition.Name == className); // EnumString.ToString(instType)); } }
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; } }