Updating and aligning structural data across models using the COM interface

Technical Article

This article was translated by Google Translator

View original text

For some structures, it is necessary to design them in different configurations. Thus, it may be the case that a lifting platform must be analyzed in the position on the ground, in the middle and extended. Since such tasks require the creation of several models, but they are almost identical, updating all models with just one mouse click makes the work considerably easier.

In the following, we assume that you have a basic knowledge of the COM interface. The links provide articles with the basics of programming.

Task

The program should automatically adjust structural data such as nodes, lines, members et cetera by clicking a button in several models. For example, the coordinates of node 1 are to be imported from a main model in various secondary models and variants. However, it is not allowed to transfer all values, but only values that were previously defined as free by the user.

Example Model

As an example for the function of the program, a simple lifting platform was modeled. The following model is considered the main model.

This lift is not parameterized and is available in three variants: fully extended, on the ground and in a middle position. The fully extended variant is defined as the main model, the middle one as variant 1, and the one on the ground as variant 2.

Preliminary Considerations

To achieve the task, you need either a kind of configuration file or a graphical user interface to define which models are to be compared with each other.

To define the free or variable coordinates of a node, use the comment of the respective element. The program should search for a specific string in the comment and, if found, change or leave the corresponding coordinates. In addition, it would be useful if new elements are automatically created in all sub-models as well. The structure should therefore be such that the user activates the desired model in RFEM (edited in the foreground) and then the program opens the required models and compares them with this main model.

Graphical user interface

The following simple design has been selected for the graphical user interface.

The user can use Copy & Paste to insert or type a path in the text box. Click "Add New Model" to add it to the list of models to be adjusted. Use the "Remove Selected Model" button to remove a model selected in the list. The "Modify Models" button starts the program.

Basic program flow

The program initially only has the paths of the secondary models and variants and requires the connection to RFEM first. When the connection to RFEM is established, the next step is to run a loop over the secondary models. Since the program is also to create elements, the hierarchy must be observed. Therefore, the nodes are compared first, then the lines, materials, cross-sections, and finally members. The nodes are an exception because the directions x, y, and z should be adopted or left as required. All other elements are either transferred completely or left unchanged. However, it should be the same for all elements that new ones are created.

Framework of the program

The method that is executed when clicking the "Modify Models" button has the following basic structure.

private void button_mod_click (object sender, EventArgs e)
{
//RFEM
//##############################
Dlubal.RFEM5.IModel3 iModel_org = null;
Dlubal.RFEM5.IApplication iApp = null;
try
{
//get interface to application and open model
iApp = Marshal.GetActiveObject ("RFEM5.Application") as Dlubal.RFEM5.IApplication;
iApp.LockLicense ();
iModel_org = iApp.GetActiveModel () as Dlubal.RFEM5.IModel3;

//loop over found models
Dlubal.RFEM5.IModel iModel_cpy = null;

for (int i = 0; i <listBox_models.Items.Count; ++ i)
{
//open model
iModel_cpy = iApp.OpenModel (listBox_models.Items [i] .ToString ());

//get structural data
Dlubal.RFEM5.IModelData2 iModData_org
= iModel_org.GetModelData () as Dlubal.RFEM5.IModelData2;
Dlubal.RFEM5.IModelData2 iModData_cpy
= iModel_cpy.GetModelData () as Dlubal.RFEM5.IModelData2;

//compare/change nodes
//compare/change lines
//compare/change materials
//compare/change cross sections
//compare/change members
}

}
catch (Exception ex)
{
MessageBox.Show (ex.Message, ex.Source);
}
finally
{
if (iApp! = null)
{
iApp.UnlockLicense ();

//Releases COM object - not needed anymore
//Marshal.ReleaseComObject (iApp);
iApp = null;
}

iModel_org = null;

//Cleans Garbage Collector for releasing all COM interfaces and objects.
System.GC.Collect ();
System.GC.WaitForPendingFinalizers ();
}
}

As already described, the connection to RFEM is created via GetActiveObject ("RFEM5.Application"). Then, a connection to the active model is created via GetActiveModel (). To be able to perform the comparison, the submodels and their structural data (GetModelData ()) are opened one after the other in a loop using the entries in the list box. At this point, all geometric data is available and can be compared.

If there is a problem, for example, that a model cannot be opened, the error is caught by the try-catch block, displayed and the program unlocked.

Node comparison

The comparison of the nodes between the main model and the secondary model is as follows.

First, all nodes of the main model are fetched and a loop is started via these nodes. In this loop, we first try to get the data of the node with the same number in the secondary model. If this fails because the node does not exist, the error is caught with another try-catch block and the node with the data from the main model is created in the secondary model instead.

If the node exists, the comment is read out and separated by means of the separator ";" disassembled. If there are fewer than three parts, the data is imported from the main model. If there are three parts or more, they are evaluated. An "f" stands for a fixed value that should not be overwritten. If it is not an "f", the value is overwritten by the value from the main model.

A short example is the string "f ;; f1; kkl" in the comment of a node. When decomposed, the strings "f", "", "f1" and "kkl" result. Thus, the value x is left at the node and the values y and z are overwritten because there is an empty string for y and for z not exactly "f", but "f1".

//compare/change nodes
Dlubal.RFEM5.Node [] nodes_org = iModData_org.GetNodes ();
for (int j = 0; j <nodes_org.Length; ++ j)
{
try
{
Dlubal.RFEM5.INode iNode = iModData_cpy.GetNode (nodes_org [j] .No, Dlubal.RFEM5.ItemAt.AtNo);
Dlubal.RFEM5.Node node = new Dlubal.RFEM5.Node ();
node = iNode.GetData ();

//check, if there are fixed components
List <string> defs = (node.Comment) .Split (';'). ToList <string> ();

if (defs.Count> = 3)
{
if (defs [0]! = "f")
node.X = nodes_org [j] .X;

if (defs [1]! = "f")
node.Y = nodes_org [j] .Y;

if (defs [2]! = "f")
node.Z = nodes_org [j] .Z;
}
else
{
node.X = nodes_org [j] .X;
node.Y = nodes_org [j] .Y;
node.Z = nodes_org [j] .Z;
}

//set node
iModData_cpy.PrepareModification ();
iNode.SetData (node);
iModData_cpy.FinishModification ();

}
catch (Exception ex)
{
//if nodes doesn't exist, create it;
iModData_cpy.PrepareModification ();
iModData_cpy.SetNode (nodes_org [j]);
iModData_cpy.FinishModification ();
}

}

Lines, materials, and other comparisons

The other elements are slightly different from the node comparison in the process and are identical to each other.

//compare/change lines
Dlubal.RFEM5.Line [] lines_org = iModData_org.GetLines ();
for (int j = 0; j <lines_org.Length; ++ j)
{
try
{
Dlubal.RFEM5.ILine iLine = iModData_cpy.GetLine (lines_org [j] .No, Dlubal.RFEM5.ItemAt.AtNo);
Dlubal.RFEM5.Line line = new Dlubal.RFEM5.Line ();
line = iLine.GetData ();

//check, if the line is fixed
List <string> defs = (line.Comment) .Split (';'). ToList <string> ();

if (defs [0]! = "f")
{
line = lines_org [j];
}

//set line
iModData_cpy.PrepareModification ();
iLine.SetData (line);
iModData_cpy.FinishModification ();

}
catch (Exception ex)
{
//if nodes doesn't exist, create it;
iModData_cpy.PrepareModification ();
iModData_cpy.SetLine (lines_org [j]);
iModData_cpy.FinishModification ();
}

}

The difference to the node comparison is that the element is completely overwritten if no "f" is found in the decomposed comment (decomposed with ";"). The other elements are created and compared in exactly the same way. See the source code in the attached Visual Studio project.

Evaluation

The program is able to implement the desired changes in the secondary models. The functionality is shown in the video of the article. The biggest problem currently is that incorrect entries are not or only slightly intercepted.

Summary and Outlook

The program presented here is able to update secondary models on the basis of a main model. Changes from nodes to members are transferred correctly.

What is missing are routines for intercepting incorrect entries, which could be supplemented. Further optimizations would be, for example, the optional closing of the secondary models, which can lead to processing in the background. It may also be useful to add additional structural data, loads, and combinations.

Keywords

COM Super combination Components All models Update Lifting platform Scissor lift

Downloads

Links

Write a Comment...

  • Views 265x
  • Updated 10/23/2020

Contact us

Do you have questions or need advice?
Contact our free e-mail, chat, or forum support or find various suggested solutions and useful tips on our FAQ page.

(267) 702-2815

info-us@dlubal.com

RFEM Main Program
RFEM 5.xx

Main Program

Structural engineering software for finite element analysis (FEA) of planar and spatial structural systems consisting of plates, walls, shells, members (beams), solids and contact elements

Price of First License
3,540.00 USD
RFEM Other
RF-COM 5.xx

Add-on Module

Programmable interface (API) based on the COM technology

Price of First License
580.00 USD