Professional Documents
Culture Documents
StressCheck COM Training GSG
StressCheck COM Training GSG
I. Introduction
The following getting started guide is intended to demonstrate the
basics of using Microsoft Excel VBA (Visual Basic for Applications)
object-oriented programming concepts in conjunction with the
StressCheck COM API (Application Programming Interface). This is not
intended to be a getting started guide for VBA, but on the StressCheck
COM API. The goal is for users to gain proficiency in using Excel to
solve and post-process StressCheck problems in the automation mode.
A framework for developing automation scripts will be outlined, and a
comprehensive example provided to practice and refine key concepts.
II. What is COM?1
Microsoft COM (Component Object Model) technology in the Microsoft
Windows-family of Operating Systems enables software components to
communicate. COM is used by developers to create re-usable software
components, link components together to build applications, and take
advantage of Windows services. COM is used in applications such as
the Microsoft Office Family of products. For example COM OLE
technology allows Word documents to dynamically link to data in Excel
spreadsheets and COM Automation allows users to build scripts in their
applications to perform repetitive tasks or control one application from
another.
In this guide, it will be shown how Excel can be used to communicate
with StressCheck objects, through VBA and COM API technology, in
order to accomplish a wide variety of automation tasks. First, we must
learn how to enable Microsoft Excel to communicate with StressCheck.
III. Linking Microsoft Excel with the StressCheck Object Library
It is very simple enable Microsoft Excel to communicate with
StressCheck. All that is necessary are proper installations of each
application, and specification of the StressCheck object library to be
referenced by Excel. This library contains all StressCheck objects,
along with the associated methods and properties, needed to develop,
solve, and post-process StressCheck models on the fly. The concepts
contained in the previous sentence will be clarified shortly; that is, if
1
http://www.microsoft.com/com/default.mspx
http://msdn2.microsoft.com/en-us/library/zztsbwsx(VS.80).aspx
object has properties, methods and events which give the object
distinction. The properties, methods, and events of an object are
enabled by the class from which the object is defined. Generally
speaking, a class is an abstract representation of something, whereas
an object is a usable example of the thing the class represents.
Objects are therefore instances of a given class. A class may be
imagined as a blueprint, capable of providing instructions as to how an
object is to be represented. For example, imagine a floor plan for a
house. The floor plan may be represented by the number of rooms,
dimensions for each room, etc. These are properties of the house.
Additionally, instructions may be provided as to how modifications may
be made to a floor plan. These modifications are implemented by
various methods. The floor plan, though, is only a set of instructions,
or an abstraction, for how to produce a house (class). A house is
therefore a habitable, or usable, instance of a given floor plan (object).
From the above example, the idea of StressCheck object hierarchy can
be extrapolated and explored.
V. StressCheck Application Object Hierarchy
In the way that a house can be represented by the number of rooms
and the dimensions of each room, the doors, windows and other
attributes (properties) for each individual room can also be specified.
Additionally, each of the doors in a given room may be assigned a
different color. We may continue extending this hierarchic approach
until all the attributes of the house, meaning all objects and their
properties, have been assigned. These attributes may be assigned by
using the default configurations provided in the floor plan or by
explicitly stating them as the house is built. Since StressCheck is
hierarchic in the manner described above, a user has access to any
StressCheck model attribute through the object hierarchy provided by
the StressCheck COM API.
At the top of the StressCheck object hierarchy is the Application.
Below the Application is the Document (dataset). The StressCheck
Document (dataset) is therefore a property of the StressCheck
Application, but it is also a hierarchic object with its own methods,
properties, etc. The StressCheck Document methods include the
ability to solve a pre-defined solution saved within a StressCheck input
file, or to extract engineering information from a solution using a predefined extraction. Below the Document (dataset) are Model,
Extractions, Solutions, etc. Again, these are properties of the
StressCheck Document but are also hierarchic objects. For instance,
the Model object has as its properties geometric objects, mesh objects,
2013 ESRD, Inc. All Rights Reserved. StressCheck is a
registered trademark of ESRD, Inc.
These concepts are intended to show how the loading, solving, and
post-processing of pre-defined StressCheck models is accomplished via
Excel VBA scripting combined with COM automation. To practice these
concepts, an example will be given at the end of this guide which will
use the framework provided to load, solve, and post-process a
StressCheck Handbook model.
In the following sections, each of the concepts outlined in the
StressCheck automation framework will be examined in detail. Sample
VBA code, with explanations of syntax and structure, will be provided.
VII. Example 1: Plate with Central Hole under Uniform Tension
The goal of the following example is to read an existing StressCheck
Handbook model (peter02.sci in 2-D Basic Handbook folder), modify a
geometric parameter, solve a linear solution and extract the maximum
first principal stress with the error in this value.
) and click
10
As Double, S As Double, W
True
True
True
True
True
11
There are eight (8) rows, one for each polynomial level, and seven (7)
columns, each describing the attributes of the extraction, in the above
StressCheck Datatable. To perform the extraction shown above, we
will simply call the xExtractData method. This is used in the same
manner as the xSolve method, in that we supply the name of the
saved extraction setting (2-Min/Max/Avg). However, because the
xExtractData method returns a StressCheck Datatable object, we must
define a StressCheck Datatable object for assignment (SCDT):
Dim SCDT As StressCheck.DataTable
Set SCDT = SCDoc.xExtractData("2-Min/Max/Avg")
Once the StressCheck Datatable object SCDT is set to the datatable
output by the xExtractData method from the 2-Min/Max/Avg extraction
setting, we may interrogate this datatable for relevant engineering
information. The relevant information for Example1 is the maximum
first principal stress (S1max) and the estimated maximum for this
quantity. From these two values, we can determine the estimated
12
relative error in S1max. Since we are interested in the p=8 value for
S1max, we can directly interrogate the Data property for this value:
Dim S1max As Double, S1maxEstimated As Double, S1maxError
As Double
S1max = SCDT.Data (7, 2)
S1maxEstimated = SCDT.Data (7, 3)
S1maxError = (S1maxEstimated-S1max)/S1maxEstimated*100
The Data property of the SCDT object contains an array of all
extraction information relevant to the given datatable type. As
mentioned, this array is in row and column format with a beginning
index of zero (0). This means that at p=8, we will interrogate row
number seven (7), and for the Max. S1 and Maximum Limit we use
column numbers two and three (2 and 3), respectively. The
S1maxError variable will give us the estimated error percentage for
S1max. We are now ready to place the information from these
variables into our Excel spreadsheet. Navigate back to the Excel
spreadsheet by click on the
icon in the upper left-hand corner of the
Visual Basic interface. Next, click on cell A10 and type Maximum S1,
then click on cell B10 and type Estimated Error. Now, click on the
icon on the Developers tab to bring back the Visual Basic
interface. Finally, input the following code:
Sheet1.Cells (11, 1) = S1max
Sheet1.Cells (11, 2) = S1maxError
This will place the values of S1max and S1maxError in the cells A11
and B11, respectively.
Step 9: Closing the StressCheck Document and Application
After we have completed our tasks, we must close and release the
StressCheck Document and Application objects before exiting the
Visual Basic session. To release the objects, we will simply set them
to Nothing such that the object variables no longer refer to any object
instance:
SCDoc.Close
Set SCDoc = Nothing
SCApp.Close
Set SCApp = Nothing
2013 ESRD, Inc. All Rights Reserved. StressCheck is a
registered trademark of ESRD, Inc.
13
14