Results 1 to 2 of 2

Thread: Creating a list of element IDs and IFC GUIDs

  1. #1
    Join Date

    Default Creating a list of element IDs and IFC GUIDs

    So...I need a list of element IDs matched to their IFC GUIDs, but I'm not having much luck. I've tried piecing together a bit of what I know and what I've found, but I keep getting errors connected to the IDs : I can't get the element ID from an element, and I can't create the GUID to feed into an ifc converter. I imagine I'm making a total rookie mistake, as this is my first attempt to code in C#, but here you have it. The place I'm having problems is Suggestions?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Diagnostics;
    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;
    using Autodesk.Revit.DB.IFC.ExporterIFCUtils;
    public class copyEverything : IExternalCommand
        //Set the path for the new text file
        string myPath = @"c:\temp\MyTest.txt";
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
            //Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            var collector = new FilteredElementCollector(doc).WhereElementIsNotElementType()
            //Create a new text file and fill it with lines of elementIDs and IFC GUIDs, with a space in between
            using (StreamWriter myText = File.CreateText(myPath))
                foreach (Element x in collector)
    ///// ////////THIS IS WHERE I'M HAVING PROBLEMS///// ////////
                    var elemId = GetElementId(x);
                    var tempNum = CreateGUID(x);
    ///// ////////THIS IS WHERE I'M HAVING PROBLEMS///// ////////
                    //Convert the GUID to IFC format, and add a new line to the text file
                    var tempIfcId = IfcGuid.cv_to_64( tempNum );
                    myText.WriteLine(elemId + " " + tempIfcId);
            return Result.Succeeded;
        //Found function to convert GUID's into IFC's 64-bit scheme
        public static class IfcGuid
            private static readonly char[] base64Chars = new char[]
            { '0','1','2','3','4','5','6','7','8','9'
            , 'A','B','C','D','E','F','G','H','I','J'
            , 'K','L','M','N','O','P','Q','R','S','T'
            , 'U','V','W','X','Y','Z','a','b','c','d'
            , 'e','f','g','h','i','j','k','l','m','n'
            , 'o','p','q','r','s','t','u','v','w','x'
            , 'y','z','_','$' };
            public static void cv_to_64(uint number, ref char[] result, int start, int len)
                uint act;
                int iDigit, nDigits;
                Debug.Assert(len <= 4);
                act = number;
                nDigits = len;
                for (iDigit = 0; iDigit < nDigits; iDigit++)
                    result[start + len - iDigit - 1] = base64Chars[(int)(act % 64)];
                    act /= 64;
                Debug.Assert(act == 0, "Logic failed, act was not null: " + act.ToString());

  2. #2
    Join Date

    Default Re: Creating a list of element IDs and IFC GUIDs

    Is there any reason that you're not using the GUID that Revit assigns to every element?

    You can retrieve the GUID of any element by accessing the element.UniqueId property

    To retrieve the Element ID, you need to access the element.Id property. If you just want the numeric value of the ID, access the element.Id.IntegerValue property.

Similar Threads

  1. Replies: 0
    Last Post: 2012-02-24, 02:33 PM
  2. Element counting in a list
    By RabbitM in forum AutoLISP
    Replies: 11
    Last Post: 2010-11-01, 03:59 PM
  3. Replies: 1
    Last Post: 2010-07-15, 08:43 PM
  4. RAC 2009 - Creating cutting element for a sink
    By designviz in forum Revit Architecture - Families
    Replies: 10
    Last Post: 2009-10-12, 11:30 AM
  5. Creating new list from xdata
    By cadconcepts in forum AutoLISP
    Replies: 7
    Last Post: 2009-05-08, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts