Exemplo n.º 1
0
        public static string ParameterToString(Document doc, FamilyParameter param, FamilyType type)
        {
            if (!type.HasValue(param))
            {
                return("无");
            }
            if (param.Definition.ParameterType == ParameterType.Invalid)
            {
                return("不可用");
            }
            switch (param.StorageType)
            {
            case StorageType.Double:
#if R2014
                var uStr = FormatUtils.Format(doc, param.Definition.UnitType, type.AsDouble(param).Value);
#else
                var uStr = UnitFormatUtils.Format(doc.GetUnits(), param.Definition.UnitType, type.AsDouble(param).Value, false, false);
#endif
                return(uStr);

            //var uStr = string.Empty;
            //if (param.Definition.ParameterType == ParameterType.Length)
            //{
            //    uStr = GetParamaterUnit(param.DisplayUnitType);
            //}
            //var dStr = param.AsValueString();
            //if (!String.IsNullOrEmpty(uStr) && !dStr.EndsWith(uStr)) dStr += uStr;
            //return dStr;
            case StorageType.Integer:
                var v = type.AsInteger(param).Value;
                if (param.Definition.ParameterType == ParameterType.YesNo)
                {
                    if (v == 0)
                    {
                        return("否");
                    }
                    return("是");
                }
#if R2014
                return(FormatUtils.Format(doc, param.Definition.UnitType, v));
#else
                return(UnitFormatUtils.Format(doc.GetUnits(), param.Definition.UnitType, v, false, false));
#endif
            case StorageType.String:
                return(type.AsString(param));

            case StorageType.ElementId:
                ElementId idVal = type.AsElementId(param);
                return(AsElementName(doc, idVal));

            case StorageType.None:
            default:
                return("无");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ask the user to open a revit family template and then add FamilyTypes and FamilyParameters
        /// to it. Say the user opens a Door template, he can then save the family as a new door family and load
        /// it into a new project for use.
        /// </summary>
        public void AddFamilyParameterAndType()
        {
            Document doc;

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "Select family document";
            openFileDialog.Filter = "RFT Files (*.rft)|*.rft";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                doc = m_revitApp.Application.NewFamilyDocument(openFileDialog.FileName);
            }
            else
            {
                return;
            }

            using (Transaction transaction = new Transaction(m_revitApp.ActiveUIDocument.Document))
            {
                transaction.Start("AddFamilyParameterAndType");

                if (doc.IsFamilyDocument)
                { // has to be a family document to be able to use the Family Manager.
                    FamilyManager famMgr = doc.FamilyManager;

                    //Add a family param.
                    FamilyParameter famParam = famMgr.AddParameter("RevitLookup_Param", BuiltInParameterGroup.PG_TITLE, ParameterType.Text, false);
                    famMgr.Set(famParam, "Default text.");

                    //Create a couple of new family types. Note that we can set different values for the param
                    //in different family types.

                    FamilyType newFamType = famMgr.NewType("RevitLookup_Type1");
                    famMgr.CurrentType = newFamType;

                    if (newFamType.HasValue(famParam))
                    {
                        famMgr.Set(famParam, "Text1.");
                    }

                    FamilyType newFamType1 = famMgr.NewType("RevitLookup_Type2");
                    famMgr.CurrentType = newFamType;

                    if (newFamType.HasValue(famParam))
                    {
                        famMgr.Set(famParam, "Text2.");
                    }

                    famMgr.MakeType(famParam);

                    if ((famParam != null) && (newFamType != null))
                    {
                        MessageBox.Show("New family types/params added successfully.", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Family types/params addition failed.", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                transaction.Commit();
            }
        }
        /// <summary>
        /// The method is used to collect template information, specifying the New Window Parameters
        /// </summary>
        private void CollectTemplateInfo()
        {
            List <Wall> walls = Utility.GetElements <Wall>(m_application, m_document);

            m_wallThickness = walls[0].Width;
            ParameterMap paraMap        = walls[0].ParametersMap;
            Parameter    wallheightPara = walls[0].get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);//paraMap.get_Item("Unconnected Height");

            if (wallheightPara != null)
            {
                m_wallHeight = wallheightPara.AsDouble();
            }

            LocationCurve location = walls[0].Location as LocationCurve;

            m_wallWidth = location.Curve.Length;

            m_windowInset = m_wallThickness / 10;
            FamilyType      type           = m_familyManager.CurrentType;
            FamilyParameter heightPara     = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT);
            FamilyParameter widthPara      = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH);
            FamilyParameter sillHeightPara = m_familyManager.get_Parameter("Default Sill Height");

            if (type.HasValue(heightPara))
            {
                switch (heightPara.StorageType)
                {
                case StorageType.Double:
                    m_height = type.AsDouble(heightPara).Value;
                    break;

                case StorageType.Integer:
                    m_height = type.AsInteger(heightPara).Value;
                    break;
                }
            }
            if (type.HasValue(widthPara))
            {
                switch (widthPara.StorageType)
                {
                case StorageType.Double:
                    m_width = type.AsDouble(widthPara).Value;
                    break;

                case StorageType.Integer:
                    m_width = type.AsDouble(widthPara).Value;
                    break;
                }
            }
            if (type.HasValue(sillHeightPara))
            {
                switch (sillHeightPara.StorageType)
                {
                case StorageType.Double:
                    m_sillHeight = type.AsDouble(sillHeightPara).Value;
                    break;

                case StorageType.Integer:
                    m_sillHeight = type.AsDouble(sillHeightPara).Value;
                    break;
                }
            }

            //set the height,width and sillheight parameter of the opening
            m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT),
                                m_height);
            m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH),
                                m_width);
            m_familyManager.Set(m_familyManager.get_Parameter("Default Sill Height"), m_sillHeight);

            //get materials

            FilteredElementCollector elementCollector = new FilteredElementCollector(m_document);

            elementCollector.WherePasses(new ElementClassFilter(typeof(Material)));
            IList <Element> materials = elementCollector.ToElements();

            foreach (Element materialElement in materials)
            {
                Material material = materialElement as Material;
                m_para.GlassMaterials.Add(material.Name);
                m_para.FrameMaterials.Add(material.Name);
            }

            //get categories
            Categories      categories = m_document.Settings.Categories;
            Category        category   = categories.get_Item(BuiltInCategory.OST_Windows);
            CategoryNameMap cnm        = category.SubCategories;

            m_frameCat = categories.get_Item(BuiltInCategory.OST_WindowsFrameMullionProjection);
            m_glassCat = categories.get_Item(BuiltInCategory.OST_WindowsGlassProjection);

            //get referenceplanes
            List <ReferencePlane> planes = Utility.GetElements <ReferencePlane>(m_application, m_document);

            foreach (ReferencePlane p in planes)
            {
                if (p.Name.Equals("Sash"))
                {
                    m_sashPlane = p;
                }
                if (p.Name.Equals("Exterior"))
                {
                    m_exteriorPlane = p;
                }
                if (p.Name.Equals("Center (Front/Back)"))
                {
                    m_centerPlane = p;
                }
                if (p.Name.Equals("Top") || p.Name.Equals("Head"))
                {
                    m_topPlane = p;
                }
                if (p.Name.Equals("Sill") || p.Name.Equals("Bottom"))
                {
                    m_sillPlane = p;
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Check parameter conditions
 /// </summary>
 /// <param name="fp"></param>
 /// <param name="ft"></param>
 /// <returns></returns>
 private Boolean famEdit(FamilyParameter fp, FamilyType ft)
 {
     //double valueDouble;
     //int valueInt;
     if (!fp.StorageType.ToString().Equals("Double") && !fp.StorageType.ToString().Equals("Integer"))
     {
         return false;
     }
     else if (fp.UserModifiable)
     {
         return false;
     }
     else if (fp.IsDeterminedByFormula || fp.Formula != null)
     {
         return false;
     }
     else if (!ft.HasValue(fp))
     {
         return false;
     }
     else if (ft.AsDouble(fp) == null && ft.AsInteger(fp) == null)
     {
         return false;
     }
     //else if (!double.TryParse(ft.AsDouble(fp).ToString(), out valueDouble) && !int.TryParse(ft.AsInteger(fp).ToString(), out valueInt))
     //{
     //    return false;
     //}
     else if (fp.IsReporting)
     {
         return false;
     }
     else if (fp.IsDeterminedByFormula)
     {
         return false;
     }
     return true;
 }
Exemplo n.º 5
0
 public CFamilyParameter(FamilyParameter oParam, FamilyType oFamType)
 {
     //IL_0028: Unknown result type (might be due to invalid IL or missing references)
     //IL_0029: Unknown result type (might be due to invalid IL or missing references)
     //IL_0039: Unknown result type (might be due to invalid IL or missing references)
     //IL_003a: Unknown result type (might be due to invalid IL or missing references)
     //IL_003f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0045: Unknown result type (might be due to invalid IL or missing references)
     //IL_0051: Unknown result type (might be due to invalid IL or missing references)
     //IL_0052: Unknown result type (might be due to invalid IL or missing references)
     //IL_0061: Unknown result type (might be due to invalid IL or missing references)
     //IL_0062: Unknown result type (might be due to invalid IL or missing references)
     //IL_006e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0074: Invalid comparison between Unknown and I4
     //IL_0076: Unknown result type (might be due to invalid IL or missing references)
     //IL_0077: Unknown result type (might be due to invalid IL or missing references)
     //IL_007c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0083: Invalid comparison between Unknown and I4
     //IL_0085: Unknown result type (might be due to invalid IL or missing references)
     //IL_0086: Unknown result type (might be due to invalid IL or missing references)
     //IL_00bc: Unknown result type (might be due to invalid IL or missing references)
     //IL_00c2: Invalid comparison between Unknown and I4
     //IL_00c5: Unknown result type (might be due to invalid IL or missing references)
     //IL_00c6: Unknown result type (might be due to invalid IL or missing references)
     //IL_00e1: Unknown result type (might be due to invalid IL or missing references)
     //IL_00e7: Invalid comparison between Unknown and I4
     //IL_00ea: Unknown result type (might be due to invalid IL or missing references)
     //IL_00eb: Unknown result type (might be due to invalid IL or missing references)
     //IL_010f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0115: Invalid comparison between Unknown and I4
     //IL_0118: Unknown result type (might be due to invalid IL or missing references)
     //IL_0119: Unknown result type (might be due to invalid IL or missing references)
     this.Name             = oParam.get_Definition().get_Name();
     this.ParamStorageType = oParam.get_StorageType();
     this.TypeName         = oFamType.get_Name();
     this.ID = oParam.get_Id().get_IntegerValue();
     if (oFamType.HasValue(oParam))
     {
         if ((int)this.ParamStorageType == 1 && (int)oParam.get_Definition().get_ParameterType() == 10)
         {
             if (oFamType.AsInteger(oParam) == 1)
             {
                 this.Value = "Yes";
             }
             else
             {
                 this.Value = "No";
             }
         }
         else if ((int)this.ParamStorageType == 1)
         {
             this.Value = oFamType.AsInteger(oParam).ToString();
         }
         else if ((int)this.ParamStorageType == 2)
         {
             this.Value = Math.Round(oFamType.AsDouble(oParam).Value, 2).ToString();
         }
         else if ((int)this.ParamStorageType == 3)
         {
             this.Value = oFamType.AsString(oParam);
         }
     }
 }