public void ClassSelectionChanged()
        {
            PropsToWrite.Clear();
            if (string.IsNullOrEmpty(SelectedClass))
            {
                return;
            }
            string schemaName;
            int    marjornum, minornum;

            if (!Extension.Utilities.TryParseSchemaString(SelectedSchema, out schemaName, out marjornum, out minornum))
            {
                return;
            }
            BDE.FindInstancesScope scope   = BDE.FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new BDE.FindInstancesScopeOption());
            BES.IECSchema          schema  = BDE.DgnECManager.Manager.LocateSchemaInScope(scope, schemaName, marjornum, minornum, BES.SchemaMatchType.Exact);
            BES.IECClass           ecClass = schema.GetClass(SelectedClass);

            foreach (BES.IECProperty ecProp in ecClass.Properties(false))
            {
                PropsToWrite.Add(new PropertyToWrite {
                    PropertyName = ecProp.Name, PropertyType = ecProp.Type.Name, PropertyValue = ""
                });
            }
        }
Ejemplo n.º 2
0
        protected override bool OnDataButton(BD.DgnButtonEvent ev)
        {
            BD.HitPath hitPath = DoLocate(ev, true, 1);
            if (null != hitPath)
            {
                InstanceToWrite instanceInfo = (WriteInstanceOnElementView.Instance.DataContext as WriteInstanceOnElementViewModel).GetInstanceToWrite();
                if (string.IsNullOrEmpty(instanceInfo.SchemaName) || string.IsNullOrEmpty(instanceInfo.ClassName) || instanceInfo.Properties.Count == 0)
                {
                    mc.StatusPrompt = "请先选择要附加的class";
                    return(false);
                }
                BDEC.FindInstancesScope scope  = BDEC.FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new BDEC.FindInstancesScopeOption());
                BES.IECSchema           schema = BDEC.DgnECManager.Manager.LocateSchemaInScope(scope, instanceInfo.SchemaName, instanceInfo.MajorVersion, instanceInfo.MinorVersion, BES.SchemaMatchType.Exact);
                BDE.Element             ele    = hitPath.GetHeadElement();

                BES.ECClass class1 = schema.GetClass(instanceInfo.ClassName) as BES.ECClass;
                BDEC.DgnECInstanceEnabler instanceEnabler = BDEC.DgnECManager.Manager.ObtainInstanceEnabler(Program.GetActiveDgnFile(), class1);
                BEI.StandaloneECDInstance instance        = instanceEnabler.SharedWipInstance;
                foreach (var pInfo in instanceInfo.Properties)
                {
                    switch (pInfo.PropertyType.ToLower())
                    {
                    case "string":
                        instance.MemoryBuffer.SetStringValue(pInfo.PropertyName, -1, pInfo.GetValueAsString());
                        break;

                    case "boolean":
                        instance.MemoryBuffer.SetBooleanValue(pInfo.PropertyName, -1, pInfo.GetValueAsBoolean());
                        break;

                    case "int":
                        instance.MemoryBuffer.SetIntegerValue(pInfo.PropertyName, -1, pInfo.GetValueAsInt());
                        break;

                    case "double":
                        instance.MemoryBuffer.SetDoubleValue(pInfo.PropertyName, -1, pInfo.GetValueAsDouble());
                        break;
                    }
                }
                instanceEnabler.CreateInstanceOnElement(ele, instance, false);
                mc.StatusPrompt  = "附加完成";
                mc.StatusMessage = $"将{instanceInfo.ClassName}附加到ID:{ele.ElementId}物体上";
            }

            return(true);
        }