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 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; }