Zero Touch - How to return list of elements

I’m new to Zero Touch. I think the solution is easy for one with a little more experience than I have
How can I return a formatted list showing elements in the same way as standard Revit nodes?

My code looks something like this:

List types = new List(); List istances = new List();
        ElementId id = new ElementId(766598);
        types.Add(doc.GetElement(id));
        types.Add(doc.GetElement(id));
        types.Add(doc.GetElement(id));
        types.Add(doc.GetElement(id));
        types.Add(doc.GetElement(id));

        return new Dictionary<string, List<Element>>()
        {
        { "Types", new List<Element>(types) },
        { "Istances", new List<Element>(istances) }
        };

That return statement looks good and it seems to be doing what it’s supposed to inside Dynamo. Tho I’m not sure why you’re generating new lists instead of using the existing lists?

I guess your question is how to return a Dynamo element instead? You’ll need to wrap the Revit element like so:

types.Add(doc.GetElement(id).ToDSType(true) )

You could also give the new C# interpreter a try. It’s up on the package manager:

4 Likes

@Dimitar_Venkov
Thank you. It worked perfectly.
Do you know why many of my nodes fails the first I thicker on the run button?
If I remove one of the wires and reconnect it again and hit run the node works fine.

    [CanUpdatePeriodically(true)]
    [IsVisibleInDynamoLibrary(true)]
    [MultiReturn(new[] { "worked", "failed" })]
    public static Dictionary<string, List<string>> IFCExport(
        string[] folder,
        string[] name,
        //int[] viewid,
        List<Revit.Elements.Element> view,
        string[] familymappingfile,
        string[] version,
        bool[] wallandcolumnsplitting,
        //bool[] exportinternalrevitpropertysets,
        //bool[] exportbasequantities,
        //bool[] exportifccommonpropertysets,
        bool[] exportuserdefinedpsets,
        string[] exportuserdefinedpsetsfilename
        //bool[] includesiteelevation,
        //bool[] storeifcguid
        )
    {
        //DocumentManager.Instance.CurrentUIDocument.Application.ActiveUIDocument.Document.Application.ExportIFCCategoryTable;
        //http://help.autodesk.com/view/RVT/2017/ENU/?guid=GUID-E029E3AD-1639-4446-A935-C9796BC34C95
        Document doc = DocumentManager.Instance.CurrentDBDocument;
        UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
        Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
        UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

        List<string> exports = new List<string>();
        List<string> worked = new List<string>();
        List<string> failed = new List<string>();
        exports.Clear();
        worked.Clear();
        failed.Clear();


        //for (int i = 0; i < viewid.Length; i++)
        for (int i = 0; i < view.Count; i++)
        {
            IFCExportOptions options = new IFCExportOptions();
            if (string.IsNullOrEmpty(version[i].ToString()) == false)
            {
                if (version.ToString() == "IFC2x2")
                {
                    options.FileVersion = IFCVersion.IFC2x2;
                }
                if (version.ToString() == "IFC2x3")
                {
                    options.FileVersion = IFCVersion.IFC2x3;
                }
                if (version.ToString() == "IFC2x3CV2")
                {
                    options.FileVersion = IFCVersion.IFC2x3CV2;
                }
                if (version.ToString() == "IFC4")
                {
                    options.FileVersion = IFCVersion.IFC4;
                }
                if (version.ToString() == "IFCBCA")
                {
                    options.FileVersion = IFCVersion.IFCBCA;
                }
                if (version.ToString() == "IFCCOBIE")
                {
                    options.FileVersion = IFCVersion.IFCCOBIE;
                }
                if (version.ToString() == "Default")
                {
                    options.FileVersion = IFCVersion.Default;
                }
                else
                {
                    options.FileVersion = IFCVersion.Default;
                }
            }

            if (string.IsNullOrEmpty(wallandcolumnsplitting[i].ToString()) == false)
            {
                options.WallAndColumnSplitting = wallandcolumnsplitting[i];
            }

            //if (string.IsNullOrEmpty(exportbasequantities[i].ToString()) == false)
            //{
            //    options.ExportBaseQuantities = exportbasequantities[i];
            //}

            //if (string.IsNullOrEmpty(viewid[i].ToString()) == false)
            if (view.Count > 0)
            {
                ElementId id = new ElementId(view[i].Id);
                options.FilterViewId = id;
            }

            //if (string.IsNullOrEmpty(familymappingfile[i].ToString()) == false)
            //{
            //    if (familymappingfile.ToString().Length >= 1)
            //    {
            //if (familymappingfile.ToString().StartsWith("exportlayers"))
            //{
            if (File.Exists(familymappingfile[i].ToString()) == true)
            {
                options.FamilyMappingFile = familymappingfile[i].ToString();
            }

            //}
            //else
            //{
            //    failed.Add("FamilyMappingFile Must Start With \"exportlayers\"");
            //}
            //    }
            //    else
            //    {

            //    }
            //}

            string exportfolder = "";
            if (string.IsNullOrEmpty(folder[i].ToString()) == false)
            {
                exportfolder = folder[i].ToString();
            }

            string exportname = "";
            if (string.IsNullOrEmpty(name[i].ToString()) == false)
            {
                exportname = name[i].ToString();
            }

            //options.AddOption("SpaceBoundaries ", "0");
            //options.AddOption("ActivePhaseId ", "");//ElementId.InvalidElementId

            //options.AddOption("VisibleElementsOfCurrentView ", "false");
            //options.AddOption("Use2DRoomBoundaryForVolume ", "false");
            //options.AddOption("UseFamilyAndTypeNameForReference ", "false");
            //options.AddOption("ExportInternalRevitPropertySets ", exportinternalrevitpropertysets.ToString());
            //options.AddOption("ExportIFCCommonPropertySets", exportifccommonpropertysets.ToString());
            //options.AddOption("Export2DElements", "false");
            //options.AddOption("ExportPartsAsBuildingElements", "false");
            //options.AddOption("ExportBoundingBox", "false");
            //options.AddOption("ExportSolidModelRep", "false");
            //options.AddOption("ExportSchedulesAsPsets", "false");
            options.AddOption("ExportUserDefinedPsets", exportuserdefinedpsets[i].ToString());
            if (File.Exists(exportuserdefinedpsetsfilename[i].ToString()) == true)
            {
                options.AddOption("ExportUserDefinedPsetsFileName", exportuserdefinedpsetsfilename[i].ToString());
            }
            //options.AddOption("ExportLinkedFiles", "false");
            //options.AddOption("IncludeSiteElevation", includesiteelevation[i].ToString());
            //options.AddOption("UseActiveViewGeometry", "false");
            //options.AddOption("ExportSpecificSchedules", "false");
            //options.AddOption("TessellationLevelOfDetail", "0.5");
            //options.AddOption("StoreIFCGUID", storeifcguid[i].ToString());
            //options.AddOption("ExportRoomsInView", "false");


            foreach (Revit.Elements.Element e in view)
            {
                exports.Add(exportfolder + "\\" + exportname + ".ifc");
            }

            using (Transaction t = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document))
            {
                t.Start("BIMShark IFC-export");
                try
                {
                    DocumentManager.Instance.CurrentUIDocument.Application.ActiveUIDocument.Document.Export(exportfolder, exportname, options);
                }
                catch (Exception e)
                {
                    failed.Add("Export failed " + e.Message);
                }
                t.Commit();
            }
        }

        //Check that file was created
        bool exists = false;
        string file = "";
        foreach (string item in exports)
        {
            file = item;
            exists = File.Exists(item);
            if (exists == true)
            {
                worked.Add(item);
            }
            if (exists == false)
            {
                failed.Add(item);
            }
        }
        return new Dictionary<string, List<string>>()
        {
            { "worked", worked },
            { "failed", failed }
        };
    }

my problem seems to be related to this thread ReRun the definition without changing parameters

Removed the transaction and now it works perfectly.

Nicklas,
to you previous work on IFC Exporter- failing options.AddOption
it is possible that the solution for IFC exporter to get in the extra functionality is this:
options.AddOption("ExportInternalRevitPropertySets ",“true”)
or
options.AddOption("ExportInternalRevitPropertySets ",“false”)
I added it to your script and found it working ( added Revitproperty sets, and they did appear)
so…
that is the “patch”

options.AddOption("SpaceBoundaries ", “0”);
options.AddOption("VisibleElementsOfCurrentView ", “false”);
options.AddOption("Use2DRoomBoundaryForVolume ", “false”);
options.AddOption("UseFamilyAndTypeNameForReference ", “false”);
options.AddOption("ExportInternalRevitPropertySets ",“true”);
options.AddOption(“ExportIFCCommonPropertySets”,“true”);
options.AddOption(“Export2DElements”, “false”);
options.AddOption(“ExportPartsAsBuildingElements”, “false”);
options.AddOption(“ExportBoundingBox”, “false”);
options.AddOption(“ExportSolidModelRep”, “false”);
options.AddOption(“ExportSchedulesAsPsets”, “false”);
options.AddOption(“ExportLinkedFiles”, “false”);
options.AddOption(“IncludeSiteElevation”,“true”);
options.AddOption(“UseActiveViewGeometry”, “false”);
options.AddOption(“ExportSpecificSchedules”, “false”);
options.AddOption(“TessellationLevelOfDetail”, “0.5”);
options.AddOption(“StoreIFCGUID”, “true”);
options.AddOption(“ExportRoomsInView”, “false”);
options.AddOption(“ExportLinkedFiles”, “false”);
options.AddOption(“IncludeSiteElevation”, “false”);
options.AddOption(“UseActiveViewGeometry”, “false”);
options.AddOption(“ExportSpecificSchedules”, “false”);
options.AddOption(“TessellationLevelOfDetail”, “0.5”);
options.AddOption(“StoreIFCGUID”, “false”);
options.AddOption(“ExportRoomsInView”, “false”);

please, advise if this might be a solution for the extra IFC functionality

yes it seems to be a good solution. Thank you.