I noticed that the example given in the official page using ComponentFunctionInfo.Invoke()
but somehow I make it work with ComponentFunctionInfo.Evavluate()
. And the following code is the result I had. Works in my local machine.
private void RunScript(Brep BREP, ref object DS)
{
// AddMaterial component to create a material
var queryMaterials = Components.FindComponent("RhinoInside_QueryMaterials");
// and AddGeometryDirectShape to create a DirectShape element in Revit
var addGeomDirectshape = Components.FindComponent("RhinoInside_AddGeometryDirectShape");
if (queryMaterials == null || addGeomDirectshape == null) {
throw new Exception("One or more of the necessary components are not available as node-in-code");
}
if(BREP != null) {
string[] warns;
object[] newMaterials = queryMaterials.Evaluate(
new object[]{
"",
"Glass",
null},
false,
out warns);
string[] warnings;
object[] dsElements = addGeomDirectshape.Evaluate(
new object[]{
"Custom DS",
GetCategory("Walls"),
BREP,
newMaterials[0]
},
false,
out warnings
);
// assign the new DirectShape element to output
DS = dsElements[0];
}
}
// <Custom additional code>
public DB.Category GetCategory(string categoryName){
var doc = RIR.Revit.ActiveDBDocument;
foreach(DB.Category cat in doc.Settings.Categories) {
if (cat.Name == categoryName)
return cat;
}
return null;
}