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: 

Setting FamilyParameter via API

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mhillis
3056 Views, 5 Replies

Setting FamilyParameter via API

Hello all,

 

I've been trying to figure out how I can set the value of a FamilyParameter with the API.  Here's the deal.

 

I have an add-in that's taking a family and adding some family parameters to it, like so

 

FamilyParameter widthParam = 
famDoc.FamilyManager.AddParameter("Width",
BuiltInParameterGroup.PG_GENERAL,
ParameterType.HVACDuctSize, true);

 

Going this route, I can't figure out a way to set a value for this parameter. I've read-up this post by Jeremy - http://thebuildingcoder.typepad.com/blog/2009/11/family-parameter-value.html

 

However, that just covers reading the value, I was hoping I could reverse engineer it and figure out how to set the value, but no avail.

 

Any ideas anyone?

 

Thanks!

5 REPLIES 5
Message 2 of 6
MarryTookMyCoffe
in reply to: mhillis

ok, I can see why this can be confusing for you. It was for me on start to. You do all things on FamilyParameter with document.FamilyManager. I put some exemple code:

 

FamilyParameter familyParameter = document.FamilyManager.AddParameter("Radius", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, false);

document.Regenerate();
document.FamilyManager.Set( familyParameter, diameterList[i]);
document.FamilyManager.SetFormula( familyParameter, "Height * 2");

sometimes there will be problem with adding FamilyParameter to dimension try use document.Regenerate()

ps. text before 2014 are in most case not useful, they change a lot from that time.

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Tags (1)
Message 3 of 6
mhillis
in reply to: MarryTookMyCoffe

MarryTookMyCoffee,

 

Thank you, that was it.  I didn't realize that the FamilyManager had the Set/SetFormula methods for this purpose.

 

Thank you again. 

Message 4 of 6
MarryTookMyCoffe
in reply to: mhillis

Glad I could help

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Message 5 of 6

Hi: I'm trying this, but it doesn't works:

using System;
using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class EditarFamiliav2 : IExternalCommand
{
  public Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements)
  {
	
    //Get application and document objects
    UIApplication uiApp = commandData.Application;    
    Document doc = uiApp.ActiveUIDocument.Document;


    Transaction trans = new Transaction(doc);
    trans.Start("Lab");
    
    FamilyParameter familyParameter = doc.FamilyManager.AddParameter("Radius", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, false);
    ElementId elemId = familyParameter.Id;
doc.Regenerate();
doc.FamilyManager.Set( familyParameter, elemId);
doc.FamilyManager.SetFormula( familyParameter, "Height * 2");
    trans.Commit();
    trans.Dispose();
    return Result.Succeeded;
  }
}

I changed the line 

document.FamilyManager.Set( familyParameter, diameterList[i]);

 for avoiding a compilation error (I don't know what "diameterList[i]" is)

 

Here's a screenshot of the error:

errorfamily.jpg

 

Thank you

Message 6 of 6
mhillis
in reply to: leandrocaplan

leandrocaplan,

 

There are two things to address.  First, you mention that you don't know what 'diameterList[i]' is. You should, it is a value that you define in your own code.

 

Second, the error message you're getting indicates that the Revit Add-in simply failed to execute correctly, typically because of an exception that happened somewhere in your code.  You'll need to debug your add-in using a debugger (like Visual Studio) and then see the exception happen in real time by setting your debugger to break execution when an exception happens.  From there, you should have a much better understanding of what is failing. 

 

 

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community