Adding a parameter through code

Adding a parameter through code

Anonymous
Not applicable
481 Views
1 Reply
Message 1 of 2

Adding a parameter through code

Anonymous
Not applicable

I have this code

 

        public void CreateParameter(ExternalCommandData commandData) {
        UIApplication uiapp = commandData.Application;
        UIDocument uidoc = uiapp.ActiveUIDocument;
        Document doc = uidoc.Document;
        FamilyManager fam = doc.FamilyManager;
        var param = fam.AddParameter("Size", BuiltInParameterGroup.PG_STRUCTURAL, ParameterType.Length, true);
        fam.Set(param, 0.2);
        }

Although I can't seen to run it in the Macro Manager --> http://i.imgur.com/1iaApXy.png

 

I've also tried running it as an Add-Ins External Tools and this message pops up --> http://i.imgur.com/ZIKpC8i.png

 

I'm new to Revit API so I'm not sure what I need to do to fix this. Any help would be great.

0 Likes
Accepted solutions (1)
482 Views
1 Reply
Reply (1)
Message 2 of 2

keith_white
Autodesk
Autodesk
Accepted solution

You need to separate the parameter creation and the parameter value update into two transactions.

 

First create the parameter in a transaction and commit it.

var param = fam.AddParameter("Size", BuiltInParameterGroup.PG_STRUCTURAL, ParameterType.Length, true);

 

Then update the parameter in a transaction and commit it.

fam.Set(param, 0.2);

 

 



Keith White

Principal Solution Architect, Autodesk Consulting
0 Likes