Message 1 of 9

Not applicable
02-06-2013
08:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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. 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; [TransactionAttribute(TransactionMode.Manual)] [RegenerationAttribute(RegenerationOption.Manual)] 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); //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()); return; } } }
Solved! Go to Solution.