Tekla Open API: print drawings to PDF and export IFC

Grasshopper Tekla Drawing Link has an export component for PDF and one for IFC. The PDF one doesn’t call PrintDrawing. There are two ways to get a PDF out of Tekla from code, and they need opposite things. The API wants the drawing closed. The printer exe wants it open.

PrintDrawing: the drawing closed, the settings in code

var dh = new DrawingHandler();
var attributes = new DPMPrinterAttributes
{
    OutputType    = DotPrintOutputType.PDF,
    ScalingMethod = DotPrintScalingType.Auto,
};

// Tekla's own naming, revision mark included; the 2nd argument overrides OutputFileName
string file = Path.Combine(folder, drawing.GetPlotFileName(true) + ".pdf");
bool printed = dh.PrintDrawing(drawing, attributes, file);   // false, not an exception, when it fails

Paper size, orientation, colour and scale are all properties on DPMPrinterAttributes. The file name property is OutputFileName. OutputFile is the easy guess, and it doesn’t exist on this class. The drawing must not be open in the editor, so close it first. And let GetPlotFileName build the name. A file name rebuilt by hand from Mark won’t match what the checker gets from Tekla’s own print dialog.

Drawing Link prints with the settings you saved in Tekla

A Grasshopper user doesn’t want to set the paper size in code. They already have PDF settings saved in the Print Drawings dialog, as <name>.PdfPrintOptions.xml. Tekla ships DPMPrinterCommand.exe, which takes that file. It prints the active drawing, so Drawing Link opens the drawing in the background first:

string bin = string.Empty;
TeklaStructuresSettings.GetAdvancedOption("XSBIN", ref bin);
string printer = Path.Combine(bin.Replace(@"\\", @"\"),
    @"applications\Tekla\Model\DPMPrinter\DPMPrinterCommand.exe");

bool wasOpen = IsSameDrawing(dh.GetActiveDrawing(), drawing);  // the user already has it open
if (!wasOpen)
    dh.SetActiveDrawing(drawing, false);            // false = open it without showing it

try
{
    string args = $"printActive:true printer:pdf settingsFile:\"{settingsFile}\" out:\"{file}\"";
    using (var p = Process.Start(new ProcessStartInfo(printer, args) { WindowStyle = ProcessWindowStyle.Hidden }))
        p.WaitForExit();
}
catch (CannotPerformOperationDrawingNotUpToDateException)
{
    // the drawing isn't up to date: report it, don't print an old one
}
finally
{
    if (!wasOpen)
        dh.CloseActiveDrawing();                    // never close the drawing the user is working in
}

Drawing has no public Identifier, so IsSameDrawing is a few lines of your own. Drawing Link reads the internal id by reflection. Three more details from the same component. It finds the settings file with TeklaStructuresFiles.GetAttributeFile, so model, project and firm folders all work. It reads <IncludeRevision> from that file and passes it to GetPlotFileName, so the PDF name matches the dialog’s. And it replaces characters that Windows refuses in file names.

The honest caveat: DPMPrinterCommand.exe isn’t part of the Open API. It’s a program in Tekla’s bin folder. Drawing Link has used it since November 2024, and it still works on 2026. Nobody promises it will in 2027, so test it after every upgrade.

IFC export is a component that runs when you insert it

var input = new ComponentInput();
input.AddOneInputPosition(new Point(0, 0, 0));

var export = new Component(input)
{
    Name   = "ExportIFC",                                // exact name: the exporter is a plug-in
    Number = BaseComponent.PLUGIN_OBJECT_NUMBER,
};
export.LoadAttributesFromFile("standard");               // the settings saved in the export dialog
export.SetAttribute("OutputFile", @"C:\Models\Hall B\IFC\walls.ifc");  // a file name, not a folder
export.SetAttribute("CreateAll", 0);                     // 0 = selected objects, 1 = the whole model
export.Insert();                                         // inserting it runs the export

Here it really is OutputFile: an attribute of the plug-in, not a property of the printer class. Drawing Link refuses a path that ends in \ and adds .ifc when it’s missing.

IFC4 takes every option as an argument

From Tekla 2022 there’s a direct call. It doesn’t read a settings file: you pass each option.

bool exported = Operation.CreateIFC4ExportFromSelected(
    @"C:\Models\Hall B\IFC\walls.ifc",
    Operation.IFCExportViewTypeEnum.REFERENCE_VIEW,
    new string[0],                                     // no extra property set files
    Operation.ExportBasePoint.GLOBAL,
    "__Name__",                                        // layers by name; "__Phase__" for phases
    "ByObjectClass",
    new Operation.IFCExportFlags { IsBoltsEnabled = true, IsRebarsEnabled = true },
    string.Empty);                                     // base point name, only for BASE_POINT

Drawing Link’s IFC4 component reads the dialog’s .ifc4export.json and maps each field to one of these arguments. Two version notes. The 2026 documentation lists a longer overload with an export version and attribute override files, but the eight-argument call above compiles on 2024, 2025 and 2026. And on 2026, IsAssembliesEnabled is obsolete. The compiler points you to IncludeAssemblyHierarchy.

“Selected” means selected in the model view

CreateAll = 0 and CreateIFC4ExportFromSelected both export what’s highlighted in Tekla. Neither takes a list. Drawing Link’s components take objects as input, so they select those objects first:

// using UISelector = Tekla.Structures.Model.UI.ModelObjectSelector;
new UISelector().Select(new ArrayList(walls));          // replaces the user's selection

Select replaces whatever the user had selected. Say so in the tool, or put their selection back afterwards. Reading a selection has traps of its own, and the next post covers them.

Before an export runs on a colleague’s PC

  • PrintDrawing: the drawing closed, the settings in DPMPrinterAttributes, and check the bool.
  • DPMPrinterCommand: the drawing open in the background, the saved settings file, and close only what you opened.
  • PDF names come from GetPlotFileName, with illegal characters replaced.
  • The IFC output is a file path ending in .ifc, not a folder.
  • “Selected” exports use the model view’s selection. Select first, and tell the user.

Exports are components too. In lesson 6 of the course you insert a system connection from code and drive its attributes. Then you reuse the same Component pattern to run an IFC export: one mechanism, two jobs. The PrintDrawing rules are in the Tekla Open API skill (closed drawing, OutputFileName, GetPlotFileName), so your agent starts from them instead of the forum mix.

Tekla Open API Course: build real Tekla tools with an AI agent →

Related: Get selected objects in Tekla Open API (and use LINQ on them) · Tekla TSEP packaging: build a .tsep with BatchBuilder · What is Tekla Open API? A guide for detailers and engineers

Tags

Greg Olszewski

Greg Olszewski builds Tekla Open API tools: Grasshopper Tekla Drawing Link, Smart Select, Tekla Lookup. Ten years of C# on Tekla Structures, day job in precast. Now he teaches engineers to build their own.

About Greg ›

COURSE

Build your own Tekla tools

Learn the Tekla Open API in C#, from your first plug-in to tools your team actually uses.

See the course ›