Plugin to Python Code

Hi Devs,

Can this code for a plugin be converted to something useful in Dynamo, like nodes, a python script or ???
It’s a code to be able to modify Omniclass parameters.

Thanks,

I hope I inserted the code right with the “Preformated Text” button.

[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
    public Result Execute(ExternalCommandData extCmdData, ref string msg, ElementSet elmtSet)
    {
        UIApplication uiapp = extCmdData.Application;
        UIDocument uiDoc = uiapp.ActiveUIDocument;
        Application app = uiapp.Application;
        Document doc = uiDoc.Document;

        Family fam;

        try
        {
            Reference refsel = uiDoc.Selection.PickObject(ObjectType.Element, "selection élément");
            Element elmnt = doc.GetElement(refsel.ElementId);
            FamilyInstance fyInst = elmnt as FamilyInstance;
            fam = fyInst.Symbol.Family;
            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("Mise à jour Paramètre OmniClass");
                Parameter para = fam.get_Parameter(BuiltInParameter.OMNICLASS_CODE);
                para.Set("23.70.50.21.24.14");//valeur exemple
                trans.Commit();
            }           
        }
        catch (Exception e)
        {
            msg = e.Message;
            return Result.Failed;
        }
        return Result.Succeeded;
    }
}

This is just changing a parameter value - you can do that with OOTB nodes. No need for coding.

1 Like

@Andreas_Dieckmann I haven’t found a way, and so far everything points toward this parameter being a non read/write parameter. Nobody was able to provide a solution to the Omniclass parameter in my previous post. If there’s a way, I’m all ears.

Dynamo lacks a node for c# codes. It would be great if such functionality get implemented in future release.
Python has the ability to work with Revit API.

@Jonathan_Roy - There are a lot of examples out there that show how to set a builtin parameter’s value via Python, e.g. Element.SetWorkset or FamilyInstance.SetLevel nodes in pkg Clockwork

Maybe you can try @Dimitar_Venkov s C# interpreter: (found in the package manager). I just slightly edited the code to include some references and swapped to Dynamos document manager.

//Add references
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using RevitServices.Persistence;
using RevitServices.Transactions;

UIDocument uiDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
Document doc = DocumentManager.Instance.CurrentDBDocument;
string OUT;
Family fam;

try
{
	Reference refsel = uiDoc.Selection.PickObject(ObjectType.Element, "selection élément");
	Element elmnt = doc.GetElement(refsel.ElementId);
	FamilyInstance fyInst = elmnt as FamilyInstance;
	fam = fyInst.Symbol.Family;
	using (Transaction trans = new Transaction(doc))
	{
		trans.Start("Mise à jour Paramètre OmniClass");
		Parameter para = fam.get_Parameter(BuiltInParameter.OMNICLASS_CODE);
		para.Set("23.70.50.21.24.14");//valeur exemple
		trans.Commit();
	OUT = "succses!";
	}           
}
catch (Exception e)
{
	OUT = e.Message;
}
1 Like

@Andreas_Dieckmann, Now that I know what they are called “Builtin parameters” it will help further my research. I am totally clueless with regards to Python and C# and have been asking lots of questions to help me keep pushing forward, so thank you all for your precious time!

Thanks for another clue @Einar_Raknes Einar, I’ll look on the forum for other users who have used this node to help me figure out how to plug in the other in/out ports and use it.