Add custom data fields to .MAJ export from Revit

Add custom data fields to .MAJ export from Revit

mmckeonXZRL9
Contributor Contributor
223 Views
1 Reply
Message 1 of 2

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
224 Views
1 Reply
Reply (1)
Message 2 of 2

craigjonnson
Collaborator
Collaborator

We created an API for this exact same thing. Im not the developer of this app though. I have had this working using the Fabrication Bolognese dynamo package, you should be able to find which Revit API it uses from that package.

 

And dont quote me on this, but check out the API SetPartCustomDataInteger Method (revitapidocs.com)

Additionally, this should be posted in the API forum, you will get better help in there.

craigjonnson_1-1694609221943.png

 

 

 

0 Likes