Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Migration Binding Update

0 REPLIES 0
Reply
Message 1 of 1
stephen_harrison
86 Views, 0 Replies

Migration Binding Update

I would be great full for some assistance as I am trying to update some apps to deal with soon to be deprecated items. The app is for Binding Shared Parameters.

I currently create a tree that represent the Instance and Type BuiltInCategory an example as below

 

 

 

TreeNode FlexDucts = new TreeNode(nodeName = treeViewName(doc, -2008020));

FlexDucts.Tag = -2008020;

 

 

I then utilised the code below to create the different Bindings

 

private void BindParam(UIApplication uiApp, DefinitionFile parafile)
{
    ResourceManager LocRM = new ResourceManager("BindSharedParam.Properties.Resources", typeof(BindParamForm).Assembly);
    try
    {
        BuiltInParameterGroup bIPG = (BuiltInParameterGroup)ReturnParamGroup();
        // create a category set and insert category of wall to it
        CategorySet myCategories = uiApp.Application.Create.NewCategorySet();
        TreeNodeCollection nodes = categoryTv.Nodes;
        using (Transaction t = new Transaction(doc, LocRM.GetString("Transaction").TrimEnd('\r', '\n')))
        {
            foreach (TreeNode n in nodes)
            {
                if (n.Checked == true)
                {
                    BuiltInCategory enumCategory = (BuiltInCategory)n.Tag;
                    Category myCategorie = uiApp.ActiveUIDocument.Document.Settings.Categories.get_Item(enumCategory);
                    myCategories.Insert(myCategorie);
                    foreach (TreeNode child in n.Nodes)
                    {
                        if (child.Checked == true)
                        {
                            BuiltInCategory enumCategoryChild = (BuiltInCategory)child.Tag;
                            myCategorie = uiApp.ActiveUIDocument.Document.Settings.Categories.get_Item(enumCategoryChild);
                            myCategories.Insert(myCategorie);
                        }
                    }
                }
                else if (n.Parent == null)
                {
                    foreach (TreeNode nChild in n.Nodes)
                    {
                        if (nChild.Checked == true)
                        {
                            BuiltInCategory enumCategoryChild = (BuiltInCategory)nChild.Tag;
                            Category myCategorie = uiApp.ActiveUIDocument.Document.Settings.Categories.get_Item(enumCategoryChild);
                            myCategories.Insert(myCategorie);
                        }
                    }
                }
            }
            t.Start();
            {
		   // loop through DataGrid Values for Shared Parameters to be Bound
                foreach (DataGridViewRow row in sharedParamDGV.Rows)
                {
                    if (row.Cells[0].Value != null)
                    {
                        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells[0];
                        if ((Convert.ToBoolean(chk.Value) == true))
                        {
                            numberSelected++;
                            string paramName = "";
                            string pGroup = "";
                            string paramGUID = "";
			         // Read Checked DataGrid Values for Parameter to be Bound
                            paramName = row.Cells[1].Value.ToString();
                            paramGUID = row.Cells[3].Value.ToString();
                            pGroup = row.Cells[4].Value.ToString();
                            // create a new group in the shared parameters file
                            DefinitionGroups myGroups = parafile.Groups;
                            DefinitionGroup myGroup = null;
                            myGroup = myGroups.get_Item(pGroup);
                            Definition myDefinition = myGroup.Definitions.get_Item(paramName);
                            if (instanceRdo.Checked)
                            {
                                //Create an instance of InstanceBinding
                                InstanceBinding instanceBinding = uiApp.Application.Create.NewInstanceBinding(myCategories);
                                // Bind the definitions to the document
                                bool instanceBindOK = uiApp.ActiveUIDocument.Document.ParameterBindings.Insert(myDefinition, instanceBinding, bIPG);
                            }
                            else
                            {
                                //Create an object of TypeBinding according to the Categories
                                TypeBinding typeBinding = uiApp.Application.Create.NewTypeBinding(myCategories);
                                // Bind the definitions to the document
                                bool typeBindOK = uiApp.ActiveUIDocument.Document.ParameterBindings.Insert(myDefinition, typeBinding, bIPG);
                                if (GroupInstanceRdo.Checked == true)
                                {
                                    try
                                    {
                                        Guid spGUID = new Guid(row.Cells[3].Value.ToString());
                                        SharedParameterElement spE = SharedParameterElement.Lookup(doc, spGUID);
                                        InternalDefinition intdef = spE.GetDefinition();
                                        intdef.SetAllowVaryBetweenGroups(doc, true);
                                    }
                                    catch
                                    {

                                    }
                                }
                            }
                            numberParamsBound++;
                            ProgressBarChange();
                        }
                    }
                }
            }
            t.Commit();
            TaskDialog tD = new TaskDialog(LocRM.GetString("AddSharedParam").TrimEnd('\r', '\n'));
            tD.TitleAutoPrefix = false;
            tD.MainInstruction = (string.Format(LocRM.GetString("TransactionSuccessfull"), numberParamsBound, numberSelected)).TrimEnd('\r', '\n');
            tD.CommonButtons = TaskDialogCommonButtons.Ok;
            TaskDialogResult result = tD.Show();
            progressBar1.Value = 0;
            selectAllCatRdo.Checked = false;
            closeBt.Enabled = true;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
        //if tree view selected before a parameter this shows.
        TaskDialog tD = new TaskDialog(LocRM.GetString("AddSharedParam").TrimEnd('\r', '\n'));
        tD.TitleAutoPrefix = false;
        tD.MainInstruction = LocRM.GetString("TransactionError").TrimEnd('\r', '\n');
        tD.CommonButtons = TaskDialogCommonButtons.Ok;
        TaskDialogResult result = tD.Show();
        progressBar1.Value = 0;
        closeBt.Enabled = true;
    }
}

 

 

Regrettably I am having difficulties updating it.

Thankyou in advance for your assistance.

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community