public static DgnECInstanceCollection GetElementProperties(Element element) { DgnECManager manager = DgnECManager.Manager; var properties = manager.GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses); return(properties); }
/// <summary> /// Writes the stream states to the current schema. /// </summary> /// <param name="streamStates"></param> public static void WriteStreamStateList(DgnFile File, List <StreamState> streamStates) { DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = RetrieveSchema(File, scope); IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; using (DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget)) { foreach (IDgnECInstance instance in instances) { instance.Delete(); } } DgnECInstanceEnabler instanceEnabler = Manager.ObtainInstanceEnabler(File, ecClass); var data = JsonConvert.SerializeObject(streamStates) as string; StandaloneECDInstance _instance = instanceEnabler.SharedWipInstance; _instance.SetAsString(propertyName, data); instanceEnabler.CreateInstanceOnFile(File, _instance); }
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)); } }
public static Element TryGetElement(DgnModelRepositoryConnection modelConn, string instanceId) { Element element; DgnECManager.TryGetElementInfo(modelConn, instanceId, out element); return(element); }
public static ECSchema RetrieveSchema() { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); return((ECSchema)schema); }
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); }
public static DgnECInstanceCollection RetrieveInstances() { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget); return(instances); }
public void FindInstances() { DgnECManager manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.Element, true)); ECQuery query = new ECQuery(Extension.Utilities.GetActiveModelAllClasses()); query.SelectClause.SelectAllProperties = true; manager.FindInstances(scope, query); //每次寻找实例不对啊,需要打开Property窗口后才能正确显示 using (DgnECInstanceCollection ecInstances = manager.FindInstances(scope, query)) { foreach (var ecin in ecInstances) { foreach (IECProperty itemProp in ecin.ClassDefinition.Properties(false)) { var instanceitem = new Instance(); instanceitem.ClassName = ecin.ClassDefinition.DisplayLabel; instanceitem.PropertyName = itemProp.Name; string type = itemProp.Type.Name.ToLower(); instanceitem.TypeName = type; IECPropertyValue propvalue = ecin.GetPropertyValue(itemProp.Name); switch (type) { case "string": instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : ""; break; case "boolean": instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : ""; break; case "int": instanceitem.PropertyValue = (propvalue != null) ? propvalue.IntValue.ToString() : ""; break; case "double": instanceitem.PropertyValue = (propvalue != null) ? propvalue.DoubleValue.ToString() : ""; break; } Instances.Add(instanceitem); } } } }
public static IDgnECInstance RetrieveInstance(StreamState streamState) { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget); var instance = instances.Where(x => x["Id"].StringValue == streamState.Stream.id).FirstOrDefault(); return(instance); }
/// <summary> /// Writes the stream states to the current schema. /// </summary> /// <param name="streamStates"></param> public static void WriteStreamStateList(List <StreamState> streamStates) { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); if (schema == null) { schema = StreamStateListSchema.GetSchema(); } IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; using (DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget)) { foreach (IDgnECInstance instance in instances) { instance.Delete(); } } DgnECInstanceEnabler instanceEnabler = Manager.ObtainInstanceEnabler(File, ecClass); foreach (var streamState in streamStates) { var data = JsonConvert.SerializeObject(streamState) as string; StandaloneECDInstance instance = instanceEnabler.SharedWipInstance; instance.SetAsString("Id", streamState.Stream.id); instance.SetAsString("StreamData", data); instanceEnabler.CreateInstanceOnFile(File, instance); } }
public static ECSchema AddSchema() { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; ECSchema newSchema = new ECSchema(schemaName, 1, 0, schemaName); ECClass streamStateClass = new ECClass(className); ECProperty streamIdProp = new ECProperty("Id", ECObjects.StringType); ECProperty streamDataProp = new ECProperty("StreamData", ECObjects.StringType); streamStateClass.Add(streamIdProp); streamStateClass.Add(streamDataProp); newSchema.AddClass(streamStateClass); var status = Manager.ImportSchema(newSchema, File, new ImportSchemaOptions()); if (status != SchemaImportStatus.Success) { return(null); } return(newSchema); }
/// <summary> /// Returns all the speckle stream states present in the custom schema (schema is attached to file). /// </summary> /// <param name="schema"></param> /// <returns></returns> public static List <StreamState> ReadState(ECSchema schema) { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; try { ECQuery readWidget = new ECQuery(schema.GetClass(className)); readWidget.SelectClause.SelectAllProperties = true; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); var states = new List <StreamState>(); using (DgnECInstanceCollection ecInstances = Manager.FindInstances(scope, readWidget)) { foreach (IDgnECInstance instance in ecInstances) { var id = instance["Id"].StringValue; var streamStateData = instance["StreamData"].StringValue; var state = JsonConvert.DeserializeObject <StreamState>(streamStateData); states.Add(state); } } if (states != null) { states.ForEach(x => x.Initialise(true)); } return(states); } catch (Exception e) { return(new List <StreamState>()); } }
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; } }