See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: How to Retrieve and Set Parameter Values of a FamilyInstance?

  1. #1
    Member
    Join Date
    2012-02
    Posts
    27
    Login to Give a bone
    0

    Default How to Retrieve and Set Parameter Values of a FamilyInstance?

    Hello All,
    I have been trying to figure out how to set and retrieve parameter values of elements. For testing I built a macro that creates a diffuser, and as a test I would like to display the Mark, and set the Offset to 10 ft. From the help file I would have thought that the code to retrieve the Mark would be:
    Code:
    Parameter param = fi.Parameter("Mark");
    And, I would have thought that the code to set the Offset to 10 would be
    Code:
    Parameter param = fi.Parameter("Offset");
    param.Set(10);
    I have looked through the Developers Guide and some sample macros from the SDK, but still haven't been able to figure it out. If someone would point out where I'm going wrong, it would be greatly appreciated. The full code for my example macro is below.

    Code:
            public void AddDiffuser()
            {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document doc = this.ActiveUIDocument.Document;
            
            //Get the level of the active view
            Level l = doc.ActiveView.GenLevel;
            
            //Get the family of the diffuser (family name)
            Family f = new FilteredElementCollector(doc)
            .OfClass(typeof(Family))
            .FirstOrDefault(q => q.Name == "Supply Diffuser") as Family;
            
            //Get the Type
            FamilySymbol fs = f.Symbols.Cast<FamilySymbol>()
            .First(q => q.Name == "24 x 24 Face 12 x 12 Connection");
            
            using (Transaction t = new Transaction(doc,"Create Diffusers"))
            {
            t.Start();
    
    
    
    
            XYZ diffuserPnt = new XYZ(-65,55,99);
            
            //Create new diffuser
            FamilyInstance fi = doc.Create
            .NewFamilyInstance(diffuserPnt, fs, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
    
    
            //How to a retrieve a parameter value from a family instance that was just created?????
            Parameter param = fi.Parameter("Mark");
            TaskDialog.Show("The Name of the Element", param.ToString());
    
    
            //How to a set a parameter value from a family instance that was just created?????
            Parameter param = fi.Parameter("Offset");
            param.Set(10);
            TaskDialog.Show("The Name of the Element", param.ToString());
            
            t.Commit();
            }
            }

  2. #2
    Member
    Join Date
    2012-09
    Posts
    34
    Login to Give a bone
    1

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    Try switching fi.Parameter("Offset") to fi.get_Parameter("Offset")

    If that doesn't work, then post some more details on the error messages that you're currently receiving.

  3. #3
    100 Club
    Join Date
    2004-09
    Posts
    104
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    I would suggest using the Built-in parameters:

    BuiltInParameter BIPmark = BuiltInParameter.ALL_MODEL_MARK;
    Parameter mark = fi.get_Parameter(BIPmark);
    mark.Set("Whatever...");

    and

    BuiltInParameter BIPoffset = BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM;
    Parameter offset = fi.get_Parameter(BIPoffset);
    offset.Set(10);

    I'm pretty sure about ALL_MODEL_MARK, but I'm not sure about INSTANCE_FREE_HOST_OFFSET_PARAM. Another possibility is INSTANCE_ELEVATION_PARAM. You can use Revit Lookup to help you find the right parameter.

  4. #4
    Member
    Join Date
    2012-02
    Posts
    27
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    Thank you. Both of these methods worked to get and set the parameter. However, when the task dialog displays
    Code:
    diffName = mark.AsValueString();
    , (I created a string named diffName)the window shows a blank. If I use
    Code:
    diffName = mark.ToString();
    , the window displays Autodesk.Revit.DB.Parameter. How can I get and display the value of the Mark?
    Thanks

  5. #5
    100 Club
    Join Date
    2004-09
    Posts
    104
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    Try
    diffName = mark.AsString();

    AsValueString() is for converting a number to a string with units, and should be the right one for offset.

  6. #6
    Member
    Join Date
    2012-02
    Posts
    27
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    That worked. Thanks!

  7. #7
    Member
    Join Date
    2012-09
    Posts
    34
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    Peter is 100% correct about using Built In Parameters wherever possible.

    If you aren't already using it, you should install RevitLookup. It's an addin that is part of the Revit SDK that allows you to explore all of the parameters of elements in the model.

    Using the "Built-in Enums Map" that's accessible through the "Parameters" section of an element, you can see which built in parameters are used for the element that you're inspecting.

  8. #8
    Member
    Join Date
    2012-02
    Posts
    27
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    Thank you. When I use Revit Lookup to get the builtin parameter for Mark, it tells me the Built in param is DOOR_NUMBER. Any ideas why it would be telling me that?

  9. #9
    Active Member
    Join Date
    2011-11
    Location
    Saint-Omer, Pas-de-Calais, France
    Posts
    58
    Login to Give a bone
    0

    Default Re: How to Retrieve and Set Parameter Values of a FamilyInstance?

    It is because there is several built in params which share the same value. DOOR_NUMBER is equal to -1001203 like ALL_MODEL_MARK. Revit Lookup does a reverse lookup of the Enum by value and DOOR_NUMBER is the identifier returned.

Similar Threads

  1. 2016: How to retrieve Parameter Value of a Family Element ?
    By huiput2006707889 in forum Revit - API
    Replies: 2
    Last Post: 2015-09-04, 03:20 AM
  2. 2015: Parameter values resetting
    By BenSammis in forum Revit MEP - General
    Replies: 5
    Last Post: 2015-03-05, 04:04 PM
  3. Strange parameter values !!!
    By some buddy in forum Revit - API
    Replies: 5
    Last Post: 2009-12-15, 11:07 PM
  4. Replies: 3
    Last Post: 2006-11-08, 08:07 PM
  5. 'Up' key to retrieve previous numerical values
    By Neda Anser in forum AutoCAD General
    Replies: 3
    Last Post: 2006-10-26, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •