Exemplo n.º 1
0
        public static void SetWallTypeParam(this WallType wt, Param p, string value)
        {
            if (wt.get_Parameter(p.Guid) != null)
            {
                Parameter par = wt.get_Parameter(p.Guid);
                switch (par.StorageType)
                {
                default:
                case StorageType.String:
                    par.Set(value);
                    break;

                case StorageType.Double:
                    par.Set(double.Parse(value));
                    break;

                case StorageType.Integer:
                    par.Set(int.Parse(value));
                    break;

                case StorageType.ElementId:
                    ElementId mat = wt.Document.GetMaterial(value);
                    if (mat != null && mat != ElementId.InvalidElementId)
                    {
                        par.Set(mat);
                    }
                    break;
                }
            }
        }
        public bool IsExterior(WallType wallType)
        {
            Parameter p = wallType.get_Parameter(
                BuiltInParameter.FUNCTION_PARAM);

            Debug.Assert(null != p, "expected wall type "
                         + "to have wall function parameter");

            WallFunction f = (WallFunction)p.AsInteger();

            return(WallFunction.Exterior == f);
        }
Exemplo n.º 3
0
        public void SetTypeParameter(Document doc)
        {
            Element  e        = FindElementByName(doc, typeof(WallType), "Basic Wall");
            WallType wallType = doc.GetElement(e.Id) as WallType;

            try
            {
                using (Transaction t = new Transaction(doc))
                {
                    Parameter p = wallType.get_Parameter(BuiltInParameter.ALL_MODEL_COST);
                    p.Set(500);
                }
            }catch (Exception ex) { TaskDialog.Show("error", ex.Message); }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 基于指定字符串,寻找参数
        /// --异常显示 族样板中的已存在默认类别尺寸参数,将其修改为实例后,通过BuiltInParameter方式,仍可以获取非null的Parameter,但是该参数存储数据为空值
        /// </summary>
        /// <returns></returns>
        public static Parameter GetParameterByBuiltInParameter(this Element _elem, BuiltInParameter builtInParameter)
        {
            if (_elem is FamilyInstance)
            {
                if (_elem.Id == new ElementId(336349))
                {
                    Line   line = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 0, 0));
                    string test = "成功进入";
                    test.TaskDialogErrorMessage();
                }
                FamilyInstance fi = _elem as FamilyInstance;
                FamilySymbol   fs = fi.Symbol;

                Parameter parameter = fs.get_Parameter(builtInParameter);
                if (parameter == null)
                {
                    return(fi.get_Parameter(builtInParameter));
                }
                else
                {
                    return(parameter);
                }
            }
            else if (_elem is Wall)
            {
                Wall     fi = _elem as Wall;
                WallType fs = fi.WallType;

                Parameter parameter = fs.get_Parameter(builtInParameter);
                if (parameter == null)
                {
                    return(fi.get_Parameter(builtInParameter));
                }
                else
                {
                    return(parameter);
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        //Method to iterate over the elements of each category and fill in the dictionary
        private void FillDictionary(ICollection <Element> collectionElements, Dictionary <string, Dictionary <string, List <FamilyInstance> > > dict)
        {
            foreach (Element element in collectionElements)
            {
                FamilyInstance el         = element as FamilyInstance;
                Wall           wall       = (Wall)el.Host;
                WallType       sWall      = wall.WallType;
                string         modelGroup = sWall.get_Parameter(BuiltInParameter.ALL_MODEL_MODEL).AsString();
                string         cat        = el.Category.Name;
                double         width      = el.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM).AsDouble();



                if (!dict.ContainsKey(modelGroup))
                {
                    var newDict = new Dictionary <string, List <FamilyInstance> >();
                    var newList = new List <FamilyInstance>();
                    newList.Add(el);
                    newDict[cat] = newList;

                    dict.Add(modelGroup, newDict);
                }
                else
                {
                    if (!dict[modelGroup].ContainsKey(cat))
                    {
                        var newListInstance = new List <FamilyInstance>();
                        newListInstance.Add(el);
                        dict[modelGroup][cat] = newListInstance;
                    }
                    else
                    {
                        dict[modelGroup][cat].Add(el);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Find a specific family type for a wall, which is a system family.
        /// This version uses iteration. (cf. look for example, Developer guide 87)
        /// </summary>
        public Element FindFamilyType_Wall_v2(string wallFamilyName, string wallTypeName)
        {
            // First, narrow down the collector by Class
            var wallTypeCollector2 = new FilteredElementCollector(_doc).OfClass(typeof(WallType));

            // Use iterator
            FilteredElementIterator wallTypeItr = wallTypeCollector2.GetElementIterator();

            wallTypeItr.Reset();
            Element wallType2 = null;

            while (wallTypeItr.MoveNext())
            {
                WallType wType = (WallType)wallTypeItr.Current;
                // We check two names for the match: type name and family name.
                if ((wType.Name == wallTypeName) & (wType.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).AsString().Equals(wallFamilyName)))
                {
                    wallType2 = wType; // We found it.
                    break;
                }
            }

            return(wallType2);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            // Open source project

            Document docHasFamily = app.OpenDocumentFile(
                _source_project_path);

            // Find system family to copy, e.g. using a named wall type

            WallType wallType = null;

            //WallTypeSet wallTypes = docHasFamily.WallTypes; // 2013

            FilteredElementCollector wallTypes
                = new FilteredElementCollector(docHasFamily) // 2014
                  .OfClass(typeof(WallType));

            int i = 0;

            foreach (WallType wt in wallTypes)
            {
                string name = wt.Name;

                Debug.Print("  {0} {1}", ++i, name);

                if (name.Equals(_wall_type_name))
                {
                    wallType = wt;
                    break;
                }
            }

            if (null == wallType)
            {
                message = string.Format(
                    "Cannot find source wall type '{0}'"
                    + " in source document '{1}'. ",
                    _wall_type_name, _source_project_path);

                return(Result.Failed);
            }

            // Create a new wall type in current document

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Transfer Wall Type");

                WallType newWallType = null;

                //WallTypeSet wallTypes = doc.WallTypes; // 2013

                wallTypes = new FilteredElementCollector(doc)
                            .OfClass(typeof(WallType)); // 2014

                foreach (WallType wt in wallTypes)
                {
                    if (wt.Kind == wallType.Kind)
                    {
                        newWallType = wt.Duplicate(_wall_type_name)
                                      as WallType;

                        Debug.Print(string.Format(
                                        "New wall type '{0}' created.",
                                        _wall_type_name));

                        break;
                    }
                }

                // Assign parameter values from source wall type:

#if COPY_INDIVIDUAL_PARAMETER_VALUE
                // Example: individually copy the "Function" parameter value:

                BuiltInParameter bip      = BuiltInParameter.FUNCTION_PARAM;
                string           function = wallType.get_Parameter(bip).AsString();
                Parameter        p        = newWallType.get_Parameter(bip);
                p.Set(function);
#endif // COPY_INDIVIDUAL_PARAMETER_VALUE

                Parameter p = null;

                foreach (Parameter p2 in newWallType.Parameters)
                {
                    Definition d = p2.Definition;

                    if (p2.IsReadOnly)
                    {
                        Debug.Print(string.Format(
                                        "Parameter '{0}' is read-only.", d.Name));
                    }
                    else
                    {
                        p = wallType.get_Parameter(d);

                        if (null == p)
                        {
                            Debug.Print(string.Format(
                                            "Parameter '{0}' not found on source wall type.",
                                            d.Name));
                        }
                        else
                        {
                            if (p.StorageType == StorageType.ElementId)
                            {
                                // Here you have to find the corresponding
                                // element in the target document.

                                Debug.Print(string.Format(
                                                "Parameter '{0}' is an element id.",
                                                d.Name));
                            }
                            else
                            {
                                if (p.StorageType == StorageType.Double)
                                {
                                    p2.Set(p.AsDouble());
                                }
                                else if (p.StorageType == StorageType.String)
                                {
                                    p2.Set(p.AsString());
                                }
                                else if (p.StorageType == StorageType.Integer)
                                {
                                    p2.Set(p.AsInteger());
                                }
                                Debug.Print(string.Format(
                                                "Parameter '{0}' copied.", d.Name));
                            }
                        }
                    }

                    // Note:
                    // If a shared parameter parameter is attached,
                    // you need to create the shared parameter first,
                    // then copy the parameter value.
                }

                // If the system family type has some other properties,
                // you need to copy them as well here. Reflection can
                // be used to determine the available properties.

                MemberInfo[] memberInfos = newWallType.GetType()
                                           .GetMembers(BindingFlags.GetProperty);

                foreach (MemberInfo m in memberInfos)
                {
                    // Copy the writable property values here.
                    // As there are no property writable for
                    // Walltype, I ignore this process here.
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 8
0
        public bool GetTheTypes(ExternalCommandData commandData, String _selectedWallTypeName)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document  doc       = uidoc.Document;
            Selection selection = uidoc.Selection;

            //read the settings file
            cmdSettingsReadWrite cls  = new cmdSettingsReadWrite();
            string _sourceProjectPath = cls.GetSetting("<GETTER_SOURCE_PROJECT>");

            //open source project
            Document _openedSourceDoc = app.OpenDocumentFile(_sourceProjectPath);


            WallType _selectedWallType = null;

            //get the wall types in the source doc
            FilteredElementCollector sourceWallTypes = new FilteredElementCollector(_openedSourceDoc).OfClass(typeof(WallType));

            foreach (WallType wt in sourceWallTypes)
            {
                if (wt.Name == _selectedWallTypeName)
                {
                    //the name matches
                    _selectedWallType = wt;
                }
            }


            //Create a wall type in the current document

            using (Transaction tx = new Transaction(doc, "Get Types"))
            {
                tx.Start("Transfer Wall Type");

                WallType newWallType = null;

                //get the wall types in the current doc
                FilteredElementCollector wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType));

                foreach (WallType wt in wallTypes)
                {
                    if (wt.Kind == _selectedWallType.Kind)
                    {
                        newWallType = wt.Duplicate(_selectedWallTypeName) as WallType;

                        TaskDialog.Show("Wall Created", "The selected wall has been created.");

                        break;
                    }
                }


                // Assign parameter values from source wall type:

#if COPY_INDIVIDUAL_PARAMETER_VALUE
                // Example: individually copy the "Function" parameter value:

                BuiltInParameter bip      = BuiltInParameter.FUNCTION_PARAM;
                string           function = wallType.get_Parameter(bip).AsString();
                Parameter        p        = newWallType.get_Parameter(bip);
                p.Set(function);


                BuiltInParameter bip            = BuiltInParameter.WALL_ATTR_WIDTH_PARAM;
                Double           _selectedWidth = _selectedWallType.get_Parameter(bip).AsDouble();
                Parameter        newWallWidth   = newWallType.get_Parameter(bip);
                newWallWidth.Set(_selectedWidth);
#endif // COPY_INDIVIDUAL_PARAMETER_VALUE



                Parameter p = null;

                foreach (Parameter p2 in newWallType.Parameters)
                {
                    Definition d = p2.Definition;

                    if (p2.IsReadOnly)
                    {
                        System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' is read-only.", d.Name));
                    }
                    else
                    {
                        p = newWallType.get_Parameter(d);

                        if (null == p)
                        {
                            System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' not found on source wall type.", d.Name));
                        }
                        else
                        {
                            if (p.StorageType == StorageType.ElementId)
                            {
                                // Here you have to find the corresponding
                                // element in the target document.

                                System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' is an element id.", d.Name));
                            }
                            else
                            {
                                if (p.StorageType == StorageType.String)
                                {
                                    p2.Set(p.AsString());
                                }
                                else if (p.StorageType == StorageType.Double)
                                {
                                    p2.Set(p.AsDouble());
                                }
                                else if (p.StorageType == StorageType.Integer)
                                {
                                    p2.Set(p.AsInteger());
                                }
                                System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' copied.", d.Name));
                            }
                        }
                    }
                }

                TaskDialog.Show("Parameter Set", "The walls parameters have been set.");

                MemberInfo[] memberInfos = newWallType.GetType().GetMembers(BindingFlags.GetProperty);

                foreach (MemberInfo m in memberInfos)
                {
                    // Copy the writable property values here.
                    // As there are no property writable for
                    // Walltype, I ignore this process here.
                }

                tx.Commit();
                tx.Dispose();
            }

            return(true);
        }
Exemplo n.º 9
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;


            // Open source project
            Document docHasFamily = app.OpenDocumentFile(_source_project_path);

            // Find system family to copy, e.g. using a named wall type
            WallType _selectedWallType = null;

            FilteredElementCollector wallTypes
                = new FilteredElementCollector(docHasFamily) // 2014
                  .OfClass(typeof(WallType));

            int i = 0;



            foreach (WallType wt in wallTypes)
            {
                //Add the wall type to the list
                m_data.Add(wt.Name);
            }

            //show the form and get a value back from it
            //See this page for example: https://stackoverflow.com/questions/5233502/how-to-return-a-value-from-a-form-in-c
            using (var f = new frmListDialog(m_data))
            {
                var result = f.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    _selectedWallTypeName = f.ReturnValue1; //values preserved after close

                    //loop thru and find the wall type the matches the name
                    foreach (WallType wt in wallTypes)
                    {
                        if (wt.Name == _selectedWallTypeName)
                        {
                            //if its a match then...
                            _selectedWallType = wt;
                            //_selectedWallTypeName = wt.Name;
                        }
                    }
                }
            }



            //foreach( WallType wt in wallTypes )
            //{
            //  string name = wt.Name;

            //  Debug.Print( "  {0} {1}", ++i, name );

            //  if( name.Equals( _selectedWallTypeName ) )
            //  {
            //    _selectedWallType = wt;
            //    break;
            //  }
            //}

            //if( null == _selectedWallType )
            //{
            //  message = string.Format(
            //    "Cannot find source wall type '{0}'"
            //    + " in source document '{1}'. ",
            //    _selectedWallTypeName, _source_project_path );

            //  return Result.Failed;
            //}



            // Create a new wall type in current document

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Transfer Wall Type");

                WallType newWallType = null;

                wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType)); // 2014

                foreach (WallType wt in wallTypes)
                {
                    if (wt.Kind == _selectedWallType.Kind)
                    {
                        newWallType = wt.Duplicate(_selectedWallTypeName) as WallType;

                        TaskDialog.Show("New wall type '{0}' created.", "Wall type " + _selectedWallTypeName + "created.");

                        break;
                    }
                }

                // Assign parameter values from source wall type:

#if COPY_INDIVIDUAL_PARAMETER_VALUE
                // Example: individually copy the "Function" parameter value:

                BuiltInParameter bip      = BuiltInParameter.FUNCTION_PARAM;
                string           function = wallType.get_Parameter(bip).AsString();
                Parameter        p        = newWallType.get_Parameter(bip);
                p.Set(function);
#endif // COPY_INDIVIDUAL_PARAMETER_VALUE

                Parameter p = null;

                foreach (Parameter p2 in newWallType.Parameters)
                {
                    Definition d = p2.Definition;

                    if (p2.IsReadOnly)
                    {
                        Debug.Print(string.Format(
                                        "Parameter '{0}' is read-only.", d.Name));
                    }
                    else
                    {
                        p = _selectedWallType.get_Parameter(d);

                        if (null == p)
                        {
                            Debug.Print(string.Format(
                                            "Parameter '{0}' not found on source wall type.",
                                            d.Name));
                        }
                        else
                        {
                            if (p.StorageType == StorageType.ElementId)
                            {
                                // Here you have to find the corresponding
                                // element in the target document.

                                Debug.Print(string.Format(
                                                "Parameter '{0}' is an element id.",
                                                d.Name));
                            }
                            else
                            {
                                if (p.StorageType == StorageType.Double)
                                {
                                    p2.Set(p.AsDouble());
                                }
                                else if (p.StorageType == StorageType.String)
                                {
                                    p2.Set(p.AsString());
                                }
                                else if (p.StorageType == StorageType.Integer)
                                {
                                    p2.Set(p.AsInteger());
                                }


                                Debug.Print(string.Format(
                                                "Parameter '{0}' copied.", d.Name));
                            }
                        }
                    }

                    // Note:
                    // If a shared parameter parameter is attached,
                    // you need to create the shared parameter first,
                    // then copy the parameter value.
                }

                // If the system family type has some other properties,
                // you need to copy them as well here. Reflection can
                // be used to determine the available properties.

                MemberInfo[] memberInfos = newWallType.GetType()
                                           .GetMembers(BindingFlags.GetProperty);

                foreach (MemberInfo m in memberInfos)
                {
                    // Copy the writable property values here.
                    // As there are no property writable for
                    // Walltype, I ignore this process here.
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 10
0
        //----------------------------------------------------------
        public string Duplicate_Type(UIApplication uiapp, Document doc)
        {
            string result = "F";

            try
            {
                type_data     item_type     = (type_data)type.SelectedItem;
                material_data item_material = (material_data)material.SelectedItem;

                CultureInfo culture   = CultureInfo.CreateSpecificCulture("eu-ES");
                string      specifier = "G";

                if (item_type.type.Category.Name == myAll_Data.list_category_draw[3])
                {
                    WallType          wall_Type             = item_type.type.Duplicate("STB " + b.Text + " " + item_material.single_value) as WallType;
                    CompoundStructure compound_new          = wall_Type.GetCompoundStructure();
                    IList <CompoundStructureLayer> cslayers = compound_new.GetLayers();

                    for (int i = 0; i < cslayers.Count; i++)
                    {
                        compound_new.SetLayerWidth(cslayers[i].LayerId, Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                        compound_new.SetMaterialId(cslayers[i].LayerId, item_material.material.Id);
                    }
                    wall_Type.SetCompoundStructure(compound_new);

                    my_type_data.Add(new type_data()
                    {
                        type         = wall_Type,
                        single_value = wall_Type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == wall_Type.Name);

                    double width = Math.Round(wall_Type.Width * myAll_Data.list_unit_value_data[6], 3);
                    wall_Type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("h = " + width.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[4])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value);
                    new_type.LookupParameter(myAll_Data.list_parameter_column[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.LookupParameter(myAll_Data.list_parameter_column[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    double width  = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value);
                    new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    double width  = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[1] || item_type.type.Category.Name == myAll_Data.list_category_draw[2])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text);
                    new_type.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    Update_UK_MA();
                }
                else
                {
                    ElementType new_type = item_type.type.Duplicate(item_type.type.Name + " " + b.Text);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    Update_UK_MA();
                }

                result = "S";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }