Add custom data fields to .MAJ export from Revit

Add custom data fields to .MAJ export from Revit

mmckeonXZRL9
Contributor Contributor
83 Views
0 Replies
Message 1 of 1

Add custom data fields to .MAJ export from Revit

mmckeonXZRL9
Contributor
Contributor

Hi there,

 

I am trying to work out how I can add the typeID and InstanceID for each Revit element when exporting to .MAJ. I have built a custom addin to export to .MAJ which is working.
In CADMep I have custom data fields set up with IDs and I want to see these fields but I can not seem to add these to the body of my SaveAsFabricationJob method. Has anyone done this ? Or am i looking at this the wrong way?
Heres my code:

 

[Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();

            if (selectedIds.Count == 0)
            {
                MessageBox.Show("Please select items before exporting to MAJ.");
                return Result.Cancelled;
            }

            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Filter = "MAJ Files|*.maj",
                Title = "Save a MAJ File"
            };

            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return Result.Cancelled;
            }

            string savePath = saveFileDialog.FileName;

            // Create the FabricationSaveJobOptions object. 
            FabricationSaveJobOptions saveOptions = new FabricationSaveJobOptions();
            FabricationPart.

            // Use SaveAsFabricationJob to export to .MAJ
            ISet<ElementId> exportedIds = FabricationPart.SaveAsFabricationJob(uidoc.Document, new HashSet<ElementId>(selectedIds), savePath, saveOptions);

            // Compare exportedIds with selectedIds to determine if any elements weren't exported
            List<ElementId> notExportedIds = selectedIds.Except(exportedIds).ToList();

            if (notExportedIds.Any())
            {
                MessageBox.Show("Some elements were not exported to MAJ.");

                // Printing the IDs of non-exported elements to the console
                foreach (ElementId id in notExportedIds)
                {
                    Console.WriteLine($"Element with ID {id.IntegerValue} was not exported.");
                }
            }

            // Collect instanceId and typeId
            Document doc = uidoc.Document;
            foreach (ElementId eid in selectedIds)
            {
                Element elem = doc.GetElement(eid);
                ElementId typeId = elem.GetTypeId();

            }

            return Result.Succeeded;
        }
    }

 

0 Likes
84 Views
0 Replies
Replies (0)