Hi! Can anyone give a piece of advice on creating a plugin that'd take several parameter values and combine them into one parameter? Any resource on it or something similar to it would help greatly!
PS: I'm pretty new to C# and programming. A user will need to find the necessary categories and then specify parameters along with the "resulting" parameter containing every value (string).
Basically, anology of this Dynamo script is needed (picture's attached).
Solved! Go to Solution.
Solved by franciscopossetto. Go to Solution.
Hey,
First of all, I would recommend you do this tutorial, to understand how Revit addíns are structured.
With regards to the logic, this schema should work in most cases:
Document doc = commandData.Application.ActiveUIDocument.Document;
//Get all elements of the Category Walls
IEnumerable<Element> collector = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.ToElements();
foreach(Element e in collector)
{
//Get Parameter values
string parameterValue1 = e.LookupParameter("Base Constraint").AsValueString();
string parameterValue2 = e.LookupParameter("Top Constraint").AsValueString();
string parameterValue3 = e.LookupParameter("Top Offset").AsValueString();
string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;
using (Transaction t = new Transaction(doc, "Set Parameter name"))
{
t.Start();
e.LookupParameter("Comments").Set(newValue);
t.Commit();
}
}
Some comments :
- Collectors can be created to get elements of certain classes, categories, etc.
- To read the value of a parameter, in addition to the method LookupParameter you can use the method get_Parameter or get values from the Properties related with the element. (Syntax: object.Property)
-The method Set is used to set a value. A value can also be set on a property (Syntax: object.Property = value)
-Any change to a document requires a transaction.
-To know more about Elements or methods you can use, I would recommend you install RevitLookup and see the Revit API online documentation: https://www.revitapidocs.com/
I hope it helps,
Good luck!
Hello! The code works but partially. For some reason something is missing. It sets only the dashes. Is there anything we can change to get the right output?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace CombineParameters
{
[Transaction(TransactionMode.Manual)]
public class Class : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
//Application app = uiapp.Application;
Document doc = uidoc.Document;
//Create Filtered Element Collector and Filter
FilteredElementCollector collector = new FilteredElementCollector(doc);
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_DuctFitting);
//Applying Filter
IList <Element> ducts = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
foreach (Element e in ducts)
{
//Get Parameter values
string parameterValue1 = e.LookupParameter("AA").AsValueString();
string parameterValue2 = e.LookupParameter("BB").AsValueString();
string parameterValue3 = e.LookupParameter("CC").AsValueString();
string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;
using (Transaction t = new Transaction(doc, "Set Parameter name"))
{
t.Start();
e.LookupParameter("DD").Set(newValue);
t.Commit();
}
}
return Result.Succeeded;
}
}
}
Hey,
Change the method AsValueString to the method AsString, inside your foreach.
string parameterValue1 = e.LookupParameter("AA").AsString();
string parameterValue2 = e.LookupParameter("BB").AsString();
string parameterValue3 = e.LookupParameter("CC").AsString();
It should work.
Can't find what you're looking for? Ask the community or share your knowledge.