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!
Solved! Go to Solution.
Solved by MarryTookMyCoffe. Go to Solution.
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.
MarryTookMyCoffee,
Thank you, that was it. I didn't realize that the FamilyManager had the Set/SetFormula methods for this purpose.
Thank you again.
Glad I could help
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:
Thank you
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.