Not all Tekla Structures functionalities can be recorded as a macro script

Tekla Structures - Not version-specific macro script api
Environment
Not environment-specific


Question:

I cannot get a recorded macro to work on an assembly drawing.

I open an assembly drawing and record a macro to remove the main part center line shown on the drawing when a user decides it is unnecessary for it to be shown.
While the macro is being recorded, the center line is removed as expected.
I open a new assembly drawing (with a main part center line shown) and the recorded macro is running, but nothing happens – it seems the macro does not run at all.
The macro is in the correct location. Any ideas why the recorded macro does not work?

Answer:

Not all Tekla Structures functionalities can be recorded as a macro script.
But you can make it work as you want using Tekla OpenAPI in the macro script.
The code snippet below removes part center lines shown on the opened drawing.
Create a *.cs file which contains the below code and store it in the folder defined with the advanced option XS_MACRO_DIRECTORY.

// Generated by Tekla.Technology.Akit.ScriptBuilder

using Tekla.Structures.Drawing;

namespace Tekla.Technology.Akit.UserScript
{
    public class Script
    {
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            var DrawingHandler = new DrawingHandler();
            if (DrawingHandler.GetConnectionStatus())
            {
                var CurrentDrawing = DrawingHandler.GetActiveDrawing();
                if (CurrentDrawing != null)
                {
                    var DrawingObjectEnumerator = CurrentDrawing.GetSheet().GetAllObjects(typeof(Part));
                    foreach (Part myPart in DrawingObjectEnumerator)
                    {
                        myPart.Attributes.DrawCenterLine = false;
                        myPart.Modify();
                    }
                }
                CurrentDrawing.CommitChanges();
            }  
        }
    }
}
 

Was this helpful?
Submit