Tekla API 常见问题摘录整理

常见问题摘录整理,内容来自Tekla Forum。
 
1. Where can I use the Open API?
You can utilize the Open API in .NET applications (*.exe), plug-ins (*.dll), macros/scripts (*.cs) and COM applications such as VBA macros. Macros/scripts are stored as ASCII files and they are compiled and executed from the menu (Tools->Macros) or the toolbar of Tekla Structures.
 
2. Can I use the Open API in my VBA application?
The Open API can be used in VBA applications by adding a reference to "Tekla_Structures" and "Tekla_Structures_Model" (include “Tekla_Structures_Drawing” if needed) in the VBA editor (Tools->References..).
 
3. Is it possible to use a Tekla Structures model without opening the Tekla Structures software?
The Open API classes and methods in the programming interface do not correspond directly to our database structure, so Tekla Structures must be opened in order to convert and pass information to and from the model database.
 
4. Is it possible to connect to external databases using DataSets classes with a macro script?
You can reference any external .NET assembly if the assembly dll has been added to the XS_MACRO_REFERENCES variable found under modeling properties in the Advanced options dialog of Tekla Structures. For using DataSets you have to add the assembly "System.Data" to the variable. That will add System.Data to be a reference for the macro compiler.
 
5. What is the difference between the Assembly types (Steel_ASSEMBLY, PRECAST_ASSEMBLY,...)?
Those are assembly types for materials (steel, precast concrete and cast-in-place concrete) that are supported in the system.
 
6. I'm looking for a method to check the type of a selected model object. How can I do it?
Use for instance type casting to check the type of a selected object. In C#:
     while(myEnum.MoveNext())
     {
         Beam myBeam = myEnum.Current as Beam;
 
         If (myBeam != null)
         {
             // beam selected, add code for beam here
         }
     }
7. How do I set the work plane to the beam coordinate system in the Open API?
Use the "SetCurrentTransformationPlane" method of the WorkPlaneHandler class in the Open API to set the work plane.
A small example (C#):
TransformationPlane myPlane = new TransformationPlane(myBeam.GetCoordinateSystem());
bool result = myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(myPlane);
8. How do I set the global work plane in the Open API?
Use the "SetCurrentTransformationPlane" default constructor method of the WorkPlaneHandler class in the Open API to set the work plane. A small example (C#): 
TransformationPlane myPlane = new TransformationPlane();
bool result = myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(myPlane);

9. How can I obtain the assembly position number of a part?
One way to get the assembly position number is to inquire the report property. See the example (C#) below:
    Beam B = new Beam(point, point2);

    string AssPos = "";

    if(!B.GetReportProperty("ASSEMBLY_POS", ref AssPos))
        Console.WriteLine("GetReportProperty failed!!!");

10. How do I know which report properties of objects can be asked from Tekla Structures?
The full list of possible properties can be found from the file contentattributes_global.lst in the environments/%env%/template/settings folder.
 
11. What argument should I use in GetObjectsByFilterName method to retrieve only assemblies?
You have to pass the name of the saved attribute file defined in the Object group dialog (the dialog can be opened for instance from the "Object representation" dialog or from the "Setup->Select filter.." menu). Please check that the extension of the used file is correct (*.SObjGrp).
 
12. Is it possible to inquire profile dimensions, for instance thickness of the flange, for one profile?
You can inquire dimensions from the report properties using the GetReportProperty() method of the ModelObject class in the Open API. Please note that a part must be selected first before using the report property inquiry.
Profile values are defined in the report properties "DIM_A", "DIM_B", etc. The full list can be found from contentattributes_global.lst.
 
13. Is it possible to ask input from Tekla Structures in runtime?
It is possible to ask input from the user when an application or a script is executed. This can be done using the Picker class, see the example below:
    try
    {
        Picker picker = new Picker();
        Tekla.Structures.Point p1 = picker.PickPoint();
    }
    catch(Exception e)
    {
        return;   // cancelled etc.
    }
14. Top5 reasons for an exception.
1. A Tekla Structures model or Tekla Structures is not open.
2. The connection to the model/drawing is not initialized (Model myModel = new Model(); needed). Use Model.GetConnectionStatus() or DrawingHandler.GetConnectionStatus() before doing anything. 
3. The Tekla.Structures.Model reference is set to the wrong version (with COM works always with the latest installed version).
4. Incompatible object types (type casting error).
5. Insert or select failed for some reason:
a. A custom component is not found from the model; or,
b. A boolean part operative class is not set to BooleanPart.BooleanOperativeClassName in insert.
Remember try-catch
Wrap your code into try-catch at some level: the usage of exceptions in the Open API will grow.
Both user and Tekla Structures errors can cause an exception -> easier to notice than return values.
 
15. How do I set a bitmap for a plugin?
The bitmap has to be named: et_element_<pluginname>.bmp 
And it has to be located under: \TeklaStructures\<version>\nt\bitmaps\
 
16. How do I select a model object, in the model, when it has been selected in the drawing?
Having selected the desired part in the drawing, partInTheDrawing, use next code:
TSM.ModelObject selectedObject = 
  Model.SelectModelObject(partInTheDrawing.ModelIdentifier);

17. Difference between PluginBase and ConnectionBase.
Plug-in is a component, meaning that is recreated when any of its inputs changes. 

ConnectionBase is a base class for defining Connections, Details and Seams. These types are more specialized and restricted by the input values than the ones derived from PluginBase.
 
18. Can a plug-in, or ConnectionBase, modify it's input?
Plug-ins and ConnectionBase cannot modify their inputs! 
E.g. if you need to make an input shorter use fittings, don't move the extremes of the input.
 
19. Difference between applications and plug-ins.
Plug-ins are components and linked to the model, when any of its inputs is modified the plugin is recreated.

Applications are standalones that create a connection to Tekla Structures when needed.
 
20. How do I check if a model is opened?
ModelInfo modelInfo = Model.GetInfo();

The modelInfo.ModelName variable contains the name of the model that is opened; if no model is opened, it returns a blank string.

 
21. What to do if something is not available in the API?
If something is not available in the API it might be possible to record a macro and run it from your application or plug-in.
Model.RunMacro("MyMacro.cs");
22. Why GetReportProperty doesn’t return anything?
Make sure you are using the correct string, for example getting the width of a profile you need to use PROFILE.WIDTH, not just WIDTH. And remember the returned value have to be the correct one, Width will return a double, not a string or integer.
 
double Thickness2 = 0.0;
modelPart.GetReportProperty("PROFILE.WIDTH", ref Thickness);
 
23. To get an attribute, report property or UDA from an object, this has to be in the model.
If you want to get some attribute, report property or UDA from a model object, the model object has to be present in the model. So if you are creating the model object through the API, first it has to be inserted to get these values.
 
24. Why inserting a part fails?
There part has to have a profile and this has to be a valid one.
 
//This is in Default environment
beam.Profile.ProfileString = "HEA300";
 
25. Difference between view and display coordinate system when creating views in drawings.
For creating a drawing view there are several methods, all of them need two coordinate systems as inputs:

public View(Tekla.Structures.Drawing.ContainerView View, Tekla.Structures.Geometry3d.CoordinateSystem ViewCoordinateSystem,Tekla.Structures.Geometry3d.CoordinateSystem DisplayCoordinateSystem, System.Collections.ArrayList PartList)

The difference between those two coordinate system is:

View coordinate system: this is the coordinate system of the object in the model.
Display coordinate system: this is the coodinate system from which we see the object.

What is important here is that only in the drawings made from 3D views these two coordinate system.

You can find an example on how to use them in the startup package BasicViews.sln, check the methods AddView and AddRotatedView (this last one is the one that uses two different coordinate systems).
 
26. Why a .NET macro throws an exception if it's run after the dialog has been several minutes opened?
This affects to .NET macros that are using the akit interface. 

By default the akit link doesn't last very long time. In order to keep the akit link alive as long as your macro is running you need the next method:

Note: This is the method used in the MultiReportGenerator macro to make sure the akit link is always available.
 
static Tekla.Technology.Akit.IScript akit; 
public static void Run(Tekla.Technology.Akit.IScript akit_in)
{
    System.Runtime.Remoting.Lifetime.ClientSponsor sponsor = null;
    try
    {
        sponsor = new System.Runtime.Remoting.Lifetime.ClientSponsor();
        akit = akit_in;
        sponsor.Register((System.MarshalByRefObject)akit);
        Application.Run(new ReportGenerator());
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
    }
    finally
    {
        if (sponsor != null)
        {
            sponsor.Close();
        }
    }
}

27. How can I know which TS version I'm running?
To get the TS version that is being run you can use the method GetCurrentProgramVersion inside the Model class. This returns a string containing the version and the date when it was build.
string TSVersion = Model.GetCurrentProgramVersion();
 
28. Why I get the next message "Cannot load DLL dakit.dll: Given module not found."?
Have you initialized the connection to the assembly you’re trying to use? eg. new Model() or new DrawingHandler()
 
29. Can report propeties return their values in local coordiante system?
No, report properties are always returned in global coordinates.
 
30. Moving macros between versions.
When moving macros to a new Tekla Structures version you have to move only the .cs files, not the dll or pdb files, so they are rebuild using the new assemblies.
 
31. Do we have any way to start the external application directly from Tekla Structures?
A .NET application can be launched from a Tekla Structures macro script. 
The script can be executed from the toolbar, a menu (customization functionality) or from the macro dialog (Tools->Macros.. in the menu).
External software can be launched from the Tekla Structures macro script by using the System.Diagnostic.Process class in System.dll of the .NET Framework.
Below is an example of opening the Tekla Extranet to Internet Explorer using the url:
// Generated by Tekla.Technology.Akit.ScriptBuilder

using Tekla.Structures.Model;
using SD =System.Diagnostics;

namespace Tekla.Technology.Akit.UserScript {
    public class Script {
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            SD.Process Process = new SD.Process();
            Process.EnableRaisingEvents=false;
            Process.StartInfo.FileName="iexplore";
            Process.StartInfo.Arguments="https://extranet.tekla.com";
            Process.Start();
        }
    }
}    
 
32. How do I enumerate through all objects from a certain type in the model?
For example, enumerating boolean parts, you just have to do the next:
ModelObjectEnumerator BooleanEnum =
Model.GetModelObjectSelector().GetAllObjectsWithType(
ModelObject.ModelObjectEnum.BOOLEANPART);

33. Reading inp files without restarting TS.
You can read inp files without restarting Tekla Structures by setting XS_DYNAMIC_INPUT_FILE=TRUE, preferable in the ...\TeklaStructures\<version>\nt\bin\user.ini file. 

This will enable an "update" button in your inp dialog that when clicked will read your new inp file.

Please be careful when using this feature, since there can be problems, like some memory handling problems. So don't use it during production, only to develop the dialogs for your plugins or custom components.

We don't recommend to use this feature, but since many users know about it we want to warn you of the risks involved in using it.

Edit: please note that the inp name cannot contain any "_", this will cause the update to fail!
 
生存 探索 进化
原文地址:https://www.cnblogs.com/radium/p/3134152.html