private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder subBuilder = new SchemaBuilder(subSchemaId);
                subBuilder.SetSchemaName("MassParameterMaps");
                subBuilder.AddSimpleField(s_HostParameterName, typeof(string));
                subBuilder.AddSimpleField(s_MassParameterName, typeof(string));
                subSchema = subBuilder.Finish();

                SchemaBuilder sBuilder = new SchemaBuilder(schemaId);
                sBuilder.SetSchemaName("MassConfiguration");
                sBuilder.AddSimpleField(s_HostCategory, typeof(string));
                sBuilder.AddSimpleField(s_MassCategory, typeof(string));
                sBuilder.AddSimpleField(s_ParameterUpdateType, typeof(string));
                sBuilder.AddSimpleField(s_SetDefaultHeight, typeof(bool));
                FieldBuilder fBuilder = sBuilder.AddSimpleField(s_UserHeight, typeof(double));
                fBuilder.SetUnitType(UnitType.UT_Length);

                fBuilder = sBuilder.AddArrayField(s_ParameterMaps, typeof(Entity));
                fBuilder.SetSubSchemaGUID(subSchemaId);

                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Get or create the schema from class definition
        /// </summary>
        /// <returns></returns>
        public Schema GetOrCreateSchema()
        {
            var schema = Schema.Lookup(SchemaId);

            if (null != schema)
            {
                return(schema);
            }
            var builder = new SchemaBuilder(SchemaId);

            builder.SetSchemaName(SchemaName);

            //Get all attributed properties to build the schema
            Properties.ToList()
            .ForEach(pp =>
            {
                builder.AddSimpleField(pp.Item1, pp.Item2.PropertyType);
            });

            //Get all attributed fields to build the schema
            Fields.ToList()
            .ForEach(fp =>
            {
                builder.AddSimpleField(fp.Item1, fp.Item2.FieldType);
            });
            return(builder.Finish());
        }
Exemplo n.º 3
0
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder sBuilder = new SchemaBuilder(schemaId);
                sBuilder.SetSchemaName("LinkedSourceInfo");
                sBuilder.AddSimpleField(s_SourceCategory, typeof(string));
                sBuilder.AddSimpleField(s_LinkedSourceId, typeof(string));
                FieldBuilder fBuilder = sBuilder.AddSimpleField(s_SourceCentroid, typeof(XYZ));
#if RELEASE2021
                fBuilder.SetSpec(SpecTypeId.Length);
#else
                fBuilder.SetUnitType(UnitType.UT_Length);
#endif
                fBuilder = sBuilder.AddSimpleField(s_MassHeight, typeof(double));
#if RELEASE2021
                fBuilder.SetSpec(SpecTypeId.Length);
#else
                fBuilder.SetUnitType(UnitType.UT_Length);
#endif
                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Mass Data Storage Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
        /// <summary>
        /// 初始化
        /// </summary>
        public void Recorder()
        {
            SchemaBuilder builder = new SchemaBuilder(_data.Guid);

            builder.SetWriteAccessLevel(AccessLevel.Public);
            builder.SetReadAccessLevel(AccessLevel.Public);
            builder.SetSchemaName(_data.SchemaName);
            foreach (RecordData item in _data.Fields)
            {
                if (item.Type == typeof(string) || item.Type == typeof(bool))
                {
                    builder.AddSimpleField(item.Key, item.Type);
                }
                else
                {
                    FieldBuilder fb = builder.AddSimpleField(item.Key, item.Type);
                    fb.SetUnitType(UnitType.UT_Length);
                }
            }
            _schema = builder.Finish();
            Entity ent = new Entity(_schema);

            foreach (RecordData item in _data.Fields)
            {
                ent.Set(item.Key, item.Value, DisplayUnitType.DUT_METERS);
            }
            // 仓库
            DataStorage st = DataStorage.Create(_doc);

            st.Name = "myStorage";
            st.SetEntity(ent);
        }
Exemplo n.º 5
0
        public FieldBuilder CreateField(SchemaBuilder schemaBuilder, PropertyInfo propertyInfo)
        {
            FieldBuilder fieldBuilder;

            var iRevitEntity = propertyInfo.PropertyType.GetInterface("IRevitEntity");

            if (iRevitEntity != null)
            {
                AttributeExtractor <SchemaAttribute> schemaAttributeExtractor =
                    new AttributeExtractor <SchemaAttribute>();

                fieldBuilder = schemaBuilder
                               .AddSimpleField(propertyInfo.Name, typeof(Entity));
                var subSchemaAttribute =
                    schemaAttributeExtractor
                    .GetAttribute(propertyInfo.PropertyType);
                fieldBuilder
                .SetSubSchemaGUID(subSchemaAttribute.GUID);
            }
            else
            {
                fieldBuilder =
                    schemaBuilder.AddSimpleField(propertyInfo.Name, propertyInfo.PropertyType);
            }

            return(fieldBuilder);
        }
Exemplo n.º 6
0
        public Schema CreateSchema(Guid schemaGuid)
        {
            Schema schema = Schema.Lookup(schemaGuid);

            if (schema == null)
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
                schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
                //schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor);
                //schemaBuilder.SetVendorId("CBIM");

                FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField("XYZ", typeof(XYZ));
                fieldBuilder.SetUnitType(UnitType.UT_Length);
                fieldBuilder.SetDocumentation("I'm XYZ");

                FieldBuilder fieldBuilder1 = schemaBuilder.AddSimpleField("Double", typeof(double));
                fieldBuilder1.SetUnitType(UnitType.UT_Length);
                fieldBuilder1.SetDocumentation("I'm Double");

                //Ilist<string>
                FieldBuilder fieldBuilder2 = schemaBuilder.AddArrayField("List", typeof(string));
                //fieldBuilder2.SetUnitType(UnitType.UT_Length);
                fieldBuilder2.SetDocumentation("I'm Ilist<string>");

                //IDictinary<string,int>
                FieldBuilder fieldBuilder3 = schemaBuilder.AddMapField("Dictionary", typeof(string), typeof(int));
                //fieldBuilder3.SetUnitType(UnitType.UT_Length);
                fieldBuilder3.SetDocumentation("I'm IDictinary<string,int>");

                //SubSchema
                //Guid guid = new Guid("f9b00633-6aa9-47a6-acea-7f74407b9ea5");
                //Schema subSchema = Schema.Lookup(guid);
                //if (subSchema == null)
                //{
                //    SchemaBuilder subSchemaBuilder = new SchemaBuilder(guid);
                //    subSchemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                //    subSchemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

                //    FieldBuilder sub = subSchemaBuilder.AddSimpleField("subInt", typeof(int));
                //    sub.SetDocumentation("I'm Int");

                //    subSchemaBuilder.SetSchemaName("SubSchema");
                //    subSchema = subSchemaBuilder.Finish();
                //}
                //Entity subEntity = new Entity(subSchema);
                //subEntity.Set<int>(subSchema.GetField("subInt"), 11);

                //FieldBuilder fieldBuilder4 = schemaBuilder.AddSimpleField("SubEntity", typeof(Entity));
                //fieldBuilder4.SetDocumentation("I'm SubSchema");


                schemaBuilder.SetSchemaName("SchemaName");
                schema = schemaBuilder.Finish();
            }

            return(schema);
        }
Exemplo n.º 7
0
        public static void SetEntity(Document doc)
        {
            DataStorage dataStorage = null;

            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("start");
                dataStorage = DataStorage.Create(doc);
                trans.Commit();
            }

            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("start");

                // 创建数据模式 相当于class
                SchemaBuilder schemaBulider = new SchemaBuilder(Guid.NewGuid());

                schemaBulider.SetReadAccessLevel(AccessLevel.Public);
                schemaBulider.SetWriteAccessLevel(AccessLevel.Public);
                schemaBulider.SetSchemaName("myFistSchema");
                schemaBulider.SetDocumentation("Data store for socket related info in a wall");

                // 相当于创建 class 里面的 字段
                FieldBuilder fieldBuilder01 = schemaBulider.AddSimpleField("SocketLocation", typeof(XYZ));
                fieldBuilder01.SetUnitType(UnitType.UT_Length);
                FieldBuilder fieldBuilder02 = schemaBulider.AddSimpleField("SocketNumber", typeof(string));

                Schema _schema = schemaBulider.Finish();

                // 创建数据实体
                Entity entity = new Entity(_schema);

                // 为实例字段赋值
                entity.Set("SocketNumber", dataStorage.Name);

                dataStorage.SetEntity(entity);

                trans.Commit();
            }

            List <Guid> listSchemaGuid = dataStorage.GetEntitySchemaGuids().ToList();
            Schema      schema         = Schema.Lookup(listSchemaGuid[0]);
            Entity      selEntity      = dataStorage.GetEntity(schema);

            string testStr  = selEntity.Get <string>("SocketNumber");
            XYZ    oriPoint = selEntity.Get <XYZ>("SocketLocation", DisplayUnitType.DUT_MILLIMETERS);

            string showSuccess = testStr + "\n" + oriPoint.ToString() + "\n" + "entity测试成功";

            showSuccess.TaskDialogErrorMessage();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 给column中写入entity
        /// </summary>
        public void SetEntityToBaseWallLoop(Document doc, Guid guid, ElementId elementId, string writeValue)
        {
            #region 设置entity 将上述生成的各个停车区域点集 存入地库外墙线线圈group的entity

            Schema schema = Schema.Lookup(guid);//guid为固定guid
            if (schema == null)
            {
                SchemaBuilder schemaBulider = new SchemaBuilder(schemaGuid);
                schemaBulider.SetReadAccessLevel(AccessLevel.Public);
                schemaBulider.SetWriteAccessLevel(AccessLevel.Public);
                schemaBulider.SetSchemaName("canParkingPlaces");
                schemaBulider.SetDocumentation("该类架构用于存储各个可停车区域的点集。");

                FieldBuilder fieldBuilder = schemaBulider.AddSimpleField("axisNumber", typeof(string));
                schema = schemaBulider.Finish();
            }
            #endregion

            #region entity赋值

            Entity entity = new Entity(schema);

            entity.Set <string>("axisNumber", writeValue);

            doc.GetElement(elementId).SetEntity(entity);

            #endregion
        }
Exemplo n.º 9
0
        public void AssociateLoadToFoundation(FamilyInstance foundation, PointLoad pointLoad)
        {
            using (Transaction trans = new Transaction(_doc, "Create Extensible Store"))
            {
                trans.Start();

                SchemaBuilder builder = new SchemaBuilder(Guids.FOUNDATION_SHEMA_GUID);

                builder.SetReadAccessLevel(AccessLevel.Public);
                builder.SetWriteAccessLevel(AccessLevel.Public);

                builder.SetSchemaName("PointLoad");

                builder.SetDocumentation("The point load linked to the foundation");

                // Create field1
                FieldBuilder fieldBuilder1 = builder.AddSimpleField("PointLoad", typeof(ElementId));

                // Register the schema object
                Schema schema = builder.Finish();

                Field  pointLoadField = schema.GetField("PointLoad");
                Entity ent            = new Entity(schema);

                ent.Set(pointLoadField, pointLoad.Id);

                foundation.SetEntity(ent);

                trans.Commit();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Creates a simple type field builder by field name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public static FieldBuilder CreateSimpleField <T>(this SchemaBuilder schemaBuilder, string fieldName,
                                                         UnitType unitType, string desc = null)
        {
            if (schemaBuilder == null)
            {
                throw new ArgumentNullException(nameof(schemaBuilder));
            }

            if (fieldName == null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            var result = schemaBuilder.AddSimpleField(fieldName, typeof(T));

            result.SetUnitType(unitType);

            if (desc == null)
            {
                desc = fieldName;
            }

            result.SetDocumentation(desc);

            return(result);
        }
Exemplo n.º 11
0
        public static Schema CreateSchema()
        {
            Schema schema    = null;
            Schema subSchema = null;

            try
            {
                SchemaBuilder subSchemaBuilder = new SchemaBuilder(subSchemaId);
                subSchemaBuilder.SetSchemaName("ElementIds");
                subSchemaBuilder.AddArrayField(s_ElementIds, typeof(ElementId));
                subSchema = subSchemaBuilder.Finish();

                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("ColorEditorSetting");
                schemaBuilder.AddSimpleField(s_BCFPath, typeof(string));
                var mapField = schemaBuilder.AddMapField(s_ColoredElementIds, typeof(string), typeof(Entity));
                mapField.SetSubSchemaGUID(subSchemaId);
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema for Color Scheme Editor.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Exemplo n.º 12
0
        private void AssociateLevelToNewSheet(Level level, ViewSheet sheet)
        {
            SchemaBuilder builder = new SchemaBuilder(Guids.SHEET_SHEMA_GUID);

            builder.SetReadAccessLevel(AccessLevel.Public);
            builder.SetWriteAccessLevel(AccessLevel.Public);

            builder.SetSchemaName("AssociatedLevel");

            builder.SetDocumentation("Associated level");

            // Create field1
            FieldBuilder fieldBuilder1 = builder.AddSimpleField("Level", typeof(ElementId));

            // Register the schema object
            Schema schema = builder.Finish();

            Field levelId = schema.GetField("Level");

            Entity ent = new Entity(schema);

            ent.Set(levelId, level.Id);

            sheet.SetEntity(ent);
        }
Exemplo n.º 13
0
        public Schema GetTooltipSchema()
        {
            Schema schema = Schema.Lookup(TooltipSchemaWrapper.SchemaGuid);

            if (schema != null)
            {
                return(schema);
            }
            SchemaBuilder schemaBuilder = new SchemaBuilder(SchemaGuid);

            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
            schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
            schemaBuilder.SetSchemaName("RevitTipSettings");
            schemaBuilder.SetDocumentation("this is a schema to store tool tip info");
            foreach (SettingsProperty property in m_settings.Properties)
            {
                schemaBuilder.AddSimpleField(property.Name, typeof(string));
            }
            try
            {
                schema = schemaBuilder.Finish();
            }
            catch (Exception e) {
                throw e;
            }
            return(schema);
        }
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                var subBuilder = new SchemaBuilder(subSchemaId);
                subBuilder.SetSchemaName("MapItemInfoList");
                subBuilder.AddSimpleField(s_SourceModelId, typeof(string));
                subBuilder.AddSimpleField(s_RecipientModelId, typeof(string));
                subBuilder.AddSimpleField(s_MapItemType, typeof(string));
                subBuilder.AddSimpleField(s_SourceItemId, typeof(int));
                subBuilder.AddSimpleField(s_RecipientItemId, typeof(int));
                subBuilder.AddSimpleField(s_SourceItemName, typeof(string));
                subBuilder.AddSimpleField(s_RecipientItemName, typeof(string));
                subSchema = subBuilder.Finish();

                var sBuilder = new SchemaBuilder(schemaId);
                sBuilder.SetSchemaName("ViewConfiguration");
                sBuilder.AddSimpleField(s_WorksetVisibility, typeof(bool));
                var fBuilder = sBuilder.AddArrayField(s_MapItems, typeof(Entity));
                fBuilder.SetSubSchemaGUID(subSchemaId);

                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Exemplo n.º 15
0
        // CRUD Services for managing Regular rule data stored using Revit's ExtensibleStorage API

        private static Schema GetRegularSchema()
        {
            // A method that handles constructing the regularSchema
            Schema ConstructRegularSchema()
            {
                // The schema doesn't exist; we need to define the schema for the first time
                SchemaBuilder schemaBuilder = new SchemaBuilder(Guid.NewGuid());

                schemaBuilder.SetSchemaName("RegularSchema");
                schemaBuilder.SetApplicationGUID(RegularApp.RegularApplicationGUID);
                schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
                schemaBuilder.SetVendorId("OGRN");

                // Constructing the scheme for regexRules stored in ExtensibleStorage
                schemaBuilder.AddSimpleField("SerializedRegexRule", typeof(string));
                return(schemaBuilder.Finish());
            }

            IList <Schema> allSchemas    = Schema.ListSchemas();
            Schema         regularSchema = allSchemas.FirstOrDefault(x => x.SchemaName == "RegularSchema");

            // If it already exists, we return it. If not, we make a new one from scratch
            return(regularSchema ?? ConstructRegularSchema());
        }
Exemplo n.º 16
0
 public override Schema GetOrCreateSchema()
 {
     SchemaBuilder sb = new SchemaBuilder(SchemaGuid);
      sb.SetSchemaName(SchemaName);
      sb.AddSimpleField("someBool", typeof(bool));
      return sb.Finish();
 }
Exemplo n.º 17
0
        private void AssociateTagToPointLoad(PointLoad pl, IndependentTag tag)
        {
            using (Transaction trans = new Transaction(_doc, "Create Extensible Store"))
            {
                trans.Start();

                SchemaBuilder builder = new SchemaBuilder(Guids.POINTLOAD_SHEMA_GUID);

                builder.SetReadAccessLevel(AccessLevel.Public);
                builder.SetWriteAccessLevel(AccessLevel.Public);

                builder.SetSchemaName("Tag");

                builder.SetDocumentation("The tag linked to the point load");

                // Create field1
                FieldBuilder fieldBuilder1 = builder.AddSimpleField("Tag", typeof(ElementId));

                // Register the schema object
                Schema schema = builder.Finish();

                Field  tagField = schema.GetField("Tag");
                Entity ent      = new Entity(schema);

                ent.Set(tagField, tag.Id);
                pl.SetEntity(ent);

                trans.Commit();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        ///     Creates a simple type field builder by field name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="dcrp"></param>
        /// <returns></returns>
        public static void AddSimpleField <T>(this SchemaBuilder schemaBuilder, string fieldName, UnitType unitType, string dcrp = null)
        {
            if (schemaBuilder is null)
            {
                throw new ArgumentNullException(nameof(schemaBuilder));
            }

            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            if (!typeof(T).IsPrimitive)
            {
                throw new NotSupportedException(nameof(T));
            }

            var result = schemaBuilder.AddSimpleField(fieldName, typeof(T));

            result.SetUnitType(unitType);

            if (dcrp is null)
            {
                dcrp = fieldName;
            }

            result.SetDocumentation(dcrp);
        }
Exemplo n.º 19
0
        private static void BuildNewSchema(Autodesk.Revit.DB.Document doc)
        {
            using (Transaction trn_1 = new Transaction(doc, "Build a new schema"))
            {
                if (trn_1.Start() == TransactionStatus.Started)
                {
                    SchemaBuilder builder = new SchemaBuilder(new Guid("2B195204-1C04-4538-8881-AD22FA697B41"));
                    // Set up accessibility levels.
                    builder.SetReadAccessLevel(AccessLevel.Public);
                    builder.SetWriteAccessLevel(AccessLevel.Vendor);
                    builder.SetVendorId("ADSK");
                    builder.SetSchemaName("Test");

                    // Create a field to store an ElementId
                    FieldBuilder elmIdField = builder.AddSimpleField("SelElmIds", typeof(ElementId));
                    elmIdField.SetDocumentation("Add the selected element's id to the created element's id");

                    Schema schema = builder.Finish();

                    if (trn_1.Commit() == TransactionStatus.Committed)
                    {
                    }
                    else
                    {
                        trn_1.RollBack();
                    }
                }
            }
        }
Exemplo n.º 20
0
        public virtual Schema GetSchema()
        {
            Schema result = Schema.Lookup(Guid);

            if (result != null)
            {
                return(result);
            }

            if (Guid == Guid.Empty || string.IsNullOrWhiteSpace(Name))
            {
                return(null);
            }

            SchemaBuilder schemaBuilder = new SchemaBuilder(Guid);

            schemaBuilder.SetReadAccessLevel(readAccessLevel);
            schemaBuilder.SetWriteAccessLevel(writeAccessLevel);
            schemaBuilder.SetVendorId(vendorId);

            if (!string.IsNullOrWhiteSpace(fieldName))
            {
                FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField(fieldName, typeof(string));
                if (!string.IsNullOrWhiteSpace(fieldDocumentation))
                {
                    fieldBuilder.SetDocumentation(fieldDocumentation);
                }
            }

            schemaBuilder.SetSchemaName(Name);
            return(schemaBuilder.Finish());
        }
        /// <summary>
        /// Проверяю наличие в документа хранилища настроек, если нет - создаю
        /// </summary>
        private void StorageCheckIn()
        {
            Entity ent = null;
            Schema sch = null;

            try
            {
                sch = Schema.Lookup(new Guid(schemaGuid));
                ent = _storageElem.GetEntity(sch);
                if (ent.Schema != null)
                {
                    return;
                }
            }
            catch { }



            SchemaBuilder sb = new SchemaBuilder(new Guid(schemaGuid));

            sb.SetReadAccessLevel(AccessLevel.Public);
            sb.SetWriteAccessLevel(AccessLevel.Public);

            FieldBuilder fb1 = sb.AddSimpleField(fieldFolder, typeof(string));
            FieldBuilder fb2 = sb.AddSimpleField(fieldConstructor, typeof(string));

            sb.SetSchemaName("YayBatchPrintSettings");

            sch = sb.Finish();

            using (Transaction t = new Transaction(_doc))
            {
                t.Start("Создание настроек печати");


                Field f1 = sch.GetField(fieldFolder);
                Field f2 = sch.GetField(fieldConstructor);

                Entity ent2 = new Entity(sch);
                ent2.Set <string>(f1, @"C:\PDF Print");
                ent2.Set <string>(f2, "<Номер листа>_<Имя листа>.pdf");

                _storageElem.SetEntity(ent2);

                t.Commit();
            }
        }
Exemplo n.º 22
0
        public override Schema GetOrCreateSchema()
        {
            SchemaBuilder sb = new SchemaBuilder(SchemaGuid);

            sb.SetSchemaName(SchemaName);
            sb.AddSimpleField("someBool", typeof(bool));
            return(sb.Finish());
        }
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("ViewDepth");
                schemaBuilder.AddSimpleField(s_ViewId, typeof(ElementId));
                schemaBuilder.AddSimpleField(s_ViewOverriden, typeof(bool));
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(schema);
        }
Exemplo n.º 24
0
        public static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("ProjectReplicator");
                schemaBuilder.AddSimpleField(s_GoogleSheetId, typeof(string));
                schemaBuilder.AddSimpleField(s_RevitDocId, typeof(string));
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Exemplo n.º 25
0
        public static Schema CreateAnalysisSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(analysisSchemaId);
                schemaBuilder.SetSchemaName("ViewAnalysisSchema");
                schemaBuilder.AddSimpleField(s_dataFileName, typeof(string));
                schemaBuilder.AddSimpleField(s_overwriteData, typeof(bool));
                schemaBuilder.AddSimpleField(s_dataResolution, typeof(string));
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create BCF Color schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Exemplo n.º 26
0
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("DoorMonitor");
                schemaBuilder.AddSimpleField(s_IsMonitorOn, typeof(bool));
                schemaBuilder.AddSimpleField(s_ProjectState, typeof(string));
                schemaBuilder.AddSimpleField(s_IsStateCA, typeof(bool));
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                string message = "Cannot Create Schema: " + ex.Message;
            }
            return(schema);
        }
Exemplo n.º 27
0
        private static Schema CreateConfigSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder sBuilder = new SchemaBuilder(configSchemaId);
                sBuilder.SetSchemaName("KeynoteEditorConfiguration");
                sBuilder.AddSimpleField(s_ProjectId, typeof(string));
                sBuilder.AddSimpleField(s_KeynoteSetId, typeof(string));

                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a schema for the configuration./n" + ex.Message, "Create Configuration Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
        private static Schema CreateSchema(string parameterName)
        {
            SchemaBuilder builder = new SchemaBuilder(Guid.NewGuid());

            builder.SetReadAccessLevel(AccessLevel.Public);
            builder.SetWriteAccessLevel(AccessLevel.Public);
            builder.AddSimpleField(parameterName, typeof(string));
            builder.SetSchemaName("ExtExtension");
            return(builder.Finish());
        }
Exemplo n.º 29
0
        /// <summary>
        /// Retrieve an existing EstoreFile schema or
        /// create a new one if it does not exist yet.
        /// </summary>
        /// <returns>EstoreFile schema</returns>
        static Schema GetSchema()
        {
            Schema schema = Schema.Lookup(CmdStore._schema_guid);

            if (null == schema)
            {
                SchemaBuilder schemaBuilder
                    = new SchemaBuilder(_schema_guid);

                schemaBuilder.SetSchemaName("EstoreFile");

                // Allow anyone to read and write the object

                schemaBuilder.SetReadAccessLevel(
                    AccessLevel.Public);

                schemaBuilder.SetWriteAccessLevel(
                    AccessLevel.Public);

                // Create fields

                FieldBuilder fieldBuilder = schemaBuilder
                                            .AddSimpleField("Filename", typeof(string));

                fieldBuilder.SetDocumentation("File name");

                fieldBuilder = schemaBuilder.AddSimpleField(
                    "Folder", typeof(string));

                fieldBuilder.SetDocumentation("Original file folder path");

                fieldBuilder = schemaBuilder.AddArrayField(
                    "Data", typeof(byte));

                fieldBuilder.SetDocumentation("Stored file data");

                // Register the schema

                schema = schemaBuilder.Finish();
            }
            return(schema);
        }
Exemplo n.º 30
0
        private static Schema CreateFamilySchema()
        {
            Schema schema = null;

            try
            {
                var sBuilder = new SchemaBuilder(familySchemaId);
                sBuilder.SetSchemaName("LinkedFamilyInfo");
                sBuilder.AddSimpleField(s_SourceLinkInstanceId, typeof(ElementId));
                sBuilder.AddSimpleField(s_SourceSymbolId, typeof(ElementId));
                sBuilder.AddSimpleField(s_LinkedSymbolId, typeof(ElementId));

                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create family schema.\n" + ex.Message, "Create Family Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Exemplo n.º 31
0
        private Schema Initialize()
        {
            var e = new SchemaBuilder(_schemaGuid);

            e.SetReadAccessLevel(AccessLevel.Vendor);
            e.SetWriteAccessLevel(AccessLevel.Vendor);
            e.SetVendorId(VendorId);
            e.SetDocumentation("");
            e.AddSimpleField("json", typeof(string));
            return(e.Finish());
        }
 private static Schema GetSchema()
 {
     Schema schema = Schema.Lookup(s_schemaId);
     if (schema == null)
     {
         SchemaBuilder classificationBuilder = new SchemaBuilder(s_schemaId);
         classificationBuilder.SetSchemaName("IFCClassification");
         classificationBuilder.AddSimpleField(s_ClassificationName, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationSource, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationEdition, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Day, typeof(Int32));
         classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Month, typeof(Int32));
         classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Year, typeof(Int32));
         classificationBuilder.AddSimpleField(s_ClassificationLocation, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationFieldName, typeof(string));
         schema = classificationBuilder.Finish();
     }
     return schema;
 }
 /// <summary>
 /// the IFC Classification Manager
 /// </summary>
 public IFCClassificationMgr()
 {
     if (m_schema == null)
     {
         m_schema = Schema.Lookup(s_schemaId);
     }
     if (m_schema == null)
     {
         SchemaBuilder classificationBuilder = new SchemaBuilder(s_schemaId);
         classificationBuilder.SetSchemaName("IFCClassification");
         classificationBuilder.AddSimpleField(s_ClassificationName, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationSource, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationEdition, typeof(string));
         classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Day, typeof(Int32));
         classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Month, typeof(Int32));
         classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Year, typeof(Int32));
         classificationBuilder.AddSimpleField(s_ClassificationLocation, typeof(string));
         m_schema = classificationBuilder.Finish();
     }
 }
            /// <summary>
            /// Retrieve our extensible storage schema 
            /// or optionally create a new one if it does
            /// not yet exist.
            /// </summary>
            public static Schema GetSchema(
                bool create = true)
            {
                Schema schema = Schema.Lookup( SchemaGuid );

                if( create && null == schema )
                {
                  SchemaBuilder schemaBuilder =
                new SchemaBuilder( SchemaGuid );

                  schemaBuilder.SetSchemaName(
                "JtNamedGuiStorage" );

                  schemaBuilder.AddSimpleField(
                "Guid", typeof( Guid ) );

                  schema = schemaBuilder.Finish();
                }
                return schema;
            }
    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    {
      UIDocument uiDoc = commandData.Application.ActiveUIDocument;
      Document doc = uiDoc.Document;

      // Create transaction for working with schema

      Transaction trans = new Transaction(doc, "Extensible Storage");
      trans.Start();

      // Select a wall element

      Wall wall = null;

      try
      {
        Reference r = uiDoc.Selection.PickObject(ObjectType.Element,
          new WallSelectionFilter());

        wall = doc.GetElement(r) as Wall;
      }
      catch (Autodesk.Revit.Exceptions.OperationCanceledException)
      {
        message = "Nothing selected; please select a wall to attach extensible data to.";
        return Result.Failed;
      }

      Debug.Assert(null != wall, "expected a wall to be selected");

      if (null == wall)
      {
        message = "Please select a wall to attach extensible data to.";
        return Result.Failed;
      }

      // Create a schema builder

      SchemaBuilder builder = new SchemaBuilder(_guid);

      // Set read and write access levels

      builder.SetReadAccessLevel(AccessLevel.Public);
      builder.SetWriteAccessLevel(AccessLevel.Public);

      // Note: if this was set as vendor or application access, 
      // we would have been additionally required to use SetVendorId

      // Set name to this schema builder

      builder.SetSchemaName("WallSocketLocation");
      builder.SetDocumentation("Data store for socket related info in a wall");

      // Create field1

      FieldBuilder fieldBuilder1 =
        builder.AddSimpleField("SocketLocation", typeof(XYZ));

      // Set unit type

      fieldBuilder1.SetUnitType(UnitType.UT_Length);

      // Add documentation (optional)

      // Create field2

      FieldBuilder fieldBuilder2 =
        builder.AddSimpleField("SocketNumber", typeof(string));

      //fieldBuilder2.SetUnitType(UnitType.UT_Custom);

      // Register the schema object

      Schema schema = builder.Finish();

      // Create an entity (object) for this schema (class)

      Entity ent = new Entity(schema);
      Field socketLocation = schema.GetField("SocketLocation");
      ent.Set<XYZ>(socketLocation, new XYZ(2, 0, 0), DisplayUnitType.DUT_METERS);

      Field socketNumber = schema.GetField("SocketNumber");
      ent.Set<string>(socketNumber, "200");

      wall.SetEntity(ent);

      // Now create another entity (object) for this schema (class)

      Entity ent2 = new Entity(schema);
      Field socketNumber1 = schema.GetField("SocketNumber");
      ent2.Set<String>(socketNumber1, "400");
      wall.SetEntity(ent2);

      // Note: this will replace the previous entity on the wall 

      // List all schemas in the document

      string s = string.Empty;
      IList<Schema> schemas = Schema.ListSchemas();
      foreach (Schema sch in schemas)
      {
        s += "\r\nSchema Name: " + sch.SchemaName;
      }
      TaskDialog.Show("Schema details", s);

      // List all Fields for our schema

      s = string.Empty;
      Schema ourSchema = Schema.Lookup(_guid);
      IList<Field> fields = ourSchema.ListFields();
      foreach (Field fld in fields)
      {
        s += "\r\nField Name: " + fld.FieldName;
      }
      TaskDialog.Show("Field details", s);

      // Extract the value for the field we created

      Entity wallSchemaEnt = wall.GetEntity(Schema.Lookup(_guid));

      XYZ wallSocketPos = wallSchemaEnt.Get<XYZ>(
        Schema.Lookup(_guid).GetField("SocketLocation"),
        DisplayUnitType.DUT_METERS);

      s = "SocketLocation: " + Format.PointString(wallSocketPos);

      string wallSocketNumber = wallSchemaEnt.Get<String>(
        Schema.Lookup(_guid).GetField("SocketNumber"));

      s += "\r\nSocketNumber: " + wallSocketNumber;

      TaskDialog.Show("Field values", s);

      trans.Commit();

      return Result.Succeeded;
    }
Exemplo n.º 36
0
        private void ModifyObjects(List<RevitObject> existingObjects, List<ElementId> existingElems, Document doc, Guid uniqueId, bool profileWarning, string nickName, int runId)
        {
            // Create new Revit objects.
            //List<LyrebirdId> newUniqueIds = new List<LyrebirdId>();

            // Determine what kind of object we're creating.
            RevitObject ro = existingObjects[0];


            #region Normal Origin based FamilyInstance
            // Modify origin based family instances
            if (ro.Origin != null)
            {
                // Find the FamilySymbol
                FamilySymbol symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);

                LevelType lt = FindLevelType(ro.TypeName, doc);

                GridType gt = FindGridType(ro.TypeName, doc);

                if (symbol != null || lt != null)
                {
                    // Get the hosting ID from the family.
                    Family fam = null;
                    Parameter hostParam = null;
                    int hostBehavior = 0;

                    try
                    {
                        fam = symbol.Family;
                        hostParam = fam.get_Parameter(BuiltInParameter.FAMILY_HOSTING_BEHAVIOR);
                        hostBehavior = hostParam.AsInteger();
                    }
                    catch{}

                    //FamilyInstance existingInstance = doc.GetElement(existingElems[0]) as FamilyInstance;
                    
                    using (Transaction t = new Transaction(doc, "Lyrebird Modify Objects"))
                    {
                        t.Start();
                        try
                        {
                            Schema instanceSchema = null;
                            try
                            {
                                instanceSchema = Schema.Lookup(instanceSchemaGUID);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (instanceSchema == null)
                            {
                                SchemaBuilder sb = new SchemaBuilder(instanceSchemaGUID);
                                sb.SetWriteAccessLevel(AccessLevel.Vendor);
                                sb.SetReadAccessLevel(AccessLevel.Public);
                                sb.SetVendorId("LMNA");

                                // Create the field to store the data in the family
                                FieldBuilder guidFB = sb.AddSimpleField("InstanceID", typeof(string));
                                guidFB.SetDocumentation("Component instance GUID from Grasshopper");
                                // Create a filed to store the run number
                                FieldBuilder runIDFB = sb.AddSimpleField("RunID", typeof(int));
                                runIDFB.SetDocumentation("RunID for when multiple runs are created from the same data");
                                // Create a field to store the GH component nickname.
                                FieldBuilder nickNameFB = sb.AddSimpleField("NickName", typeof(string));
                                nickNameFB.SetDocumentation("Component NickName from Grasshopper");

                                sb.SetSchemaName("LMNAInstanceGUID");
                                instanceSchema = sb.Finish();
                            }

                            FamilyInstance fi = null;
                            XYZ origin = XYZ.Zero;

                            if (lt != null)
                            {
                                for (int i = 0; i < existingObjects.Count; i++)
                                {
                                    RevitObject obj = existingObjects[i];
                                    Level lvl = doc.GetElement(existingElems[i]) as Level;

                                    if (lvl.ProjectElevation != (UnitUtils.ConvertToInternalUnits(obj.Origin.Z, lengthDUT)))
                                    {
                                        double offset = lvl.Elevation - lvl.ProjectElevation;
                                        lvl.Elevation = (UnitUtils.ConvertToInternalUnits(obj.Origin.Z + offset, lengthDUT));
                                    }

                                    SetParameters(lvl, obj.Parameters, doc);
                                }
                            }
                            else if (hostBehavior == 0)
                            {

                                for (int i = 0; i < existingObjects.Count; i++)
                                {
                                    RevitObject obj = existingObjects[i];
                                    fi = doc.GetElement(existingElems[i]) as FamilyInstance;

                                    // Change the family and symbol if necessary
                                    if (fi != null && (fi.Symbol.Family.Name != symbol.Family.Name || fi.Symbol.Name != symbol.Name))
                                    {
                                        try
                                        {
                                            fi.Symbol = symbol;
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                    }

                                    try
                                    {
                                        // Move family
                                        origin = new XYZ(UnitUtils.ConvertToInternalUnits(obj.Origin.X, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Z, lengthDUT));
                                        if (fi != null)
                                        {
                                            LocationPoint lp = fi.Location as LocationPoint;
                                            if (lp != null)
                                            {
                                                XYZ oldLoc = lp.Point;
                                                XYZ translation = origin.Subtract(oldLoc);
                                                ElementTransformUtils.MoveElement(doc, fi.Id, translation);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        TaskDialog.Show("Error", ex.Message);
                                    }

                                    // Rotate
                                    if (obj.Orientation != null)
                                    {
                                        if (Math.Round(Math.Abs(obj.Orientation.Z - 0), 10) < double.Epsilon)
                                        {
                                            XYZ orientation = fi.FacingOrientation;
                                            orientation = orientation.Multiply(-1);
                                            XYZ incomingOrientation = new XYZ(obj.Orientation.X, obj.Orientation.Y, obj.Orientation.Z);
                                            XYZ normalVector = new XYZ(0, -1, 0);

                                            double currentAngle = 0;
                                            if (orientation.X < 0 && orientation.Y < 0)
                                            {
                                                currentAngle = (2 * Math.PI) - normalVector.AngleTo(orientation);
                                            }
                                            else if (orientation.Y == 0 && orientation.X < 0)
                                            {
                                                currentAngle = 1.5 * Math.PI;
                                            }
                                            else if (orientation.X < 0)
                                            {
                                                currentAngle = (Math.PI - normalVector.AngleTo(orientation)) + Math.PI;
                                            }
                                            else
                                            {
                                                currentAngle = normalVector.AngleTo(orientation);
                                            }

                                            double incomingAngle = 0;
                                            if (incomingOrientation.X < 0 && incomingOrientation.Y < 0)
                                            {
                                                incomingAngle = (2 * Math.PI) - normalVector.AngleTo(incomingOrientation);
                                            }
                                            else if (incomingOrientation.Y == 0 && incomingOrientation.X < 0)
                                            {
                                                incomingAngle = 1.5 * Math.PI;
                                            }
                                            else if (incomingOrientation.X < 0)
                                            {
                                                incomingAngle = (Math.PI - normalVector.AngleTo(incomingOrientation)) + Math.PI;
                                            }
                                            else
                                            {
                                                incomingAngle = normalVector.AngleTo(incomingOrientation);
                                            }
                                            double angle = incomingAngle - currentAngle;
                                            //TaskDialog.Show("Test", "CurrentAngle: " + currentAngle.ToString() + "\nIncoming Angle: " + incomingAngle.ToString() + "\nResulting Rotation: " + angle.ToString() +
                                            //    "\nFacingOrientation: " + orientation.ToString() + "\nIncoming Orientation: " + incomingOrientation.ToString());
                                            Line axis = Line.CreateBound(origin, origin + XYZ.BasisZ);
                                            ElementTransformUtils.RotateElement(doc, fi.Id, axis, angle);
                                        }
                                    }

                                    SetParameters(fi, obj.Parameters, doc);
                                }
                            }
                            else
                            {
                                for (int i = 0; i < existingObjects.Count; i++)
                                {
                                    RevitObject obj = existingObjects[i];
                                    fi = doc.GetElement(existingElems[i]) as FamilyInstance;

                                    // Change the family and symbol if necessary
                                    if (fi.Symbol.Family.Name != symbol.Family.Name || fi.Symbol.Name != symbol.Name)
                                    {
                                        try
                                        {
                                            fi.Symbol = symbol;
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                    }

                                    origin = new XYZ(UnitUtils.ConvertToInternalUnits(obj.Origin.X, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Z, lengthDUT));

                                    // Find the level
                                    List<LyrebirdPoint> lbPoints = new List<LyrebirdPoint> { obj.Origin };
                                    Level lvl = GetLevel(lbPoints, doc);

                                    // Get the host
                                    if (hostBehavior == 5)
                                    {
                                        // Face based family.  Find the face and create the element
                                        XYZ normVector = new XYZ(obj.Orientation.X, obj.Orientation.Y, obj.Orientation.Z);
                                        XYZ faceVector;
                                        if (obj.FaceOrientation != null)
                                        {
                                            faceVector = new XYZ(obj.FaceOrientation.X, obj.FaceOrientation.Y, obj.FaceOrientation.Z);
                                        }
                                        else
                                        {
                                            faceVector = XYZ.BasisZ;
                                        }
                                        Face face = FindFace(origin, normVector, doc);
                                        if (face != null)
                                        {
                                            if (face.Reference.ElementId == fi.HostFace.ElementId)
                                            {
                                                //fi = doc.Create.NewFamilyInstance(face, origin, faceVector, symbol);
                                                // Just move the host and update the parameters as needed.
                                                LocationPoint lp = fi.Location as LocationPoint;
                                                if (lp != null)
                                                {
                                                    XYZ oldLoc = lp.Point;
                                                    XYZ translation = origin.Subtract(oldLoc);
                                                    ElementTransformUtils.MoveElement(doc, fi.Id, translation);
                                                }

                                                SetParameters(fi, obj.Parameters, doc);
                                            }
                                            else
                                            {
                                                FamilyInstance origInst = fi;
                                                fi = doc.Create.NewFamilyInstance(face, origin, faceVector, symbol);

                                                foreach (Parameter p in origInst.Parameters)
                                                {
                                                    try
                                                    {
                                                        Parameter newParam = fi.get_Parameter(p.GUID);
                                                        if (newParam != null)
                                                        {
                                                            switch (newParam.StorageType)
                                                            {
                                                                case StorageType.Double:
                                                                    newParam.Set(p.AsDouble());
                                                                    break;
                                                                case StorageType.ElementId:
                                                                    newParam.Set(p.AsElementId());
                                                                    break;
                                                                case StorageType.Integer:
                                                                    newParam.Set(p.AsInteger());
                                                                    break;
                                                                case StorageType.String:
                                                                    newParam.Set(p.AsString());
                                                                    break;
                                                                default:
                                                                    newParam.Set(p.AsString());
                                                                    break;
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }
                                                // Delete the original instance of the family
                                                doc.Delete(origInst.Id);

                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // typical hosted family.  Can be wall, floor, roof or ceiling.
                                        ElementId host = FindHost(origin, hostBehavior, doc);
                                        if (host != null)
                                        {
                                            if (host.IntegerValue != fi.Host.Id.IntegerValue)
                                            {
                                                // We'll have to recreate the element
                                                FamilyInstance origInst = fi;
                                                fi = doc.Create.NewFamilyInstance(origin, symbol, doc.GetElement(host), lvl, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                foreach (Parameter p in origInst.Parameters)
                                                {
                                                    try
                                                    {
                                                        Parameter newParam = fi.LookupParameter(p.Definition.Name);
                                                        if (newParam != null)
                                                        {
                                                            switch (newParam.StorageType)
                                                            {
                                                                case StorageType.Double:
                                                                    newParam.Set(p.AsDouble());
                                                                    break;
                                                                case StorageType.ElementId:
                                                                    newParam.Set(p.AsElementId());
                                                                    break;
                                                                case StorageType.Integer:
                                                                    newParam.Set(p.AsInteger());
                                                                    break;
                                                                case StorageType.String:
                                                                    newParam.Set(p.AsString());
                                                                    break;
                                                                default:
                                                                    newParam.Set(p.AsString());
                                                                    break;
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }
                                                // Delete the original instance of the family
                                                doc.Delete(origInst.Id);

                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
                                            }

                                            else
                                            {
                                                // Just move the host and update the parameters as needed.
                                                LocationPoint lp = fi.Location as LocationPoint;
                                                if (lp != null)
                                                {
                                                    XYZ oldLoc = lp.Point;
                                                    XYZ translation = origin.Subtract(oldLoc);
                                                    ElementTransformUtils.MoveElement(doc, fi.Id, translation);
                                                }

                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);
                                            }
                                        }
                                    }

                                    // Assign the parameters
                                    SetParameters(fi, obj.Parameters, doc);
                                }
                                // delete the host finder
                                ElementId hostFinderFamily = hostFinder.Symbol.Family.Id;
                                doc.Delete(hostFinder.Id);
                                doc.Delete(hostFinderFamily);
                                hostFinder = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }

                        t.Commit();
                    }
                }
            }

            #endregion


            #region Adaptive Components
            FamilyInstance adaptInst;
            try
            {
                adaptInst = doc.GetElement(existingElems[0]) as FamilyInstance;
            }
            catch
            {
                adaptInst = null;
            }
            if (adaptInst != null && AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(adaptInst))
            {
                // Find the FamilySymbol
                FamilySymbol symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);

                if (symbol != null)
                {
                    using (Transaction t = new Transaction(doc, "Lyrebird Modify Objects"))
                    {
                        t.Start();
                        try
                        {
                            // Create the Schema for the instances to store the GH Component InstanceGUID and the path
                            Schema instanceSchema = null;
                            try
                            {
                                instanceSchema = Schema.Lookup(instanceSchemaGUID);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (instanceSchema == null)
                            {
                                SchemaBuilder sb = new SchemaBuilder(instanceSchemaGUID);
                                sb.SetWriteAccessLevel(AccessLevel.Vendor);
                                sb.SetReadAccessLevel(AccessLevel.Public);
                                sb.SetVendorId("LMNA");

                                // Create the field to store the data in the family
                                FieldBuilder guidFB = sb.AddSimpleField("InstanceID", typeof(string));
                                guidFB.SetDocumentation("Component instance GUID from Grasshopper");
                                // Create a filed to store the run number
                                FieldBuilder runIDFB = sb.AddSimpleField("RunID", typeof(int));
                                runIDFB.SetDocumentation("RunID for when multiple runs are created from the same data");
                                // Create a field to store the GH component nickname.
                                FieldBuilder nickNameFB = sb.AddSimpleField("NickName", typeof(string));
                                nickNameFB.SetDocumentation("Component NickName from Grasshopper");

                                sb.SetSchemaName("LMNAInstanceGUID");
                                instanceSchema = sb.Finish();
                            }

                            try
                            {
                                for (int i = 0; i < existingElems.Count; i++)
                                {
                                    RevitObject obj = existingObjects[i];

                                    FamilyInstance fi = doc.GetElement(existingElems[i]) as FamilyInstance;

                                    // Change the family and symbol if necessary
                                    if (fi.Symbol.Family.Name != symbol.Family.Name || fi.Symbol.Name != symbol.Name)
                                    {
                                        try
                                        {
                                            fi.Symbol = symbol;
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                    }

                                    IList<ElementId> placePointIds = new List<ElementId>();
                                    placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(fi);

                                    for (int ptNum = 0; ptNum < obj.AdaptivePoints.Count; ptNum++)
                                    {
                                        try
                                        {
                                            ReferencePoint rp = doc.GetElement(placePointIds[ptNum]) as ReferencePoint;
                                            XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(obj.AdaptivePoints[ptNum].X, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.AdaptivePoints[ptNum].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.AdaptivePoints[ptNum].Z, lengthDUT));
                                            XYZ vector = pt.Subtract(rp.Position);
                                            ElementTransformUtils.MoveElement(doc, rp.Id, vector);
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                    }

                                    // Assign the parameters
                                    SetParameters(fi, obj.Parameters, doc);
                                }

                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        t.Commit();
                    }
                }

            }

            #endregion


            #region Curve based components
            if (ro.Curves != null && ro.Curves.Count > 0)
            {
                // Find the FamilySymbol
                FamilySymbol symbol = null;
                WallType wallType = null;
                FloorType floorType = null;
                RoofType roofType = null;
                GridType gridType = null;
                bool typeFound = false;

                FilteredElementCollector famCollector = new FilteredElementCollector(doc);

                if (ro.CategoryId == -2000011)
                {
                    famCollector.OfClass(typeof(WallType));
                    foreach (WallType wt in famCollector)
                    {
                        if (wt.Name == ro.TypeName)
                        {
                            wallType = wt;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else if (ro.CategoryId == -2000032)
                {
                    famCollector.OfClass(typeof(FloorType));
                    foreach (FloorType ft in famCollector)
                    {
                        if (ft.Name == ro.TypeName)
                        {
                            floorType = ft;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else if (ro.CategoryId == -2000035)
                {
                    famCollector.OfClass(typeof(RoofType));
                    foreach (RoofType rt in famCollector)
                    {
                        if (rt.Name == ro.TypeName)
                        {
                            roofType = rt;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else if (ro.CategoryId == -2000220)
                {
                    famCollector.OfClass(typeof(GridType));
                    foreach (GridType gt in famCollector)
                    {
                        if (gt.Name == ro.TypeName)
                        {
                            gridType = gt;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else
                {
                    symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);
                    if (symbol != null)
                        typeFound = true;
                }



                if (typeFound)
                {
                    
                    using (Transaction t = new Transaction(doc, "Lyrebird Modify Objects"))
                    {
                        t.Start();
                        try
                        {
                            // Create the Schema for the instances to store the GH Component InstanceGUID and the path
                            Schema instanceSchema = null;
                            try
                            {
                                instanceSchema = Schema.Lookup(instanceSchemaGUID);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (instanceSchema == null)
                            {
                                SchemaBuilder sb = new SchemaBuilder(instanceSchemaGUID);
                                sb.SetWriteAccessLevel(AccessLevel.Vendor);
                                sb.SetReadAccessLevel(AccessLevel.Public);
                                sb.SetVendorId("LMNA");

                                // Create the field to store the data in the family
                                FieldBuilder guidFB = sb.AddSimpleField("InstanceID", typeof(string));
                                guidFB.SetDocumentation("Component instance GUID from Grasshopper");
                                // Create a filed to store the run number
                                FieldBuilder runIDFB = sb.AddSimpleField("RunID", typeof(int));
                                runIDFB.SetDocumentation("RunID for when multiple runs are created from the same data");
                                // Create a field to store the GH component nickname.
                                FieldBuilder nickNameFB = sb.AddSimpleField("NickName", typeof(string));
                                nickNameFB.SetDocumentation("Component NickName from Grasshopper");

                                sb.SetSchemaName("LMNAInstanceGUID");
                                instanceSchema = sb.Finish();
                            }
                            FamilyInstance fi = null;
                            Grid grid = null;
                            
                            try
                            {
                                bool supress = Properties.Settings.Default.suppressWarning;
                                bool supressedReplace = false;
                                bool supressedModify = true;
                                for (int i = 0; i < existingObjects.Count; i++)
                                {
                                    RevitObject obj = existingObjects[i];
                                    if (obj.CategoryId != -2000011 && obj.CategoryId != -2000032 && obj.CategoryId != -2000035 && obj.CategoryId != -2000220)
                                    {
                                        fi = doc.GetElement(existingElems[i]) as FamilyInstance;

                                        // Change the family and symbol if necessary
                                        if (fi.Symbol.Family.Name != symbol.Family.Name || fi.Symbol.Name != symbol.Name)
                                        {
                                            try
                                            {
                                                fi.Symbol = symbol;
                                            }
                                            catch (Exception ex)
                                            {
                                                Debug.WriteLine(ex.Message);
                                            }
                                        }
                                    }
                                    else if (obj.CategoryId == -2000220)
                                    {
                                        grid = doc.GetElement(existingElems[i]) as Grid;

                                        // Get the grid location and compare against the incoming curve
                                        Curve gridCrv = grid.Curve;
                                        LyrebirdCurve lbc = obj.Curves[0];
                                        try
                                        {
                                            Arc arc = gridCrv as Arc;
                                            if (arc != null && lbc.CurveType == "Arc")
                                            {
                                                // Test that the arcs are similar
                                                XYZ startPoint = arc.GetEndPoint(0);
                                                XYZ endPoint = arc.GetEndPoint(1);
                                                XYZ centerPoint = arc.Center;
                                                double rad = arc.Radius;

                                                XYZ lbcStartPt = new XYZ(lbc.ControlPoints[0].X, lbc.ControlPoints[0].Y, lbc.ControlPoints[0].Z);
                                                XYZ lbcEndPt = new XYZ(lbc.ControlPoints[1].X, lbc.ControlPoints[1].Y, lbc.ControlPoints[1].Z);
                                                XYZ lbcMidPt = new XYZ(lbc.ControlPoints[2].X, lbc.ControlPoints[2].Y, lbc.ControlPoints[2].Z);
                                                Arc lbcArc = Arc.Create(lbcStartPt, lbcEndPt, lbcMidPt);
                                                XYZ lbcCenterPt = lbcArc.Center;
                                                double lbcRad = lbcArc.Radius;

                                                if (centerPoint.DistanceTo(lbcCenterPt) < 0.001 && lbcRad == rad && startPoint.DistanceTo(lbcStartPt) < 0.001)
                                                {
                                                    // Do not create
                                                }
                                                else
                                                {
                                                    // Delete the grid and rebuild it with the new curve.
                                                }
                                            }
                                            else
                                            {
                                                // Probably need to rebuild the curve
                                            }
                                        }
                                        catch { }


                                        try
                                        {
                                            Line line = gridCrv as Line;
                                            if (line != null && lbc.CurveType == "Line")
                                            {
                                                // Test that the arcs are similar
                                                XYZ startPoint = line.GetEndPoint(0);
                                                XYZ endPoint = line.GetEndPoint(1);

                                                XYZ lbcStartPt = new XYZ(lbc.ControlPoints[0].X, lbc.ControlPoints[0].Y, lbc.ControlPoints[0].Z);
                                                XYZ lbcEndPt = new XYZ(lbc.ControlPoints[1].X, lbc.ControlPoints[1].Y, lbc.ControlPoints[1].Z);

                                                if (endPoint.DistanceTo(lbcEndPt) < 0.001 && startPoint.DistanceTo(lbcStartPt) < 0.001)
                                                {
                                                    // Do not create
                                                }
                                                else
                                                {
                                                    // Delete the grid and rebuild it with the new curve.
                                                }
                                            }
                                            else
                                            {
                                                // Probably need to rebuild the curve
                                            }
                                        }
                                        catch { }

                                        if (grid.GridType.Name != gridType.Name)
                                        {
                                            try
                                            {
                                                grid.GridType = gridType;
                                            }
                                            catch (Exception ex)
                                            {
                                                TaskDialog.Show("Error", ex.Message);
                                                Debug.WriteLine(ex.Message);
                                            }
                                        }
                                    }
                                    #region single line based family
                                    if (obj.Curves.Count == 1 && obj.Curves[0].CurveType != "Circle")
                                    {

                                        LyrebirdCurve lbc = obj.Curves[0];
                                        List<LyrebirdPoint> curvePoints = lbc.ControlPoints.OrderBy(p => p.Z).ToList();
                                        // linear
                                        // can be a wall or line based family.

                                        // Wall objects
                                        if (obj.CategoryId == -2000011)
                                        {
                                            // draw a wall
                                            Curve crv = null;
                                            if (lbc.CurveType == "Line")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                crv = Line.CreateBound(pt1, pt2);
                                            }
                                            else if (lbc.CurveType == "Arc")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                crv = Arc.Create(pt1, pt3, pt2);
                                            }

                                            if (crv != null)
                                            {

                                                // Find the level
                                                Level lvl = GetLevel(lbc.ControlPoints, doc);

                                                double offset = 0;
                                                if (Math.Abs(UnitUtils.ConvertToInternalUnits(curvePoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                                {
                                                    offset = lvl.Elevation - UnitUtils.ConvertToInternalUnits(curvePoints[0].Z, lengthDUT);
                                                }

                                                // Modify the wall
                                                Wall w = null;
                                                try
                                                {
                                                    w = doc.GetElement(existingElems[i]) as Wall;
                                                    LocationCurve lc = w.Location as LocationCurve;
                                                    lc.Curve = crv;

                                                    // Change the family and symbol if necessary
                                                    if (w.WallType.Name != wallType.Name)
                                                    {
                                                        try
                                                        {
                                                            w.WallType = wallType;
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            Debug.WriteLine(ex.Message);
                                                        }
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    TaskDialog.Show("ERROR", ex.Message);
                                                }


                                                // Assign the parameters
                                                SetParameters(w, obj.Parameters, doc);
                                            }
                                        }
                                        // See if it's a structural column
                                        else if (obj.CategoryId == -2001330)
                                        {
                                            if (symbol != null && lbc.CurveType == "Line")
                                            {
                                                Curve crv = null;
                                                XYZ origin = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                crv = Line.CreateBound(origin, pt2);

                                                // Find the level
                                                //Level lvl = GetLevel(lbc.ControlPoints, doc);

                                                // Create the column
                                                //fi = doc.Create.NewFamilyInstance(origin, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.Column);

                                                // Change it to a slanted column
                                                Parameter slantParam = fi.get_Parameter(BuiltInParameter.SLANTED_COLUMN_TYPE_PARAM);

                                                // SlantedOrVerticalColumnType has 3 options, CT_Vertical (0), CT_Angle (1), or CT_EndPoint (2)
                                                // CT_EndPoint is what we want for a line based column.
                                                slantParam.Set(2);

                                                // Set the location curve of the column to the line
                                                LocationCurve lc = fi.Location as LocationCurve;
                                                if (lc != null)
                                                {
                                                    lc.Curve = crv;
                                                }

                                                // Change the family and symbol if necessary
                                                if (fi.Symbol.Name != symbol.Name)
                                                {
                                                    try
                                                    {
                                                        fi.Symbol = symbol;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }

                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);
                                            }
                                        }

                                        else if (obj.CategoryId == -2000220)
                                        {
                                            // draw a grid
                                            Curve crv = null;
                                            if (lbc.CurveType == "Line")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                crv = Line.CreateBound(pt1, pt2);
                                            }
                                            else if (lbc.CurveType == "Arc")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                crv = Arc.Create(pt1, pt3, pt2);
                                            }

                                            if (crv != null && grid != null)
                                            {
                                                // Determine if it's possible to edit the grid curve or if it needs to be deleted/replaced.

                                                // Assign the parameters
                                                SetParameters(grid, obj.Parameters, doc);
                                            }
                                        }

                                        // Otherwise create a family it using the line
                                        else
                                        {
                                            if (symbol != null)
                                            {
                                                Curve crv = null;

                                                if (lbc.CurveType == "Line")
                                                {
                                                    XYZ origin = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                    crv = Line.CreateBound(origin, pt2);
                                                }
                                                else if (lbc.CurveType == "Arc")
                                                {
                                                    XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                    XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                    crv = Arc.Create(pt1, pt3, pt2);
                                                }

                                                // Change the family and symbol if necessary
                                                if (fi.Symbol.Name != symbol.Name)
                                                {
                                                    try
                                                    {
                                                        fi.Symbol = symbol;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }

                                                try
                                                {
                                                    LocationCurve lc = fi.Location as LocationCurve;
                                                    lc.Curve = crv;
                                                }
                                                catch (Exception ex)
                                                {
                                                    Debug.WriteLine(ex.Message);
                                                }
                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region Closed Curve Family
                                    else
                                    {
                                        bool replace = false;
                                        if (supress)
                                        {
                                            if (supressedReplace)
                                            {
                                                replace = true;
                                            }
                                            else
                                            {
                                                replace = false;
                                            }
                                        }
                                        if (profileWarning && !supress)
                                        {
                                            TaskDialog warningDlg = new TaskDialog("Warning")
                                            {
                                                MainInstruction = "Profile based Elements warning",
                                                MainContent =
                                                  "Elements that require updates to a profile sketch may not be updated if the number of curves in the sketch differs from the incoming curves." +
                                                  "  In such cases the element and will be deleted and replaced with new elements." +
                                                  "  Doing so will cause the loss of any elements hosted to the original instance. How would you like to proceed"
                                            };

                                            warningDlg.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Replace the existing elements, understanding hosted elements may be lost");
                                            warningDlg.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Only updated parameter information and not profile or location information");
                                            warningDlg.AddCommandLink(TaskDialogCommandLinkId.CommandLink3, "Cancel");
                                            //warningDlg.VerificationText = "Supress similar warnings";

                                            TaskDialogResult result = warningDlg.Show();
                                            if (result == TaskDialogResult.CommandLink1)
                                            {
                                                replace = true;
                                                supressedReplace = true;
                                                supressedModify = true;
                                                //supress = warningDlg.WasVerificationChecked();
                                            }
                                            if (result == TaskDialogResult.CommandLink2)
                                            {
                                                supressedReplace = false;
                                                supressedModify = true;
                                                //supress = warningDlg.WasVerificationChecked();
                                            }
                                            if (result == TaskDialogResult.CommandLink3)
                                            {
                                                supressedReplace = false;
                                                supressedModify = false;
                                                //supress = warningDlg.WasVerificationChecked();
                                            }
                                        }
                                        // A list of curves.  These should equate a closed planar curve from GH.
                                        // Determine category and create based on that.
                                        #region walls
                                        if (obj.CategoryId == -2000011)
                                        {
                                            // Create line based wall
                                            // Find the level
                                            Level lvl = null;
                                            double offset = 0;
                                            List<LyrebirdPoint> allPoints = new List<LyrebirdPoint>();
                                            foreach (LyrebirdCurve lc in obj.Curves)
                                            {
                                                foreach (LyrebirdPoint lp in lc.ControlPoints)
                                                {
                                                    allPoints.Add(lp);
                                                }
                                            }
                                            allPoints.Sort((x, y) => x.Z.CompareTo(y.Z));

                                            lvl = GetLevel(allPoints, doc);

                                            if (Math.Abs(allPoints[0].Z - lvl.Elevation) > double.Epsilon)
                                            {
                                                offset = allPoints[0].Z - lvl.Elevation;
                                            }

                                            // Generate the curvearray from the incoming curves
                                            List<Curve> crvArray = new List<Curve>();
                                            try
                                            {
                                                foreach (LyrebirdCurve lbc in obj.Curves)
                                                {
                                                    if (lbc.CurveType == "Circle")
                                                    {
                                                        XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                        XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                        XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                        XYZ pt4 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Z, lengthDUT));
                                                        XYZ pt5 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Z, lengthDUT));
                                                        Arc arc1 = Arc.Create(pt1, pt3, pt2);
                                                        Arc arc2 = Arc.Create(pt3, pt5, pt4);
                                                        crvArray.Add(arc1);
                                                        crvArray.Add(arc2);
                                                    }
                                                    else if (lbc.CurveType == "Arc")
                                                    {
                                                        XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                        XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                        XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                        Arc arc = Arc.Create(pt1, pt3, pt2);
                                                        crvArray.Add(arc);
                                                    }
                                                    else if (lbc.CurveType == "Line")
                                                    {
                                                        XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                        XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                        Line line = Line.CreateBound(pt1, pt2);
                                                        crvArray.Add(line);
                                                    }
                                                    else if (lbc.CurveType == "Spline")
                                                    {
                                                        List<XYZ> controlPoints = new List<XYZ>();
                                                        List<double> weights = lbc.Weights;
                                                        List<double> knots = lbc.Knots;

                                                        foreach (LyrebirdPoint lp in lbc.ControlPoints)
                                                        {
                                                            XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(lp.X, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Z, lengthDUT));
                                                            controlPoints.Add(pt);
                                                        }

                                                        NurbSpline spline;
                                                        if (lbc.Degree < 3)
                                                            spline = NurbSpline.Create(controlPoints, weights);
                                                        else
                                                            spline = NurbSpline.Create(controlPoints, weights, knots, lbc.Degree, false, true);

                                                        crvArray.Add(spline);
                                                    }
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                TaskDialog.Show("ERROR", ex.Message);
                                            }

                                            // Create the wall
                                            Wall w = null;
                                            if (replace)
                                            {
                                                Wall origWall = doc.GetElement(existingElems[i]) as Wall;

                                                // Find the model curves for the original wall
                                                ICollection<ElementId> ids;
                                                using (SubTransaction st = new SubTransaction(doc))
                                                {
                                                    st.Start();
                                                    ids = doc.Delete(origWall.Id);
                                                    st.RollBack();
                                                }

                                                List<ModelCurve> mLines = new List<ModelCurve>();
                                                foreach (ElementId id in ids)
                                                {
                                                    Element e = doc.GetElement(id);
                                                    if (e is ModelCurve)
                                                    {
                                                        mLines.Add(e as ModelCurve);
                                                    }
                                                }

                                                // Walls don't appear to be updatable like floors and roofs
                                                //if (mLines.Count != crvArray.Count)
                                                //{

                                                w = Wall.Create(doc, crvArray, wallType.Id, lvl.Id, false);

                                                foreach (Parameter p in origWall.Parameters)
                                                {
                                                    try
                                                    {
                                                        Parameter newParam = w.LookupParameter(p.Definition.Name);
                                                        if (newParam != null)
                                                        {
                                                            switch (newParam.StorageType)
                                                            {
                                                                case StorageType.Double:
                                                                    newParam.Set(p.AsDouble());
                                                                    break;
                                                                case StorageType.ElementId:
                                                                    newParam.Set(p.AsElementId());
                                                                    break;
                                                                case StorageType.Integer:
                                                                    newParam.Set(p.AsInteger());
                                                                    break;
                                                                case StorageType.String:
                                                                    newParam.Set(p.AsString());
                                                                    break;
                                                                default:
                                                                    newParam.Set(p.AsString());
                                                                    break;
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        //TaskDialog.Show("Errorsz", ex.Message);
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }

                                                if (Math.Abs(offset - 0) > double.Epsilon)
                                                {
                                                    Parameter p = w.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
                                                    p.Set(offset);
                                                }
                                                doc.Delete(origWall.Id);

                                                // Assign the parameters
                                                SetParameters(w, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(w, uniqueId, instanceSchema, runId, nickName);
                                            }
                                            else if (supressedModify) // Just update the parameters and don't change the wall
                                            {
                                                w = doc.GetElement(existingElems[i]) as Wall;

                                                // Change the family and symbol if necessary
                                                if (w.WallType.Name != wallType.Name)
                                                {
                                                    try
                                                    {
                                                        w.WallType = wallType;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }

                                                // Assign the parameters
                                                SetParameters(w, obj.Parameters, doc);
                                            }
                                        }
                                        #endregion

                                        #region floors
                                        else if (obj.CategoryId == -2000032)
                                        {
                                            // Create a profile based floor
                                            // Find the level
                                            Level lvl = GetLevel(obj.Curves[0].ControlPoints, doc);

                                            double offset = 0;
                                            if (Math.Abs(UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                            {
                                                offset = UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation;
                                            }

                                            // Generate the curvearray from the incoming curves
                                            CurveArray crvArray = GetCurveArray(obj.Curves);

                                            // Create the floor
                                            Floor flr = null;
                                            if (replace)
                                            {
                                                Floor origFloor = doc.GetElement(existingElems[i]) as Floor;

                                                // Find the model curves for the original wall
                                                ICollection<ElementId> ids;
                                                using (SubTransaction st = new SubTransaction(doc))
                                                {
                                                    st.Start();

                                                    ids = doc.Delete(origFloor.Id);
                                                    st.RollBack();
                                                }

                                                // Get only the modelcurves
                                                List<ModelCurve> mLines = new List<ModelCurve>();
                                                foreach (ElementId id in ids)
                                                {
                                                    Element e = doc.GetElement(id);
                                                    if (e is ModelCurve)
                                                    {
                                                        mLines.Add(e as ModelCurve);
                                                    }
                                                }

                                                // Floors have an extra modelcurve for the SpanDirection.  Remove the last Item to get rid of it.
                                                mLines.RemoveAt(mLines.Count - 1);
                                                if (mLines.Count != crvArray.Size) // The sketch is different from the incoming curves so floor is recreated
                                                {
                                                    if (obj.CurveIds != null && obj.CurveIds.Count > 0)
                                                    {
                                                        // get the main profile
                                                        int crvCount = obj.CurveIds[0];
                                                        List<LyrebirdCurve> primaryCurves = obj.Curves.GetRange(0, crvCount);
                                                        crvArray = GetCurveArray(primaryCurves);
                                                        flr = doc.Create.NewFloor(crvArray, floorType, lvl, false);
                                                    }
                                                    else
                                                    {
                                                        flr = doc.Create.NewFloor(crvArray, floorType, lvl, false);
                                                    }
                                                    foreach (Parameter p in origFloor.Parameters)
                                                    {
                                                        try
                                                        {
                                                            Parameter newParam = flr.LookupParameter(p.Definition.Name);
                                                            if (newParam != null)
                                                            {
                                                                switch (newParam.StorageType)
                                                                {
                                                                    case StorageType.Double:
                                                                        newParam.Set(p.AsDouble());
                                                                        break;
                                                                    case StorageType.ElementId:
                                                                        newParam.Set(p.AsElementId());
                                                                        break;
                                                                    case StorageType.Integer:
                                                                        newParam.Set(p.AsInteger());
                                                                        break;
                                                                    case StorageType.String:
                                                                        newParam.Set(p.AsString());
                                                                        break;
                                                                    default:
                                                                        newParam.Set(p.AsString());
                                                                        break;
                                                                }
                                                            }
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            Debug.WriteLine(ex.Message);
                                                        }
                                                    }

                                                    if (Math.Abs(offset - 0) > double.Epsilon)
                                                    {
                                                        Parameter p = flr.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);
                                                        p.Set(offset);
                                                    }
                                                    doc.Delete(origFloor.Id);

                                                    // Assign the parameters
                                                    SetParameters(flr, obj.Parameters, doc);

                                                    // Assign the GH InstanceGuid
                                                    AssignGuid(flr, uniqueId, instanceSchema, runId, nickName);
                                                }
                                                else // The curves coming in should match the floor sketch.  Let's modify the floor's locationcurves to edit it's location/shape
                                                {
                                                    try
                                                    {
                                                        int crvCount = 0;
                                                        foreach (ModelCurve l in mLines)
                                                        {
                                                            LocationCurve lc = l.Location as LocationCurve;
                                                            lc.Curve = crvArray.get_Item(crvCount);
                                                            crvCount++;
                                                        }

                                                        // Change the family and symbol if necessary
                                                        if (origFloor.FloorType.Name != floorType.Name)
                                                        {
                                                            try
                                                            {
                                                                origFloor.FloorType = floorType;
                                                            }
                                                            catch (Exception ex)
                                                            {
                                                                Debug.WriteLine(ex.Message);
                                                            }
                                                        }

                                                        // Set the incoming parameters
                                                        SetParameters(origFloor, obj.Parameters, doc);
                                                    }
                                                    catch // There was an error in trying to recreate it.  Just delete the original and recreate the thing.
                                                    {
                                                        flr = doc.Create.NewFloor(crvArray, floorType, lvl, false);

                                                        // Assign the parameters in the new floor to match the original floor object.
                                                        foreach (Parameter p in origFloor.Parameters)
                                                        {
                                                            try
                                                            {
                                                                Parameter newParam = flr.LookupParameter(p.Definition.Name);
                                                                if (newParam != null)
                                                                {
                                                                    switch (newParam.StorageType)
                                                                    {
                                                                        case StorageType.Double:
                                                                            newParam.Set(p.AsDouble());
                                                                            break;
                                                                        case StorageType.ElementId:
                                                                            newParam.Set(p.AsElementId());
                                                                            break;
                                                                        case StorageType.Integer:
                                                                            newParam.Set(p.AsInteger());
                                                                            break;
                                                                        case StorageType.String:
                                                                            newParam.Set(p.AsString());
                                                                            break;
                                                                        default:
                                                                            newParam.Set(p.AsString());
                                                                            break;
                                                                    }
                                                                }
                                                            }
                                                            catch (Exception exception)
                                                            {
                                                                Debug.WriteLine(exception.Message);
                                                            }
                                                        }

                                                        if (Math.Abs(offset - 0) > double.Epsilon)
                                                        {
                                                            Parameter p = flr.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);
                                                            p.Set(offset);
                                                        }

                                                        doc.Delete(origFloor.Id);

                                                        // Set the incoming parameters
                                                        SetParameters(flr, obj.Parameters, doc);
                                                        // Assign the GH InstanceGuid
                                                        AssignGuid(flr, uniqueId, instanceSchema, runId, nickName);
                                                    }
                                                }
                                            }
                                            else if (supressedModify) // Just modify the floor and don't risk replacing it.
                                            {
                                                flr = doc.GetElement(existingElems[i]) as Floor;

                                                // Change the family and symbol if necessary
                                                if (flr.FloorType.Name != floorType.Name)
                                                {
                                                    try
                                                    {
                                                        flr.FloorType = floorType;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }
                                                // Assign the parameters
                                                SetParameters(flr, obj.Parameters, doc);
                                            }
                                        }
                                        #endregion
                                        else if (obj.CategoryId == -2000035)
                                        {
                                            // Create a RoofExtrusion
                                            // Find the level
                                            Level lvl = GetLevel(obj.Curves[0].ControlPoints, doc);

                                            double offset = 0;
                                            if (Math.Abs(UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                            {
                                                offset = UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation;
                                            }

                                            // Generate the curvearray from the incoming curves
                                            CurveArray crvArray = GetCurveArray(obj.Curves);

                                            // Create the roof
                                            FootPrintRoof roof = null;
                                            ModelCurveArray roofProfile = new ModelCurveArray();

                                            if (replace)  // Try to modify or create a new roof.
                                            {
                                                FootPrintRoof origRoof = doc.GetElement(existingElems[i]) as FootPrintRoof;

                                                // Find the model curves for the original wall
                                                ICollection<ElementId> ids;
                                                using (SubTransaction st = new SubTransaction(doc))
                                                {
                                                    st.Start();
                                                    ids = doc.Delete(origRoof.Id);
                                                    st.RollBack();
                                                }

                                                // Get the sketch curves for the roof object.
                                                List<ModelCurve> mLines = new List<ModelCurve>();
                                                foreach (ElementId id in ids)
                                                {
                                                    Element e = doc.GetElement(id);
                                                    if (e is ModelCurve)
                                                    {
                                                        mLines.Add(e as ModelCurve);
                                                    }
                                                }

                                                if (mLines.Count != crvArray.Size) // Sketch curves qty doesn't match up with the incoming cuves.  Just recreate the roof.
                                                {
                                                    roof = doc.Create.NewFootPrintRoof(crvArray, lvl, roofType, out roofProfile);

                                                    // Match parameters from the original roof to it's new iteration.
                                                    foreach (Parameter p in origRoof.Parameters)
                                                    {
                                                        try
                                                        {
                                                            Parameter newParam = roof.LookupParameter(p.Definition.Name);
                                                            if (newParam != null)
                                                            {
                                                                switch (newParam.StorageType)
                                                                {
                                                                    case StorageType.Double:
                                                                        newParam.Set(p.AsDouble());
                                                                        break;
                                                                    case StorageType.ElementId:
                                                                        newParam.Set(p.AsElementId());
                                                                        break;
                                                                    case StorageType.Integer:
                                                                        newParam.Set(p.AsInteger());
                                                                        break;
                                                                    case StorageType.String:
                                                                        newParam.Set(p.AsString());
                                                                        break;
                                                                    default:
                                                                        newParam.Set(p.AsString());
                                                                        break;
                                                                }
                                                            }
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            Debug.WriteLine(ex.Message);
                                                        }
                                                    }

                                                    if (Math.Abs(offset - 0) > double.Epsilon)
                                                    {
                                                        Parameter p = roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM);
                                                        p.Set(offset);
                                                    }

                                                    doc.Delete(origRoof.Id);

                                                    // Set the new parameters
                                                    SetParameters(roof, obj.Parameters, doc);

                                                    // Assign the GH InstanceGuid
                                                    AssignGuid(roof, uniqueId, instanceSchema, runId, nickName);
                                                }
                                                else // The curves qty lines up, lets try to modify the roof sketch so we don't have to replace it.
                                                {
                                                    if (obj.CurveIds != null && obj.CurveIds.Count > 0)
                                                    {
                                                        // Just recreate the roof
                                                        roof = doc.Create.NewFootPrintRoof(crvArray, lvl, roofType, out roofProfile);

                                                        // Match parameters from the original roof to it's new iteration.
                                                        foreach (Parameter p in origRoof.Parameters)
                                                        {
                                                            try
                                                            {
                                                                Parameter newParam = roof.LookupParameter(p.Definition.Name);
                                                                if (newParam != null)
                                                                {
                                                                    switch (newParam.StorageType)
                                                                    {
                                                                        case StorageType.Double:
                                                                            newParam.Set(p.AsDouble());
                                                                            break;
                                                                        case StorageType.ElementId:
                                                                            newParam.Set(p.AsElementId());
                                                                            break;
                                                                        case StorageType.Integer:
                                                                            newParam.Set(p.AsInteger());
                                                                            break;
                                                                        case StorageType.String:
                                                                            newParam.Set(p.AsString());
                                                                            break;
                                                                        default:
                                                                            newParam.Set(p.AsString());
                                                                            break;
                                                                    }
                                                                }
                                                            }
                                                            catch (Exception ex)
                                                            {
                                                                Debug.WriteLine(ex.Message);
                                                            }
                                                        }

                                                        if (Math.Abs(offset - 0) > double.Epsilon)
                                                        {
                                                            Parameter p = roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM);
                                                            p.Set(offset);
                                                        }

                                                        // Set the parameters from the incoming data
                                                        SetParameters(roof, obj.Parameters, doc);

                                                        // Assign the GH InstanceGuid
                                                        AssignGuid(roof, uniqueId, instanceSchema, runId, nickName);

                                                        doc.Delete(origRoof.Id);
                                                    }
                                                    else
                                                    {
                                                        try
                                                        {
                                                            int crvCount = 0;
                                                            foreach (ModelCurve l in mLines)
                                                            {
                                                                LocationCurve lc = l.Location as LocationCurve;
                                                                lc.Curve = crvArray.get_Item(crvCount);
                                                                crvCount++;
                                                            }

                                                            // Change the family and symbol if necessary
                                                            if (origRoof.RoofType.Name != roofType.Name)
                                                            {
                                                                try
                                                                {
                                                                    origRoof.RoofType = roofType;
                                                                }
                                                                catch (Exception ex)
                                                                {
                                                                    Debug.WriteLine(ex.Message);
                                                                }
                                                            }

                                                            SetParameters(origRoof, obj.Parameters, doc);
                                                        }
                                                        catch // Modificaiton failed, lets just create a new roof.
                                                        {
                                                            roof = doc.Create.NewFootPrintRoof(crvArray, lvl, roofType, out roofProfile);

                                                            // Match parameters from the original roof to it's new iteration.
                                                            foreach (Parameter p in origRoof.Parameters)
                                                            {
                                                                try
                                                                {
                                                                    Parameter newParam = roof.LookupParameter(p.Definition.Name);
                                                                    if (newParam != null)
                                                                    {
                                                                        switch (newParam.StorageType)
                                                                        {
                                                                            case StorageType.Double:
                                                                                newParam.Set(p.AsDouble());
                                                                                break;
                                                                            case StorageType.ElementId:
                                                                                newParam.Set(p.AsElementId());
                                                                                break;
                                                                            case StorageType.Integer:
                                                                                newParam.Set(p.AsInteger());
                                                                                break;
                                                                            case StorageType.String:
                                                                                newParam.Set(p.AsString());
                                                                                break;
                                                                            default:
                                                                                newParam.Set(p.AsString());
                                                                                break;
                                                                        }
                                                                    }
                                                                }
                                                                catch (Exception ex)
                                                                {
                                                                    Debug.WriteLine(ex.Message);
                                                                }
                                                            }

                                                            if (Math.Abs(offset - 0) > double.Epsilon)
                                                            {
                                                                Parameter p = roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM);
                                                                p.Set(offset);
                                                            }

                                                            // Set the parameters from the incoming data
                                                            SetParameters(roof, obj.Parameters, doc);

                                                            // Assign the GH InstanceGuid
                                                            AssignGuid(roof, uniqueId, instanceSchema, runId, nickName);

                                                            doc.Delete(origRoof.Id);
                                                        }
                                                    }
                                                }
                                            }
                                            else if (supressedModify) // Only update the parameters
                                            {
                                                roof = doc.GetElement(existingElems[i]) as FootPrintRoof;

                                                // Change the family and symbol if necessary
                                                if (roof.RoofType.Name != roofType.Name)
                                                {
                                                    try
                                                    {
                                                        roof.RoofType = roofType;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }
                                                // Assign the parameters
                                                SetParameters(roof, obj.Parameters, doc);
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                            catch (Exception ex)
                            {
                                TaskDialog.Show("Error", ex.Message);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        t.Commit();
                    }
                }


            }
            #endregion

            //return succeeded;
        }
Exemplo n.º 37
0
        private void CreateObjects(List<RevitObject> revitObjects, Document doc, Guid uniqueId, int runId, string nickName)
        {
            // Create new Revit objects.
            //List<LyrebirdId> newUniqueIds = new List<LyrebirdId>();

            // Get the levels from the project
            FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
            lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>();

            // Determine what kind of object we're creating.
            RevitObject ro = revitObjects[0];

            #region Normal Origin based Family Instance
            if (ro.Origin != null)
            {
                // Find the FamilySymbol
                FamilySymbol symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);
                
                LevelType lt = FindLevelType(ro.TypeName, doc);

                if (symbol != null || lt != null)
                {
                    // Get the hosting ID from the family.
                    Family fam = null;
                    Parameter hostParam = null;
                    int hostBehavior = 0;

                    try
                    {
                        fam = symbol.Family;
                        hostParam = fam.get_Parameter(BuiltInParameter.FAMILY_HOSTING_BEHAVIOR);
                        hostBehavior = hostParam.AsInteger();
                    }
                    catch{}
                    
                    using (Transaction t = new Transaction(doc, "Lyrebird Create Objects"))
                    {
                        t.Start();
                        try
                        {
                            // Create the Schema for the instances to store the GH Component InstanceGUID and the path
                            Schema instanceSchema = null;
                            try
                            {
                                instanceSchema = Schema.Lookup(instanceSchemaGUID);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (instanceSchema == null)
                            {
                                SchemaBuilder sb = new SchemaBuilder(instanceSchemaGUID);
                                sb.SetWriteAccessLevel(AccessLevel.Vendor);
                                sb.SetReadAccessLevel(AccessLevel.Public);
                                sb.SetVendorId("LMNA");

                                // Create the field to store the data in the family
                                FieldBuilder guidFB = sb.AddSimpleField("InstanceID", typeof(string));
                                guidFB.SetDocumentation("Component instance GUID from Grasshopper");
                                // Create a filed to store the run number
                                FieldBuilder runIDFB = sb.AddSimpleField("RunID", typeof(int));
                                runIDFB.SetDocumentation("RunID for when multiple runs are created from the same data");
                                // Create a field to store the GH component nickname.
                                FieldBuilder nickNameFB = sb.AddSimpleField("NickName", typeof(string));
                                nickNameFB.SetDocumentation("Component NickName from Grasshopper");

                                sb.SetSchemaName("LMNAInstanceGUID");
                                instanceSchema = sb.Finish();
                            }
                            FamilyInstance fi = null;
                            XYZ origin = XYZ.Zero;
                            if (lt != null)
                            {
                                // Create a level for the object.
                                foreach (RevitObject obj in revitObjects)
                                {
                                    try
                                    {
                                        Level lvl = doc.Create.NewLevel(UnitUtils.ConvertToInternalUnits(obj.Origin.Z, lengthDUT));
                                        lvl.LevelType = lt;
                                        
                                        // Set the parameters.
                                        SetParameters(lvl, obj.Parameters, doc);

                                        // Assign the GH InstanceGuid
                                        AssignGuid(lvl, uniqueId, instanceSchema, runId, nickName);
                                    }
                                    catch { }
                                }
                            }
                            else if (hostBehavior == 0)
                            {
                                int x = 0;
                                foreach (RevitObject obj in revitObjects)
                                {
                                    try
                                    {
                                        List<LyrebirdPoint> originPts = new List<LyrebirdPoint>();
                                        Level lvl = GetLevel(originPts, doc);
                                        origin = new XYZ(UnitUtils.ConvertToInternalUnits(obj.Origin.X, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Z, lengthDUT));
                                        if (symbol.Category.Id.IntegerValue == -2001330)
                                        {
                                            if (lvl != null)
                                            {
                                                // Structural Column
                                                fi = doc.Create.NewFamilyInstance(origin, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.Column);
                                                fi.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(origin.Z - lvl.Elevation);
                                                double topElev = ((Level)doc.GetElement(fi.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).AsElementId())).Elevation;
                                                if (lvl.Elevation + (origin.Z - lvl.Elevation) > topElev)
                                                {
                                                    fi.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set((lvl.Elevation + (origin.Z - lvl.Elevation)) - topElev + 10.0);
                                                }
                                            }
                                            else
                                            {
                                                TaskDialog.Show("error", "Null level");
                                            }
                                        }
                                        else
                                        {
                                            // All Else
                                            fi = doc.Create.NewFamilyInstance(origin, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        TaskDialog.Show("Error", ex.Message);
                                    }

                                    // Rotate
                                    if (obj.Orientation != null)
                                    {
                                        if (Math.Round(Math.Abs(obj.Orientation.Z - 0), 10) < double.Epsilon)
                                        {
                                            Line axis = Line.CreateBound(origin, origin + XYZ.BasisZ);
                                            XYZ normalVector = new XYZ(0, -1, 0);
                                            XYZ orient = new XYZ(obj.Orientation.X, obj.Orientation.Y, obj.Orientation.Z);
                                            double angle = 0;
                                            if (orient.X < 0 && orient.Y < 0)
                                            {
                                                angle = (2 * Math.PI) - normalVector.AngleTo(orient);
                                            }
                                            else if (orient.X < 0)
                                            {
                                                angle = (Math.PI - normalVector.AngleTo(orient)) + Math.PI;
                                            }
                                            else if (orient.Y == 0)
                                            {
                                                angle = 1.5 * Math.PI;
                                            }
                                            else
                                            {
                                                angle = normalVector.AngleTo(orient);
                                            }
                                            ElementTransformUtils.RotateElement(doc, fi.Id, axis, angle);
                                        }
                                    }

                                    // Assign the parameters
                                    SetParameters(fi, obj.Parameters, doc);

                                    // Assign the GH InstanceGuid
                                    AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);

                                    x++;
                                }
                            }
                            else
                            {
                                foreach (RevitObject obj in revitObjects)
                                {
                                    origin = new XYZ(UnitUtils.ConvertToInternalUnits(obj.Origin.X, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.Origin.Z, lengthDUT));
                                    
                                    // Find the level
                                    List<LyrebirdPoint> lbPoints = new List<LyrebirdPoint> { obj.Origin };
                                    Level lvl = GetLevel(lbPoints, doc);
                                    
                                    // Get the host
                                    if (hostBehavior == 5)
                                    {
                                        // Face based family.  Find the face and create the element
                                        XYZ normVector = new XYZ(obj.Orientation.X, obj.Orientation.Y, obj.Orientation.Z);
                                        XYZ faceVector;
                                        if (obj.FaceOrientation != null)
                                        {
                                            faceVector = new XYZ(obj.FaceOrientation.X, obj.FaceOrientation.Y, obj.FaceOrientation.Z);
                                        }
                                        else
                                        {
                                            faceVector = XYZ.BasisZ;
                                        }
                                        Face face = FindFace(origin, normVector, doc);
                                        if (face != null)
                                        {
                                            fi = doc.Create.NewFamilyInstance(face, origin, faceVector, symbol);
                                        }
                                    }
                                    else
                                    {
                                        // typical hosted family.  Can be wall, floor, roof or ceiling.
                                        ElementId host = FindHost(origin, hostBehavior, doc);
                                        
                                        if (host != null)
                                        {
                                            fi = doc.Create.NewFamilyInstance(origin, symbol, doc.GetElement(host), lvl, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                        }
                                    }
                                    // Assign the parameters
                                    SetParameters(fi, obj.Parameters, doc);

                                    // Assign the GH InstanceGuid
                                    AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
                                }
                                // delete the host finder
                                ElementId hostFinderFamily = hostFinder.Symbol.Family.Id;
                                doc.Delete(hostFinder.Id);
                                doc.Delete(hostFinderFamily);
                                hostFinder = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("Error", ex.Message);
                        }
                        t.Commit();
                    }
                }
                else
                {
                    TaskDialog.Show("Error", "Could not find the desired family type");
                }

            }
            #endregion

            #region Adaptive Components
            else if (ro.AdaptivePoints != null && ro.AdaptivePoints.Count > 0)
            {
                // Find the FamilySymbol
                FamilySymbol symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);
                if (symbol != null)
                {
                    using (Transaction t = new Transaction(doc, "Lyrebird Create Objects"))
                    {
                        t.Start();
                        try
                        {
                            // Create the Schema for the instances to store the GH Component InstanceGUID and the path
                            Schema instanceSchema = null;
                            try
                            {
                                instanceSchema = Schema.Lookup(instanceSchemaGUID);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (instanceSchema == null)
                            {
                                SchemaBuilder sb = new SchemaBuilder(instanceSchemaGUID);
                                sb.SetWriteAccessLevel(AccessLevel.Vendor);
                                sb.SetReadAccessLevel(AccessLevel.Public);
                                sb.SetVendorId("LMNA");

                                // Create the field to store the data in the family
                                FieldBuilder guidFB = sb.AddSimpleField("InstanceID", typeof(string));
                                guidFB.SetDocumentation("Component instance GUID from Grasshopper");

                                // Create a filed to store the run number
                                FieldBuilder runIDFB = sb.AddSimpleField("RunID", typeof(int));
                                runIDFB.SetDocumentation("RunID for when multiple runs are created from the same data");

                                // Create a field to store the GH component nickname.
                                FieldBuilder nickNameFB = sb.AddSimpleField("NickName", typeof(string));
                                nickNameFB.SetDocumentation("Component NickName from Grasshopper");

                                sb.SetSchemaName("LMNAInstanceGUID");
                                instanceSchema = sb.Finish();
                            }
                            try
                            {
                                foreach (RevitObject obj in revitObjects)
                                {
                                    FamilyInstance fi = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, symbol);
                                    IList<ElementId> placePointIds = new List<ElementId>();
                                    placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(fi);

                                    for (int ptNum = 0; ptNum < obj.AdaptivePoints.Count; ptNum++)
                                    {
                                        try
                                        {
                                            ReferencePoint rp = doc.GetElement(placePointIds[ptNum]) as ReferencePoint;
                                            XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(obj.AdaptivePoints[ptNum].X, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.AdaptivePoints[ptNum].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(obj.AdaptivePoints[ptNum].Z, lengthDUT));
                                            if (rp != null)
                                            {
                                                XYZ vector = pt.Subtract(rp.Position);
                                                ElementTransformUtils.MoveElement(doc, rp.Id, vector);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                    }

                                    // Assign the parameters
                                    SetParameters(fi, obj.Parameters, doc);

                                    // Assign the GH InstanceGuid
                                    AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
                                }

                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        t.Commit();
                    }
                }
            }
            #endregion

            #region Curve based
            else if (ro.Curves != null && ro.Curves.Count > 0)
            {

                // Find the FamilySymbol
                FamilySymbol symbol = null;
                WallType wallType = null;
                FloorType floorType = null;
                RoofType roofType = null;
                GridType gridType = null;
                bool typeFound = false;

                FilteredElementCollector famCollector = new FilteredElementCollector(doc);

                if (ro.CategoryId == -2000011)
                {
                    famCollector.OfClass(typeof(WallType));
                    foreach (WallType wt in famCollector)
                    {
                        if (wt.Name == ro.TypeName)
                        {
                            wallType = wt;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else if (ro.CategoryId == -2000032)
                {
                    famCollector.OfClass(typeof(FloorType));
                    foreach (FloorType ft in famCollector)
                    {
                        if (ft.Name == ro.TypeName)
                        {
                            floorType = ft;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else if (ro.CategoryId == -2000035)
                {
                    famCollector.OfClass(typeof(RoofType));
                    foreach (RoofType rt in famCollector)
                    {
                        if (rt.Name == ro.TypeName)
                        {
                            roofType = rt;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else if (ro.CategoryId == -2000220)
                {
                    famCollector.OfClass(typeof(GridType));
                    foreach (GridType gt in famCollector)
                    {
                        if (gt.Name == ro.TypeName)
                        {
                            gridType = gt;
                            typeFound = true;
                            break;
                        }
                    }
                }
                else
                {
                    symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);
                    if (symbol != null)
                        typeFound = true;
                }



                if (typeFound)
                {
                    using (Transaction t = new Transaction(doc, "Lyrebird Create Objects"))
                    {

                        t.Start();
                        try
                        {
                            // Create the Schema for the instances to store the GH Component InstanceGUID and the path
                            Schema instanceSchema = null;
                            try
                            {
                                instanceSchema = Schema.Lookup(instanceSchemaGUID);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (instanceSchema == null)
                            {
                                SchemaBuilder sb = new SchemaBuilder(instanceSchemaGUID);
                                sb.SetWriteAccessLevel(AccessLevel.Vendor);
                                sb.SetReadAccessLevel(AccessLevel.Public);
                                sb.SetVendorId("LMNA");

                                // Create the field to store the data in the family
                                FieldBuilder guidFB = sb.AddSimpleField("InstanceID", typeof(string));
                                guidFB.SetDocumentation("Component instance GUID from Grasshopper");

                                // Create a filed to store the run number
                                FieldBuilder runIDFB = sb.AddSimpleField("RunID", typeof(int));
                                runIDFB.SetDocumentation("RunID for when multiple runs are created from the same data");

                                // Create a field to store the GH component nickname.
                                FieldBuilder nickNameFB = sb.AddSimpleField("NickName", typeof(string));
                                nickNameFB.SetDocumentation("Component NickName from Grasshopper");

                                sb.SetSchemaName("LMNAInstanceGUID");
                                instanceSchema = sb.Finish();
                            }
                            FamilyInstance fi = null;
                            try
                            {

                                foreach (RevitObject obj in revitObjects)
                                {

                                    #region single line based family
                                    if (obj.Curves.Count == 1 && obj.Curves[0].CurveType != "Circle")
                                    {

                                        LyrebirdCurve lbc = obj.Curves[0];
                                        List<LyrebirdPoint> curvePoints = lbc.ControlPoints.OrderBy(p => p.Z).ToList();
                                        // linear
                                        // can be a wall or line based family.
                                        if (obj.CategoryId == -2000011)
                                        {

                                            // draw a wall
                                            Curve crv = null;
                                            if (lbc.CurveType == "Line")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                crv = Line.CreateBound(pt1, pt2);
                                            }
                                            else if (lbc.CurveType == "Arc")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                crv = Arc.Create(pt1, pt3, pt2);
                                            }

                                            if (crv != null)
                                            {

                                                // Find the level
                                                Level lvl = GetLevel(lbc.ControlPoints, doc);

                                                double offset = 0;
                                                if (Math.Abs(UnitUtils.ConvertToInternalUnits(curvePoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                                {
                                                    offset = UnitUtils.ConvertToInternalUnits(curvePoints[0].Z, lengthDUT) - lvl.Elevation;
                                                }

                                                // Create the wall
                                                Wall w = null;
                                                try
                                                {
                                                    w = Wall.Create(doc, crv, wallType.Id, lvl.Id, 10.0, offset, false, false);
                                                }
                                                catch (Exception ex)
                                                {
                                                    TaskDialog.Show("ERROR", ex.Message);
                                                }

                                                // Assign the parameters
                                                SetParameters(w, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(w, uniqueId, instanceSchema, 0, nickName);
                                            }
                                        }
                                        // See if it's a structural column
                                        else if (obj.CategoryId == -2001330)
                                        {
                                            if (symbol != null && lbc.CurveType == "Line")
                                            {
                                                XYZ origin = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                Curve crv = Line.CreateBound(origin, pt2);

                                                // Find the level
                                                Level lvl = GetLevel(lbc.ControlPoints, doc);

                                                // Create the column
                                                fi = doc.Create.NewFamilyInstance(origin, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.Column);

                                                // Change it to a slanted column
                                                Parameter slantParam = fi.get_Parameter(BuiltInParameter.SLANTED_COLUMN_TYPE_PARAM);

                                                // SlantedOrVerticalColumnType has 3 options, CT_Vertical (0), CT_Angle (1), or CT_EndPoint (2)
                                                // CT_EndPoint is what we want for a line based column.
                                                slantParam.Set(2);

                                                // Set the location curve of the column to the line
                                                LocationCurve lc = fi.Location as LocationCurve;
                                                if (lc != null)
                                                {
                                                    lc.Curve = crv;
                                                }

                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
                                            }
                                        }
                                        else if (obj.CategoryId == -2000220)
                                        {
                                            // draw a grid
                                            Grid g = null;
                                            if (lbc.CurveType == "Line")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                Line line = Line.CreateBound(pt1, pt2);
                                                try
                                                {
                                                    g = doc.Create.NewGrid(line);
                                                }
                                                catch { }
                                            }
                                            else if (lbc.CurveType == "Arc")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                Arc arc = Arc.Create(pt1, pt3, pt2);
                                                try
                                                {
                                                    g = doc.Create.NewGrid(arc);
                                                }
                                                catch { }
                                            }

                                            if (g != null)
                                            {
                                                g.ExtendToAllLevels(); ;
                                                // Assign the parameters
                                                SetParameters(g, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(g, uniqueId, instanceSchema, 0, nickName);
                                            }
                                        }
                                        else if (obj.CategoryId == -2000051)
                                        {
                                            // Draw a line
                                            Curve crv = null;
                                            Curve crv2 = null;

                                            if (lbc.CurveType == "Line")
                                            {
                                                XYZ origin = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                crv = Line.CreateBound(origin, pt2);
                                            }
                                            else if (lbc.CurveType == "Arc")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                crv = Arc.Create(pt1, pt3, pt2);
                                            }
                                            else if (lbc.CurveType == "Circle")
                                            {
                                                XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                XYZ pt4 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Z, lengthDUT));
                                                XYZ pt5 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Z, lengthDUT));
                                                Arc arc1 = Arc.Create(pt1, pt3, pt2);
                                                Arc arc2 = Arc.Create(pt3, pt5, pt4);
                                                crv = arc1;
                                                crv2 = arc2;
                                            }
                                            else if (lbc.CurveType == "Spline")
                                            {
                                                List<XYZ> controlPoints = new List<XYZ>();
                                                List<double> weights = lbc.Weights;
                                                List<double> knots = lbc.Knots;


                                                foreach (LyrebirdPoint lp in lbc.ControlPoints)
                                                {
                                                    XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(lp.X, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Z, lengthDUT));
                                                    controlPoints.Add(pt);
                                                }

                                                NurbSpline spline;
                                                if (lbc.Degree < 3)
                                                    spline = NurbSpline.Create(controlPoints, weights);
                                                else
                                                    spline = NurbSpline.Create(controlPoints, weights, knots, lbc.Degree, false, true);

                                                crv = spline;
                                            }

                                            // Check for model or detail
                                            if (obj.FamilyName == "Model Lines")
                                            {
                                                // We need a plane
                                                
                                            }
                                            else if (obj.FamilyName == "Detail Lines")
                                            {
                                                // we need the active view.
                                            }
                                        }

                                        // Otherwise create a family it using the line
                                        else
                                        {
                                            if (symbol != null)
                                            {
                                                Curve crv = null;

                                                if (lbc.CurveType == "Line")
                                                {
                                                    XYZ origin = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                    crv = Line.CreateBound(origin, pt2);
                                                }
                                                else if (lbc.CurveType == "Arc")
                                                {
                                                    XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                    XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                    XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                    crv = Arc.Create(pt1, pt3, pt2);
                                                }
                                                // Find the level
                                                Level lvl = GetLevel(lbc.ControlPoints, doc);

                                                // Create the family
                                                if (symbol.Category.Id.IntegerValue == -2002000)
                                                {
                                                    try
                                                    {
                                                        Line line = crv as Line;
                                                        fi = doc.Create.NewFamilyInstance(line, symbol, doc.ActiveView);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }
                                                else if (symbol.Category.Id.IntegerValue == -2001320)
                                                {
                                                    try
                                                    {
                                                        if (lbc.CurveType == "Arc")
                                                        {
                                                            XYZ origin = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                            fi = doc.Create.NewFamilyInstance(origin, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                                            // Set the location curve of the column to the line
                                                            LocationCurve lc = fi.Location as LocationCurve;
                                                            if (lc != null)
                                                            {
                                                                lc.Curve = crv;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            fi = doc.Create.NewFamilyInstance(crv, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }
                                                else
                                                {
                                                    try
                                                    {
                                                        fi = doc.Create.NewFamilyInstance(crv, symbol, lvl, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Debug.WriteLine(ex.Message);
                                                    }
                                                }

                                                // Assign the parameters
                                                SetParameters(fi, obj.Parameters, doc);

                                                // Assign the GH InstanceGuid
                                                AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region Closed Curve Family
                                    else
                                    {
                                        // A list of curves.  These should equate a closed planar curve from GH.

                                        //TODO: For each profile type, determine if the offset is working correctly or inverted

                                        // Then determine category and create based on that.
                                        if (obj.CategoryId == -2000011)
                                        {
                                            // Create line based wall
                                            // Find the level
                                            double offset = 0;
                                            List<LyrebirdPoint> allPoints = new List<LyrebirdPoint>();
                                            foreach (LyrebirdCurve lc in obj.Curves)
                                            {
                                                foreach (LyrebirdPoint lp in lc.ControlPoints)
                                                {
                                                    allPoints.Add(lp);
                                                }
                                            }
                                            allPoints.Sort((x, y) => x.Z.CompareTo(y.Z));

                                            Level lvl = GetLevel(allPoints, doc);

                                            if (Math.Abs(UnitUtils.ConvertToInternalUnits(allPoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                            {
                                                offset = UnitUtils.ConvertToInternalUnits(allPoints[0].Z, lengthDUT) - lvl.Elevation;
                                            }

                                            // Generate the curvearray from the incoming curves
                                            List<Curve> crvArray = new List<Curve>();
                                            try
                                            {
                                                foreach (LyrebirdCurve lbc in obj.Curves)
                                                {
                                                    if (lbc.CurveType == "Circle")
                                                    {
                                                        XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                        XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                        XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                        XYZ pt4 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Z, lengthDUT));
                                                        XYZ pt5 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Z, lengthDUT));
                                                        Arc arc1 = Arc.Create(pt1, pt3, pt2);
                                                        Arc arc2 = Arc.Create(pt3, pt5, pt4);
                                                        crvArray.Add(arc1);
                                                        crvArray.Add(arc2);
                                                    }
                                                    else if (lbc.CurveType == "Arc")
                                                    {
                                                        XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                        XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                        XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT));
                                                        Arc arc = Arc.Create(pt1, pt3, pt2);
                                                        crvArray.Add(arc);
                                                    }
                                                    else if (lbc.CurveType == "Line")
                                                    {
                                                        XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT));
                                                        XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT));
                                                        Line line = Line.CreateBound(pt1, pt2);
                                                        crvArray.Add(line);
                                                    }
                                                    else if (lbc.CurveType == "Spline")
                                                    {
                                                        List<XYZ> controlPoints = new List<XYZ>();
                                                        List<double> weights = lbc.Weights;
                                                        List<double> knots = lbc.Knots;


                                                        foreach (LyrebirdPoint lp in lbc.ControlPoints)
                                                        {
                                                            XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(lp.X, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Z, lengthDUT));
                                                            controlPoints.Add(pt);
                                                        }

                                                        NurbSpline spline;
                                                        if (lbc.Degree < 3)
                                                            spline = NurbSpline.Create(controlPoints, weights);
                                                        else
                                                            spline = NurbSpline.Create(controlPoints, weights, knots, lbc.Degree, false, true);

                                                        crvArray.Add(spline);
                                                    }
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                TaskDialog.Show("ERROR", ex.Message);
                                            }

                                            // Create the floor
                                            Wall w = Wall.Create(doc, crvArray, wallType.Id, lvl.Id, false);
                                            if (Math.Abs(offset - 0) > double.Epsilon)
                                            {
                                                Parameter p = w.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
                                                p.Set(offset);
                                            }

                                            // Assign the parameters
                                            SetParameters(w, obj.Parameters, doc);

                                            // Assign the GH InstanceGuid
                                            AssignGuid(w, uniqueId, instanceSchema, 0, nickName);

                                        }
                                        else if (obj.CategoryId == -2000032)
                                        {
                                            // Create a profile based floor
                                            // Find the level
                                            Level lvl = GetLevel(obj.Curves[0].ControlPoints, doc);

                                            double offset = 0;
                                            if (Math.Abs(UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                            {
                                                offset = UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation;
                                            }

                                            // Generate the curvearray from the incoming curves
                                            CurveArray crvArray;
                                            Floor flr;
                                            List<Opening> flrOpenings = new List<Opening>();
                                            if (obj.CurveIds != null && obj.CurveIds.Count > 0)
                                            {
                                                // get the main profile
                                                int crvCount = obj.CurveIds[0];
                                                List<LyrebirdCurve> primaryCurves = obj.Curves.GetRange(0, crvCount);
                                                crvArray = GetCurveArray(primaryCurves);
                                                flr = doc.Create.NewFloor(crvArray, floorType, lvl, false);

                                                // TODO: You cannot create holes in an element with the API without using openings rather than interior closed curves.
                                                // Evaluate with later versions if it's worth creating the openings and updating them
                                                // Create the openings associated with it.
                                                //int start = crvCount - 1;
                                                //for (int i = 1; i < obj.CurveIds.Count; i++)
                                                //{
                                                //    List<LyrebirdCurve> interiorCurves = obj.Curves.GetRange(start, obj.CurveIds[i]);
                                                //    start += interiorCurves.Count;
                                                //    CurveArray openingArray = GetCurveArray(interiorCurves);
                                                //    try
                                                //    {
                                                //        SubTransaction st2 = new SubTransaction(doc);
                                                //        st2.Start();
                                                //        Opening opening = doc.Create.NewOpening(flr, openingArray, false);
                                                //        st2.Commit();
                                                //        flrOpenings.Add(opening);

                                                //    }
                                                //    catch (Exception ex)
                                                //    {
                                                //        TaskDialog.Show("TEST", ex.Message);
                                                //    }
                                                //}
                                            }
                                            else
                                            {
                                                crvArray = GetCurveArray(obj.Curves);
                                                flr = doc.Create.NewFloor(crvArray, floorType, lvl, false);
                                            }

                                            // Create the floor
                                            //flr = doc.Create.NewFloor(crvArray, floorType, lvl, false);

                                            if (Math.Abs(offset - 0) > double.Epsilon)
                                            {
                                                Parameter p = flr.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);
                                                p.Set(offset);
                                            }

                                            // Assign the parameters
                                            SetParameters(flr, obj.Parameters, doc);

                                            // Assign the GH InstanceGuid
                                            AssignGuid(flr, uniqueId, instanceSchema, 0, nickName);

                                        }
                                        else if (obj.CategoryId == -2000035)
                                        {
                                            // Create a RoofExtrusion
                                            // Find the level
                                            Level lvl = GetLevel(obj.Curves[0].ControlPoints, doc);

                                            double offset = 0;
                                            if (Math.Abs(UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation) > double.Epsilon)
                                            {
                                                offset = UnitUtils.ConvertToInternalUnits(obj.Curves[0].ControlPoints[0].Z, lengthDUT) - lvl.Elevation;
                                            }

                                            // Generate the curvearray from the incoming curves
                                            CurveArray crvArray = GetCurveArray(obj.Curves);

                                            // Create the roof
                                            FootPrintRoof roof = null;
                                            ModelCurveArray roofProfile = new ModelCurveArray();
                                            try
                                            {
                                                roof = doc.Create.NewFootPrintRoof(crvArray, lvl, roofType, out roofProfile);
                                            }
                                            catch (Exception ex)
                                            {
                                                TaskDialog.Show("ERROR", ex.Message);
                                            }
                                            if (Math.Abs(offset - 0) > double.Epsilon)
                                            {
                                                Parameter p = roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM);
                                                p.Set(offset);
                                            }

                                            // Assign the parameters
                                            SetParameters(roof, obj.Parameters, doc);

                                            // Assign the GH InstanceGuid
                                            AssignGuid(roof, uniqueId, instanceSchema, 0, nickName);
                                        }
                                    }
                                    #endregion
                                }
                            }
                            catch (Exception ex)
                            {
                                TaskDialog.Show("Error", ex.ToString());
                                Debug.WriteLine(ex.Message);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        t.Commit();
                    }
                }


            }
            #endregion
        }
Exemplo n.º 38
0
        // Setup routine: updates parameters of the window to the appropriate values on load
        internal void UpdateInitialParameters(Document doc)
        {
            Transaction t = new Transaction(doc, "Update parameters");
               t.Start();

               SchemaBuilder builder = new SchemaBuilder(m_schemaId); //(new Guid("{4DE4BE80-0857-4785-A7DF-8A8918851CB2}"));
               builder.AddSimpleField("Position", typeof(XYZ)).SetUnitType(UnitType.UT_Length);
               builder.AddSimpleField("Orientation", typeof(XYZ)).SetUnitType(UnitType.UT_Length);
               builder.SetSchemaName("WallPositionData");
               builder.SetDocumentation("Two points in a Window element that assist in placing a section view.");
               builder.SetVendorId("adsk");
               builder.SetApplicationGUID(doc.Application.ActiveAddInId.GetGUID());

               m_schema = builder.Finish();

               t.Commit();

               t.Start();
               Field fieldPosition = m_schema.GetField("Position");
               Field fieldOrientation = m_schema.GetField("Orientation");

               FamilyInstance window = doc.get_Element(m_windowId) as FamilyInstance;

               Entity storageEntity = new Entity(m_schema);

               LocationPoint lp = window.Location as LocationPoint;
               XYZ location = lp.Point;

               storageEntity.Set<XYZ>(fieldPosition, location, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);

               XYZ orientation = window.FacingOrientation;
               storageEntity.Set<XYZ>(fieldOrientation, orientation, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);
               window.SetEntity(storageEntity);

               t.Commit();
        }
Exemplo n.º 39
0
            /// <summary>
            /// Retrieve our extensible storage schema 
            /// or optionally create a new one if it does
            /// not yet exist.
            /// </summary>
            public static Schema InitializeSchema(
              bool create = true)
            {
                Schema schema = Schema.Lookup(SchemaGuid);

                if (create && null == schema)
                {
                    SchemaBuilder schemaBuilder =
                      new SchemaBuilder(SchemaGuid);

                    schemaBuilder.SetSchemaName(
                      "SlackitSettings");

                    schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

                    schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

                    schemaBuilder.AddSimpleField(
                        "slackOn", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "slackWSWarn", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "slackModelWarn", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "slackBPWarn", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "slackWSInfo", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "slackModelInfo", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "slackBPInfo", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                         "slackExtraTrackPin", typeof(Boolean));

                    schemaBuilder.AddSimpleField(
                        "giphySet", typeof(int));

                    schemaBuilder.AddSimpleField(
                        "tidySet", typeof(int));

                    schemaBuilder.AddSimpleField(
                        "slackToken", typeof(String));

                    schemaBuilder.AddSimpleField(
                        "slackCh", typeof(String));

                    schemaBuilder.AddSimpleField(
                        "slackChId", typeof(String));

                    schema = schemaBuilder.Finish();
                }
                return schema;
            }
Exemplo n.º 40
0
        /// <summary>
        /// Updates the setups to save into the document.
        /// </summary>
        /// <param name="document">The document storing the saved configuration.</param>
        public void UpdateSavedConfigurations(Document document)
        {
            if (m_schema == null)
            {
                m_schema = Schema.Lookup(s_schemaId);
            }

            // Are there any setups to save or resave?
            List<IFCExportConfiguration> setupsToSave = new List<IFCExportConfiguration>();
            foreach (IFCExportConfiguration configuration in m_configurations.Values)
            {
                if (configuration.IsBuiltIn)
                    continue;

                // Store in-session settings in the cached in-session configuration
                if (configuration.IsInSession)
                {
                    IFCExportConfiguration.SetInSession(configuration);
                    continue;
                }

                setupsToSave.Add(configuration);
           }

           // If there are no setups to save, and if the schema is not present (which means there are no
           // previously existing setups which might have been deleted) we can skip the rest of this method.
           if (setupsToSave.Count <= 0 && m_schema == null)
               return;

           if (m_schema == null)
           {
                SchemaBuilder builder = new SchemaBuilder(s_schemaId);
                builder.SetSchemaName("IFCExportConfiguration");
                builder.AddSimpleField(s_setupName, typeof(String));
                builder.AddSimpleField(s_setupDescription, typeof(String));
                builder.AddSimpleField(s_setupVersion, typeof(int));
                builder.AddSimpleField(s_setupFileFormat, typeof(int));
                builder.AddSimpleField(s_setupSpaceBoundaries, typeof(int));
                builder.AddSimpleField(s_setupQTO, typeof(bool));
                builder.AddSimpleField(s_splitWallsAndColumns, typeof(bool));
                builder.AddSimpleField(s_setupCurrentView, typeof(bool));
                builder.AddSimpleField(s_setupExport2D, typeof(bool));
                builder.AddSimpleField(s_setupExportRevitProps, typeof(bool));
                builder.AddSimpleField(s_setupUse2DForRoomVolume, typeof(bool));
                builder.AddSimpleField(s_setupUseFamilyAndTypeName, typeof(bool));
                builder.AddSimpleField(s_setupExportPartsAsBuildingElements, typeof(bool));

                m_schema = builder.Finish();
           }

           // Overwrite all saved configs with the new list
           Transaction transaction = new Transaction(document, "Update IFC export setups");
           transaction.Start();
           IList<DataStorage> savedConfigurations = GetSavedConfigurations(document);
           int savedConfigurationCount = savedConfigurations.Count<DataStorage>();
           int savedConfigurationIndex = 0;
           foreach (IFCExportConfiguration configuration in setupsToSave)
           {
                DataStorage configStorage;
                if (savedConfigurationIndex >= savedConfigurationCount)
                {
                    configStorage = DataStorage.Create(document);
                }
                else
                {
                    configStorage = savedConfigurations[savedConfigurationIndex];
                    savedConfigurationIndex ++;
                }
                Entity entity = new Entity(m_schema);
                entity.Set(s_setupName, configuration.Name);
                entity.Set(s_setupDescription, configuration.Description);
                entity.Set(s_setupVersion, (int)configuration.IFCVersion);
                entity.Set(s_setupFileFormat, (int)configuration.IFCFileType);
                entity.Set(s_setupSpaceBoundaries, configuration.SpaceBoundaries);
                entity.Set(s_setupQTO, configuration.ExportBaseQuantities);
                entity.Set(s_setupCurrentView, configuration.VisibleElementsOfCurrentView);
                entity.Set(s_splitWallsAndColumns, configuration.SplitWallsAndColumns);
                entity.Set(s_setupExport2D, configuration.Export2DElements);
                entity.Set(s_setupExportRevitProps, configuration.ExportInternalRevitPropertySets);
                entity.Set(s_setupUse2DForRoomVolume, configuration.Use2DRoomBoundaryForVolume);
                entity.Set(s_setupUseFamilyAndTypeName, configuration.UseFamilyAndTypeNameForReference);
                entity.Set(s_setupExportPartsAsBuildingElements, configuration.ExportPartsAsBuildingElements);

                configStorage.SetEntity(entity);
            }

            List<ElementId> elementsToDelete = new List<ElementId>();
            for (; savedConfigurationIndex < savedConfigurationCount; savedConfigurationIndex++)
            {
                DataStorage configStorage = savedConfigurations[savedConfigurationIndex];
                elementsToDelete.Add(configStorage.Id);
            }
            if (elementsToDelete.Count > 0)
                document.Delete(elementsToDelete);

            transaction.Commit();
        }
        private Schema GetStorageSchema()
        {
            var bld = new SchemaBuilder(_schemaGuid);
            bld.SetSchemaName("BimLibraryData");
            bld.SetWriteAccessLevel(AccessLevel.Public);
            bld.SetReadAccessLevel(AccessLevel.Public);
            //bld.SetVendorId("ADSK");
            bld.SetDocumentation("This schema stores project specific application data of Czech BIM Library.");
            bld.AddSimpleField(FieldNameData, typeof(String)).SetDocumentation("Data field");

            return bld.Finish();
        }
        // Create a data structure, attach it to a wall, populate it with data, and retrieve the data back from the wall
        public void CreateSchemeAndStoreData(FamilySymbol titleblock)
        {
            SchemaBuilder schemaBuilder = new SchemaBuilder(new Guid("1a68d420-96dd-44aa-a1de-000774a6104b"));
            schemaBuilder.SetReadAccessLevel(AccessLevel.Public); // allow anyone to read the object
            schemaBuilder.SetSchemaName("TitleBlockSettings");

            // create a field to store data
            FieldBuilder fieldBuilder_titleblockName = schemaBuilder.AddSimpleField("titleblockName", typeof(string));

            FieldBuilder fieldBuilder_cellSizeDistance_X = schemaBuilder.AddSimpleField("cellSizeDistance_X", typeof(string));
            //fieldBuilder_cellSizeDistance_X.SetUnitType(UnitType.UT_Length);
            FieldBuilder fieldBuilder_lowerGap_X = schemaBuilder.AddSimpleField("lowerGap_X", typeof(string));
            //fieldBuilder_lowerGap_X.SetUnitType(UnitType.UT_Length);
            FieldBuilder fieldBuilder_additionalEdge_X = schemaBuilder.AddSimpleField("additionalEdge_X", typeof(string));
            //fieldBuilder_additionalEdge_X.SetUnitType(UnitType.UT_Length);
            FieldBuilder fieldBuilder_fineTune_X = schemaBuilder.AddSimpleField("fineTune_X", typeof(string));
            //fieldBuilder_fineTune_X.SetUnitType(UnitType.UT_Length);

            FieldBuilder fieldBuilder_cellSizeDistance_Y = schemaBuilder.AddSimpleField("cellSizeDistance_Y", typeof(string));
            //fieldBuilder_cellSizeDistance_Y.SetUnitType(UnitType.UT_Length);
            FieldBuilder fieldBuilder_lowerGap_Y = schemaBuilder.AddSimpleField("lowerGap_Y", typeof(string));
            //fieldBuilder_lowerGap_Y.SetUnitType(UnitType.UT_Length);
            FieldBuilder fieldBuilder_additionalEdge_Y = schemaBuilder.AddSimpleField("additionalEdge_Y", typeof(string));
            //fieldBuilder_additionalEdge_Y.SetUnitType(UnitType.UT_Length);
            FieldBuilder fieldBuilder_fineTune_Y = schemaBuilder.AddSimpleField("fineTune_Y", typeof(string));
            //fieldBuilder_fineTune_Y.SetUnitType(UnitType.UT_Length);

            FieldBuilder fieldBuilder_cellGrid_Length = schemaBuilder.AddSimpleField("cellGrid_Length", typeof(string));
            FieldBuilder fieldBuilder_cellGrid_Height = schemaBuilder.AddSimpleField("cellGrid_Height", typeof(string));

            //fieldBuilder.SetDocumentation("store length of cell size in X direction.");

            Schema schema = schemaBuilder.Finish(); // register the Schema object
        }
        /// <summary>
        /// the IFC Classification Manager
        /// </summary>
        /// <param name="document">The document.</param>
        public IFCClassificationMgr(Document document)
        {
            if (Schema == null)
            {
                SchemaBuilder classificationBuilder = new SchemaBuilder(s_schemaId);
                classificationBuilder.SetSchemaName("IFCClassification");
                classificationBuilder.AddSimpleField(s_ClassificationName, typeof(string));
                classificationBuilder.AddSimpleField(s_ClassificationSource, typeof(string));
                classificationBuilder.AddSimpleField(s_ClassificationEdition, typeof(string));
                classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Day, typeof(Int32));
                classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Month, typeof(Int32));
                classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Year, typeof(Int32));
                classificationBuilder.AddSimpleField(s_ClassificationLocation, typeof(string));
                classificationBuilder.AddSimpleField(s_ClassificationFieldName, typeof(string));
                m_schema = classificationBuilder.Finish();
            }

            // Potentially delete obsolete schema.
            if (SchemaV1 != null)
            {
                IList<IFCClassification> classifications;
                bool hasOldClassifications = GetSavedClassifications(document, SchemaV1, out classifications);
                if (hasOldClassifications)
                {
                    Transaction transaction = new Transaction(document, "Upgrade saved IFC classification");
                    transaction.Start();

                    IList<DataStorage> oldSchemaData = GetClassificationInStorage(document, SchemaV1);
                    IList<ElementId> oldDataToDelete = new List<ElementId>();

                    foreach (DataStorage oldData in oldSchemaData)
                    {
                        Entity savedClassification = oldData.GetEntity(SchemaV1);

                        DataStorage classificationStorage = DataStorage.Create(document);
                        Entity entIFCClassification = new Entity(Schema);
                        string classificationName = savedClassification.Get<string>(s_ClassificationName);
                        if (classificationName != null) entIFCClassification.Set<string>(s_ClassificationName, classificationName);

                        string classificationSource = savedClassification.Get<string>(s_ClassificationSource);
                        if (classificationSource != null) entIFCClassification.Set<string>(s_ClassificationSource, classificationSource);

                        string classificationEdition = savedClassification.Get<string>(s_ClassificationEdition);
                        if (classificationEdition != null) entIFCClassification.Set<string>(s_ClassificationEdition, classificationEdition);

                        Int32 classificationEditionDateDay = savedClassification.Get<Int32>(s_ClassificationEditionDate_Day);
                        Int32 classificationEditionDateMonth = savedClassification.Get<Int32>(s_ClassificationEditionDate_Month);
                        Int32 classificationEditionDateYear = savedClassification.Get<Int32>(s_ClassificationEditionDate_Year);

                        entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Day, classificationEditionDateDay);
                        entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Month, classificationEditionDateMonth);
                        entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Year, classificationEditionDateYear);

                        string classificationLocation = savedClassification.Get<string>(s_ClassificationLocation);
                        if (classificationLocation != null) entIFCClassification.Set<string>(s_ClassificationLocation, classificationLocation);
                        
                        classificationStorage.SetEntity(entIFCClassification);
                        oldDataToDelete.Add(oldData.Id);
                    }

                    if (oldDataToDelete.Count > 0)
                        document.Delete(oldDataToDelete);
                    transaction.Commit();
                }
            }
        }