Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Last active December 17, 2022 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkoshy/4183d4cae1da69cc3ed6c244df5fb766 to your computer and use it in GitHub Desktop.
Save benkoshy/4183d4cae1da69cc3ed6c244df5fb766 to your computer and use it in GitHub Desktop.
How to programmatically generate a bolt list report from selected model objects
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Model;
namespace RopesProject
{
class Program
{
static void Main(string[] args)
{
Model model = new Model();
if (model.GetConnectionStatus())
{
// or you can otherwise manually select objects and obviate the following code:
List<ModelObject> modelObjects = getModelObjects(model);
Tekla.Structures.Model.UI.ModelObjectSelector selector = new Tekla.Structures.Model.UI.ModelObjectSelector();
selector.Select(new System.Collections.ArrayList(modelObjects));
// This must be contained in a particular folder.
// Users must have this macro on their computer for this
// program to work.
// If you are using Tekla version 20 and above you can simply use the macro builder class which is a lifesaver
Tekla.Structures.Model.Operations.Operation.RunMacro("BoltList.cs");
// use if you are actually changing the model:
model.CommitChanges();
}
}
private static List<ModelObject> getModelObjects(Model model)
{
ModelObjectEnumerator enumerator = model.GetModelObjectSelector().GetAllObjects();
List<ModelObject> modelObjects = new List<ModelObject>();
while (enumerator.MoveNext())
{
ModelObject modelObject = enumerator.Current as ModelObject;
if (modelObject != null)
{
modelObjects.Add(modelObject);
}
}
return modelObjects;
}
}
}
// And here is the macro:
// you MUST save it in the following location:
// adjust according to your environment
// C:\ProgramData\Tekla Structures\19.1\Environments\australasia\macros\modeling\BoltList.cs
// // If you are using Tekla version 20 and above you can simply use the macro builder class which is a lifesaver
// macro builders allow you to write your macros inline in your code, rather than requiring users to save it in a particular
// location. This makes deployment relatively easy.
namespace Tekla.Technology.Akit.UserScript
{
public class Script
{
public static void Run(Tekla.Technology.Akit.IScript akit)
{
akit.Callback("acmd_display_report_dialog", "", "main_frame");
akit.ListSelect("xs_report_dialog", "xs_report_list", "Bolt_Summary");
akit.ModalDialog(1);
akit.PushButton("xs_report_selected", "xs_report_dialog");
// you can of course substitute the type of report here, depending on whether one is available
// and the name of that report. e.g.
// akit.PushButton("INSERT_NAME_OF_REPORT", "xs_report_dialog");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment