Exemple #1
0
        public static void GetFamilyTemplateReferencePlanes(FamilyTemplate famTemplate, Document doc, User user)
        {
            if (doc != null)
            {
                if (famTemplate.FamilyTemplateReferencePlanes.InternalCollection.Count <= 0)
                {
                    List <Element> referencePlaneElementList = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.ReferencePlane)).ToElements() as List <Element>;
                    foreach (Element element in referencePlaneElementList)
                    {
                        Autodesk.Revit.DB.ReferencePlane plane = (Autodesk.Revit.DB.ReferencePlane)element as Autodesk.Revit.DB.ReferencePlane;
                        ReferencePlane refPlane = ReferencePlane.NewReferencePlane(famTemplate.internalSQLConenction, famTemplate.FamilyTemplateReferencePlanes.InternalDataView, user);
                        refPlane.Name      = plane.Name;
                        refPlane.FamiltyId = famTemplate.Id;
                        refPlane.ElementId = plane.Id.IntegerValue;
                        refPlane.UniqueId  = plane.UniqueId;
                        refPlane.LevelId   = plane.LevelId.IntegerValue;
                        refPlane.ViewId    = plane.OwnerViewId.IntegerValue;

                        if (plane.Category != null)
                        {
                            refPlane.Category = plane.Category.Name;
                        }
                        else
                        {
                            refPlane.Category = "None";
                        }

                        refPlane.DirectionX   = plane.Direction.X;
                        refPlane.DirectionY   = plane.Direction.Y;
                        refPlane.DirectionZ   = plane.Direction.Z;
                        refPlane.BubbleEndX   = plane.BubbleEnd.X;
                        refPlane.BubbleEndY   = plane.BubbleEnd.Y;
                        refPlane.BubbleEndZ   = plane.BubbleEnd.Z;
                        refPlane.NormalX      = plane.Normal.X;
                        refPlane.NormalY      = plane.Normal.Y;
                        refPlane.NormalZ      = plane.Normal.Z;
                        refPlane.FreeEndX     = plane.FreeEnd.X;
                        refPlane.FreeEndY     = plane.FreeEnd.Y;
                        refPlane.FreeEndZ     = plane.FreeEnd.Z;
                        refPlane.IsActive     = true;
                        refPlane.CreatedById  = user.Id;
                        refPlane.CreatedBy    = user;
                        refPlane.ModifiedBy   = user;
                        refPlane.ModifiedById = user.Id;
                        refPlane.EndEdit();
                    }
                }
                else
                {
                }
            }
        }
Exemple #2
0
        public static void GetFamilyTemplateParameters(FamilyTemplate famTemplate, Document doc, User user)
        {
            if (famTemplate.FamilyTemplateParameters.InternalCollection.Count <= 0)
            {
                foreach (Autodesk.Revit.DB.FamilyParameter item in doc.FamilyManager.Parameters)
                {
                    Parameter parameter = Parameter.newParameter(famTemplate.internalSQLConenction, famTemplate.FamilyTemplateParameters.InternalDataView, user);
                    parameter.FamilyId  = famTemplate.Id;
                    parameter.Name      = item.Definition.Name;
                    parameter.ElementId = item.Id.IntegerValue;
                    parameter.IsShared  = item.IsShared;
                    if (parameter.IsShared)
                    {
                        parameter.ElementGUID = item.GUID.ToString();
                    }
                    else
                    {
                        parameter.ElementGUID = string.Empty;
                    }
                    parameter.HasValue          = false;
                    parameter.IsInstance        = item.IsInstance;
                    parameter.IsReadOnly        = item.IsReadOnly;
                    parameter.IsReporting       = item.IsReporting;
                    parameter.StorageType       = (int)item.StorageType;
                    parameter.BuiltInParamGroup = (int)item.Definition.ParameterGroup;
                    parameter.ParameterType     = (int)item.Definition.ParameterType;
                    parameter.UnitType          = (int)item.Definition.UnitType;

                    try
                    {
                        parameter.DisplayUnitType = (int)item.DisplayUnitType;
                    }
                    catch
                    {
                        parameter.DisplayUnitType = (int)Autodesk.Revit.DB.DisplayUnitType.DUT_UNDEFINED;
                    }

                    parameter.UserModifiable        = item.UserModifiable;
                    parameter.IsDeterminedByFormula = item.IsDeterminedByFormula;
                    parameter.Formula    = item.Formula;
                    parameter.IsActive   = false;
                    parameter.IsEditable = true;
                    parameter.EndEdit();
                }
            }
        }
Exemple #3
0
        internal static FamilyTemplateComponent NewTemplateComponent(SQLiteConnection connection, DataView dataVew, User user, FamilyTemplate parent)
        {
            FamilyTemplateComponent component = new FamilyTemplateComponent(dataVew.AddNew(), connection, user);

            component.Id = Guid.NewGuid().ToString();
            component.FamilyComponentTypeId = component.FamilyComponentTypes[0].Id;
            component.DateCreated           = DateTime.Now;
            component.DateModified          = DateTime.Now;
            component.CreatedById           = user.Id;
            component.ModifiedById          = user.Id;
            component.CreatedBy             = user;
            component.ModifiedBy            = user;
            component.FamilyId = parent.Id;
            component.RefreshCollections();
            component.XReferencePlane   = component.ParentReferencePlanes[0];
            component.XReferencePlaneId = component.XReferencePlane.Id;
            component.YReferencePlane   = component.ParentReferencePlanes[0];
            component.YReferencePlaneId = component.YReferencePlane.Id;
            component.ZReferencePlane   = component.ParentReferencePlanes[0];
            component.ZReferencePlaneId = component.ZReferencePlane.Id;
            component.IsProfile         = false;
            if (component.ParentGeometries.Count > 0)
            {
                component.ProfileGeometryId = component.ParentGeometries[0].Id;
            }
            component.ProfileTypeNameId       = "Type1";
            component.ProfileVerticalOffset   = 0;
            component.ProfileHorizontalOffset = 0;
            component.ProfileAngle            = 0;
            component.ProfileIsFlipped        = false;
            return(component);
        }
Exemple #4
0
        public static void GetFamilyTemplateFeatures(FamilyTemplate template, Document doc, User user)
        {
            if (template.FamilyTemplateGeometries.InternalCollection.Count <= 0)
            {
                if (doc != null)
                {
                    List <Element> sweepElementList      = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Sweep)).ToElements() as List <Element>;
                    List <Element> extrudeElementList    = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Extrusion)).ToElements() as List <Element>;
                    List <Element> blendElementList      = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Blend)).ToElements() as List <Element>;
                    List <Element> sweptBlendElementList = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.SweptBlend)).ToElements() as List <Element>;
                    List <Element> revolveElementList    = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Revolution)).ToElements() as List <Element>;

                    foreach (Element element in sweepElementList)
                    {
                        Autodesk.Revit.DB.Sweep sweep          = (Autodesk.Revit.DB.Sweep)element as Autodesk.Revit.DB.Sweep;
                        FamilyGeometry          familyGeometry = FamilyGeometry.NewFamilyGeometry(template.FamilyTemplateGeometries.SQLiteConnection, template.FamilyTemplateGeometries.InternalDataView, user);
                        familyGeometry.Name        = sweep.Name;
                        familyGeometry.ElementId   = sweep.Id.IntegerValue;
                        familyGeometry.Description = string.Empty;

                        if (sweep.Category != null)
                        {
                            familyGeometry.Category = sweep.Category.Name;
                        }
                        else
                        {
                            familyGeometry.Category = "None";
                        }

                        if (sweep.Subcategory != null)
                        {
                            familyGeometry.SubCategory = sweep.Subcategory.Name;
                        }
                        else
                        {
                            familyGeometry.SubCategory = "None";
                        }

                        familyGeometry.FamilyId     = template.Id;
                        familyGeometry.GeometryType = sweep.Name;
                        familyGeometry.UniqueId     = sweep.UniqueId;
                        familyGeometry.OwnerViewId  = sweep.OwnerViewId.IntegerValue;
                        familyGeometry.LevelId      = sweep.LevelId.IntegerValue;
                        familyGeometry.IsSolid      = sweep.IsSolid;
                        familyGeometry.MaterialId   = 0;
                        familyGeometry.CreatedById  = user.Id;
                        familyGeometry.CreatedBy    = user;
                        familyGeometry.ModifiedBy   = user;
                        familyGeometry.ModifiedById = user.Id;
                        familyGeometry.EndEdit();
                    }

                    foreach (Element element in extrudeElementList)
                    {
                        Autodesk.Revit.DB.Extrusion extrude = (Autodesk.Revit.DB.Extrusion)element as Autodesk.Revit.DB.Extrusion;
                        FamilyGeometry familyGeometry       = FamilyGeometry.NewFamilyGeometry(template.FamilyTemplateGeometries.SQLiteConnection, template.FamilyTemplateGeometries.InternalDataView, user);
                        familyGeometry.Name        = extrude.Name;
                        familyGeometry.ElementId   = extrude.Id.IntegerValue;
                        familyGeometry.Description = string.Empty;

                        if (extrude.Category != null)
                        {
                            familyGeometry.Category = extrude.Category.Name;
                        }
                        else
                        {
                            familyGeometry.Category = "None";
                        }

                        if (extrude.Subcategory != null)
                        {
                            familyGeometry.SubCategory = extrude.Subcategory.Name;
                        }
                        else
                        {
                            familyGeometry.SubCategory = "None";
                        }

                        familyGeometry.FamilyId     = template.Id;
                        familyGeometry.GeometryType = extrude.Name;
                        familyGeometry.UniqueId     = extrude.UniqueId;
                        familyGeometry.OwnerViewId  = extrude.OwnerViewId.IntegerValue;
                        familyGeometry.LevelId      = extrude.LevelId.IntegerValue;
                        familyGeometry.IsSolid      = extrude.IsSolid;
                        familyGeometry.MaterialId   = 0;
                        familyGeometry.CreatedById  = user.Id;
                        familyGeometry.CreatedBy    = user;
                        familyGeometry.ModifiedBy   = user;
                        familyGeometry.ModifiedById = user.Id;
                        familyGeometry.EndEdit();
                    }
                    foreach (Element element in blendElementList)
                    {
                        Autodesk.Revit.DB.Blend blend          = (Autodesk.Revit.DB.Blend)element as Autodesk.Revit.DB.Blend;
                        FamilyGeometry          familyGeometry = FamilyGeometry.NewFamilyGeometry(template.FamilyTemplateGeometries.SQLiteConnection, template.FamilyTemplateGeometries.InternalDataView, user);
                        familyGeometry.Name        = blend.Name;
                        familyGeometry.ElementId   = blend.Id.IntegerValue;
                        familyGeometry.Description = string.Empty;

                        if (blend.Category != null)
                        {
                            familyGeometry.Category = blend.Category.Name;
                        }
                        else
                        {
                            familyGeometry.Category = "None";
                        }

                        if (blend.Subcategory != null)
                        {
                            familyGeometry.SubCategory = blend.Subcategory.Name;
                        }
                        else
                        {
                            familyGeometry.SubCategory = "None";
                        }

                        familyGeometry.FamilyId     = template.Id;
                        familyGeometry.GeometryType = blend.Name;
                        familyGeometry.UniqueId     = blend.UniqueId;
                        familyGeometry.OwnerViewId  = blend.OwnerViewId.IntegerValue;
                        familyGeometry.LevelId      = blend.LevelId.IntegerValue;
                        familyGeometry.IsSolid      = blend.IsSolid;
                        familyGeometry.MaterialId   = 0;
                        familyGeometry.CreatedById  = user.Id;
                        familyGeometry.CreatedBy    = user;
                        familyGeometry.ModifiedBy   = user;
                        familyGeometry.ModifiedById = user.Id;
                        familyGeometry.EndEdit();
                    }
                    foreach (Element element in sweptBlendElementList)
                    {
                        Autodesk.Revit.DB.SweptBlend weptblend = (Autodesk.Revit.DB.SweptBlend)element as Autodesk.Revit.DB.SweptBlend;
                        FamilyGeometry familyGeometry          = FamilyGeometry.NewFamilyGeometry(template.FamilyTemplateGeometries.SQLiteConnection, template.FamilyTemplateGeometries.InternalDataView, user);
                        familyGeometry.Name        = weptblend.Name;
                        familyGeometry.ElementId   = weptblend.Id.IntegerValue;
                        familyGeometry.Description = string.Empty;

                        if (weptblend.Category != null)
                        {
                            familyGeometry.Category = weptblend.Category.Name;
                        }
                        else
                        {
                            familyGeometry.Category = "None";
                        }

                        if (weptblend.Subcategory != null)
                        {
                            familyGeometry.SubCategory = weptblend.Subcategory.Name;
                        }
                        else
                        {
                            familyGeometry.SubCategory = "None";
                        }

                        familyGeometry.FamilyId     = template.Id;
                        familyGeometry.GeometryType = "SweptBlend";
                        familyGeometry.UniqueId     = weptblend.UniqueId;
                        familyGeometry.OwnerViewId  = weptblend.OwnerViewId.IntegerValue;
                        familyGeometry.LevelId      = weptblend.LevelId.IntegerValue;
                        familyGeometry.IsSolid      = weptblend.IsSolid;
                        familyGeometry.MaterialId   = 0;
                        familyGeometry.CreatedById  = user.Id;
                        familyGeometry.CreatedBy    = user;
                        familyGeometry.ModifiedBy   = user;
                        familyGeometry.ModifiedById = user.Id;
                        familyGeometry.EndEdit();
                    }
                    foreach (Element element in revolveElementList)
                    {
                        Autodesk.Revit.DB.Revolution revolve = (Autodesk.Revit.DB.Revolution)element as Autodesk.Revit.DB.Revolution;
                        FamilyGeometry familyGeometry        = FamilyGeometry.NewFamilyGeometry(template.FamilyTemplateGeometries.SQLiteConnection, template.FamilyTemplateGeometries.InternalDataView, user);
                        familyGeometry.Name        = revolve.Name;
                        familyGeometry.ElementId   = revolve.Id.IntegerValue;
                        familyGeometry.Description = string.Empty;

                        if (revolve.Category != null)
                        {
                            familyGeometry.Category = revolve.Category.Name;
                        }
                        else
                        {
                            familyGeometry.Category = "None";
                        }

                        if (revolve.Subcategory != null)
                        {
                            familyGeometry.SubCategory = revolve.Subcategory.Name;
                        }
                        else
                        {
                            familyGeometry.SubCategory = "None";
                        }

                        familyGeometry.FamilyId     = template.Id;
                        familyGeometry.GeometryType = revolve.Name;
                        familyGeometry.UniqueId     = revolve.UniqueId;
                        familyGeometry.OwnerViewId  = revolve.OwnerViewId.IntegerValue;
                        familyGeometry.LevelId      = revolve.LevelId.IntegerValue;
                        familyGeometry.IsSolid      = revolve.IsSolid;
                        familyGeometry.MaterialId   = 0;
                        familyGeometry.CreatedById  = user.Id;
                        familyGeometry.CreatedBy    = user;
                        familyGeometry.ModifiedBy   = user;
                        familyGeometry.ModifiedById = user.Id;
                        familyGeometry.EndEdit();
                    }
                }
            }
            else
            {
            }
        }