Tekla Custom Inquiry macro script

Tekla Structures custom inquire toolOne of the main advantages of Tekla Structure is ability to get full necessary info about any part of model in couple clicks. I really appreciate this thing but all default tools has some disadvantages.

For example default Inquire return complete info about selected Entity, but about only one item per time, and only after user request. Custom Inquire – from Tools menu – is mach more flexible, but also – only one item, and  there is no way to get UDA.

Organizer tool from the same menu – is pretty cool. But at the same time it’s pretty slow, and could freeze model for couple minutes.

Reports, is awesome, but not interactive at all and require special skills and time to get used to with Template Editor.

Let’s make our own custom Inquire, and it’s qute easy with C# and Tekla Open API.

In one of previous articles was provided Tekla API Envents example from Tekla OpenAPI reference. Why not to make macro based on this feature?

All what we have to do is:

  • Make a form
  • Sign this form on Tekla Event
  • Grab data from Tekla each time when event appears
  • Show it to user, in on a form
  • Pack all this thing in Tekla MacroScript

Simple, and this macro could be downloaded under cut:

http://cadsupport.ru/en/upload/CADSUPPORT_CustomInquireTool.cs

If you do not now where to put it, and how to run you could look here: how to work with tekla structure macro script

So now lets take a look on script it self. It’s based on example which was provided before in article about Tekla Events

Tekla Custom Inquire main method

Most interesting part of a scripts is represented in Events_SelectionChangeEvent() method. Here we grab all selected items from model in manyO enumerator. Then going through each element, and if this Entity suitable for us get some properties.

 

        void Events_SelectionChangeEvent()
        {
            lock (_selectionEventHandlerLock)
            {
                Tekla.Structures.Model.UI.ModelObjectSelector selected = new Tekla.Structures.Model.UI.ModelObjectSelector();
                Tekla.Structures.Model.ModelObjectEnumerator manyO = (selected.GetSelectedObjects() as ModelObjectEnumerator);
                string txt = string.Empty;
                while (manyO.MoveNext())
                {
                    string GUID = string.Empty;
                    string POS = string.Empty;
                    string UDA = string.Empty; 
                    if ((manyO.Current as Part) != null) //change for Assembly, Bolt, or whatever. 
                    {
                        var pp = (manyO.Current as Part); 
                            pp.GetReportProperty("ASSEMBLY.GUID", ref GUID);
                            pp.GetReportProperty("ASSEMBLY_POS", ref POS);
                            pp.GetReportProperty("ASSEMBLY.MAINPART.USERDEFINED.SOME_UDA", ref UDA);
                        txt += GUID + "; " + POS +"; "+UDA+Environment.NewLine; 
                    }
                    else if ((manyO.Current as Assembly)!= null)
                        {
                        var pp = (manyO.Current as Assembly); 
                            pp.GetReportProperty("GUID", ref GUID);
                            pp.GetReportProperty("ASSEMBLY_POS", ref POS);
                            pp.GetReportProperty("MAINPART.USERDEFINED.SOME_UDA", ref UDA);
                            txt += GUID + "; " + POS +"; "+UDA+Environment.NewLine; 
                        }
                }
                SetText(txt.ToString());//this method push result to form in separate thread
            }
        }

Additional example of code

// here we can check any object which inherite ModelObject interface bolts, welds, beams, assembly, etc
                if ((manyO.Current as ModelObject) != null)
                {
                    var pp = manyO.Current as ModelObject;
                        string GUID = string.Empty;
                        string POS = string.Empty;
                        string UDA = string.Empty;
                        string DP = string.Empty;
                        pp.GetReportProperty("GUID", ref GUID);
                        pp.GetReportProperty("STANDARD", ref POS);
                        pp.GetReportProperty("ASSEMBLY.MAINPART.USERDEFINED.UDA", ref UDA);
                        txt += GUID + "\t " + POS + "\t " + UDA + Environment.NewLine;
                }

More articles about Tekla OpenAPI and Macro

4 thoughts on “Tekla Custom Inquiry macro script

  1. Mason August 14, 2023 at 6:22 am

    Thanks for the useful information you posted. I have a question which of course is not in “inquiry object”!Suppose a poly beam is modeled.
    And we know that this beam is modeled from three nodes, each of which has its own coordinates.
    How can we find the coordinates of the third (final) node and put it in the form of (x,y,z) fields in the template? I will be grateful for your guidance.

  2. DonJad August 14, 2023 at 11:10 am

    To be honest, if case a bit way complicated than something simple – I prefer to make a macro to extract information.
    Template Editor – is great. And guys put a lot of efforts to make it universal as possible. But it have a price – it took a lot of time. Instead of try to goes through TE user expiriense, I prefer tekla API shortcuted way.

  3. Mason August 14, 2023 at 1:16 pm

    Of course, I am still reviewing this issue and the output in the “template editor”. Do you think there is really a way for this topic to be output in “template”? Because there is no field for this purpose!!

Leave a Reply

Name *
Email *
Website