Beispiel #1
0
        //Method deletes parameters
        public void RemoveSharedParameterBinding(Application app, string name, ParameterType type)
        {
            BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();

            Definition def = null;

            while (it.MoveNext())
            {
                if (it.Key != null && it.Key.Name == name && type == it.Key.ParameterType)
                {
                    def = it.Key;
                    break;
                }
            }

            if (def == null)
            {
                sbFeedback.Append("Parameter " + name + " does not exist.\n");
            }
            else
            {
                map.Remove(def);
                if (map.Contains(def))
                {
                    sbFeedback.Append("Failed to delete parameter " + name + " for some reason.\n");
                }
                else
                {
                    sbFeedback.Append("Parameter " + name + " deleted.\n");
                }
            }
        }
Beispiel #2
0
        //----------------------------------------------------------
        public string Them_Hoac_Xoa_Parameter_Trong_Project(UIApplication uiapp, Document doc)
        {
            string result = "F";

            try
            {
                Transaction transaction = new Transaction(doc);
                transaction.Start("Parameters");
                var enums      = Enum.GetValues(typeof(BuiltInCategory));
                var enums1     = Enum.GetValues(typeof(BuiltInParameterGroup));
                var categories = doc.Settings.Categories;
                foreach (data_group_share_parameter item in my_group_share_parameter)
                {
                    DefinitionFile parafile = uiapp.Application.OpenSharedParameterFile();
                    if (parafile != null)
                    {
                        DefinitionGroup myGroup = parafile.Groups.get_Item(item.ten_group_parameter);

                        foreach (data_item_share_parameter subitem in item.Children)
                        {
                            if (subitem.exist_parameter == true)
                            {
                                //BuiltInParameterGroup builtInParameterGroup = BuiltInParameterGroup.PG_TEXT;
                                //foreach (BuiltInParameterGroup builtIn in enums1)
                                //{
                                //    if (builtIn.ToString().Split('_')[0] == subitem.ten_parameter && builtIn != BuiltInParameterGroup.INVALID) builtInParameterGroup = builtIn;
                                //}

                                Definition  myDefinition_ProductDate = myGroup.Definitions.get_Item(subitem.ten_parameter);
                                CategorySet myCategories             = uiapp.Application.Create.NewCategorySet();
                                foreach (BuiltInCategory buildCategory in enums)
                                {
                                    try
                                    {
                                        Category cate = categories.get_Item(buildCategory);
                                        if (cate.AllowsBoundParameters == true && cate.CategoryType.ToString() == "Model")
                                        {
                                            myCategories.Insert(cate);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }

                                try
                                {
                                    BindingMap bindingMap = doc.ParameterBindings;
                                    if (subitem.ten_parameter != "Chiều dày hoàn thiện")
                                    {
                                        InstanceBinding instanceBinding = uiapp.Application.Create.NewInstanceBinding(myCategories);
                                        bindingMap.Insert(myDefinition_ProductDate, instanceBinding);
                                    }
                                    else
                                    {
                                        TypeBinding instanceBinding = uiapp.Application.Create.NewTypeBinding(myCategories);
                                        bindingMap.Insert(myDefinition_ProductDate, instanceBinding);
                                    }
                                    if (my_data_parameter_current.Any(x => x.ten_parameter == subitem.ten_parameter) == false)
                                    {
                                        my_data_parameter_current.Add(new data_parameter()
                                        {
                                            ten_parameter = subitem.ten_parameter
                                        });
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                            else
                            {
                                try
                                {
                                    Definition myDefinition_ProductDate = myGroup.Definitions.get_Item(subitem.ten_parameter);
                                    BindingMap bindingMap = doc.ParameterBindings;
                                    bindingMap.Remove(myDefinition_ProductDate);
                                    data_parameter item_remove = my_data_parameter_current.First(x => x.ten_parameter == subitem.ten_parameter);
                                    if (item_remove != null)
                                    {
                                        my_data_parameter_current.Remove(item_remove);
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                            try
                            {
                                if (my_data_parameter_current.Any(x => x.ten_parameter == subitem.ten_parameter) == false)
                                {
                                    my_data_parameter_need.First(x => x.ten_parameter == subitem.ten_parameter).color = Source.color_error;
                                }
                                else
                                {
                                    my_data_parameter_need.First(x => x.ten_parameter == subitem.ten_parameter).color = Source.color;
                                }
                                thong_tin_parameter.Items.Refresh();
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Not found share parameter file!!!", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                result = "S";
                transaction.Commit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }