概要信息:
www.cadfamily.com
The document is forAspen HYSYS Customization Guide EMail:cadserv21@hotmail.com
study only,if tort to your rights,please inform us,we will delete
www.c
The doVersion Number: 7.0
Copyright (c) 1981-2008 by Aspen Technology, Inc. All rights reserved.
Aspen HYSYS, Aspen RefSYS, Aspen HYSYS Refining, Aspen FLARENET, Aspen Flare System Analyzer,
Aspen HX-Net, Aspen Energy Analyzer, Aspen RefSYS Catcracker(FCC), Aspen HYSYS Refining
CatCracker, Aspen HYSYS PIPESYS, and Aspen HYSYS Pipeline Hydraulics, are trademarks or registered
trademarks of Aspen Technology, Inc., Burlington, MA.
All other brand and product names are trademarks or registered trademarks of their respective
companies.
This manual is intended as a guide to using AspenTech’s software. This documentation contains
AspenTech proprietary and confidential information and may not be disclosed, used, or copied without
the prior consent of AspenTech or as set forth in the applicable license agreement. Users are solely
responsible for the proper use of the software and the application of the results obtained.
Although AspenTech has tested the software and reviewed the documentation, the sole warranty for the
software may be found in the applicable license agreement between AspenTech and the user.
ASPENTECH MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESSED OR IMPLIED,
WITH RESPECT TO THIS DOCUMENTATION, ITS QUALITY, PERFORMANCE,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
Aspen Technology, Inc.
200 Wheeler Road
Burlington, MA 01803-5501
USA
Phone: (781) 221-6400
Website http://www.aspentech.comadfamily.com EMail:cadserv21@hotmail.com
cument is for study only,if tort to your rights,please inform us,we will delete
www.c
The doadfamily.com EMail:cadserv21@hotmail.com
cument is for study only,if tort to your rights,please inform us,we will delete
v
ww
ThTechnical Supportv
Online Technical Support Center ........................................................ vi
Phone and E-mail .............................................................................. vii
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
vi
ww
ThOnline Technical Support
Center
AspenTech customers with a valid license and software
maintenance agreement can register to access the Online
Technical Support Center at:
http://support.aspentech.com
You use the Online Technical Support Center to:
• Access current product documentation
• Search for technical tips, solutions, and frequently asked
questions (FAQs)
• Search for and download application examples
• Search for and download service packs and product
updates
• Submit and track technical issues
• Send suggestions
• Report product defects
• Review known deficiencies and defects
Registered users can also subscribe to our Technical Support e-
Bulletins. These e-Bulletins proactively alert you to important
technical support information such as:
• Technical advisories
• Product updates and releasesvi
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
vii
ww
ThPhone and E-mail
Customer support is also available by phone, fax, and e-mail for
customers who have a current support contract for their
product(s). Toll-free charges are listed where available;
otherwise local and international rates apply.
For the most up-to-date phone listings, please see the Online
Technical Support Center at:
http://support.aspentech.comvii
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
viii
ww
Thviii
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Table of ContentsTechnical Support..................................................... v
Online Technical Support Center ............................vi
Phone and E-mail................................................ vii
1 Introduction .........................................................1-1
1.1 Customization.................................................. 1-2
1.2 Automation & Extensibility................................. 1-3
1.3 Customizing HYSYS .......................................... 1-6
2 Automation...........................................................2-1
2.1 Introduction .................................................... 2-2
2.2 Objects........................................................... 2-2
2.3 Automation Syntax........................................... 2-9
2.4 Key HYSYS Objects .........................................2-17
2.5 Example 1: The Macro Language Editor..............2-44
2.6 Example 2: Automation in Visual Basic...............2-50
3 Extensibility .........................................................3-1
3.1 Introduction .................................................... 3-3
3.2 Implementing Interfaces ................................... 3-5
3.3 Data Types...................................................... 3-6
3.4 Extension Development Kit................................ 3-7
3.5 Creating an Extension....................................... 3-9
3.6 Registering Extensions.....................................3-21
3.7 Extension Interface Details ...............................3-26
3.8 Extension Reaction Kinetics ..............................3-28
3.9 Extension Property Packages ............................3-46
3.10 Extension Unit Operations ................................3-52
3.11 References .....................................................3-80
4 Extension View Editor...........................................4-1ix
www.cadfamily.com EMail:cadserv21@hotmail.com
The document is for study only,if tort to your rights,please inform us,we will delete
4.1 Introduction .................................................... 4-3
4.2 Using the View Editor........................................ 4-8
4.3 Widget Properties............................................4-28
5 User Variables ......................................................5-1
5.1 Introduction .................................................... 5-2
5.2 Adding a User Variable...................................... 5-2
5.3 Importing/Exporting User Variables .................... 5-7
5.4 User Variable Property View............................... 5-9
5.5 Data Types.....................................................5-10
5.6 User Variables Tabs.........................................5-13
5.7 Code Editor ....................................................5-20
5.8 User Variable Examples....................................5-22
6 User Unit Operation..............................................6-1
6.1 Introduction .................................................... 6-2
6.2 Adding a User Unit Operation............................. 6-2
6.3 User Unit Op Property View ............................... 6-5
6.4 Dehumidifier Example......................................6-12
7 Aspen Custom Modeler Operation.........................7-1
7.1 Introduction .................................................... 7-2
7.2 Creating an ACM Model ..................................... 7-3
A Customization FAQ ...............................................A-1
A.1 Automation FAQ............................................... A-2
A.2 Extensibility FAQ............................................ A-10
Index.................................................................... I-1x
www.cadfamily.com EMail:cadserv21@hotmail.com
The document is for study only,if tort to your rights,please inform us,we will delete
Introduction 1-1
ww
Th1 Introduction1-1
1.1 Customization ................................................................................ 2
1.2 Automation & Extensibility............................................................. 3
1.2.1 Automation ............................................................................. 3
1.2.2 Extensions .............................................................................. 4
1.3 Customizing HYSYS........................................................................ 6
1.3.1 HYSYS & the Macro Language Editor ........................................... 7
1.3.2 Programming HYSYS from External Programs............................... 9
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
1-2 Customization
ww
Th1.1 Customization
Unlike its accompanying volumes, the Customization Guide does
not discuss exact procedures for accomplishing tasks within
HYSYS. The purpose of this volume is to demonstrate the
possible simulation technologies that can be created both within
HYSYS and also in addition to the application. HYSYS
incorporates an advanced software architecture and OLE
Technology to provide a component-based framework that can
be easily customized, updated and maintained to meet changing
user requirements.
The term customization encompasses several different
approaches for tailoring HYSYS including:
The difference between automation and extensibility may not be
explicitly apparent. The difference lies in the environment in
which your personal algorithms are executed. Automation
requires the use of third party software to link to HYSYS in a
client-server relationship. Using this functionality, you can hide
the complexity of a simulation by building a front-end in another
program that allows access to only the important parameters of
the simulation. You can also use HYSYS as a server in your own
applications. HYSYS is an Automation Server, which means that
it can act as an Automation client that can be used to access
HYSYS. Some examples of tools that can access HYSYS are
Microsoft Visual Basic and the VBA component of applications
such as Excel, Word, PowerPoint and Visio. You can also access
HYSYS through programs written in C++.
Extensibility incorporates your custom algorithms in the form of
Extension Property Packages, Extension Unit Operations, and
Extension Reaction Kinetics. The calculations take place within
the calculation sequence of a HYSYS simulation. Extensions can
Method Description
Automation The use of third party tools such as Visual Basic or the
HYSYS Macro Language Editor to programmatically run
HYSYS.
Extensibility The creation of custom unit operations, property packages
and kinetic reactions which become part of the simulation
and function as built in HYSYS objects. 1-2
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Introduction 1-3
ww
Thbe easily distributed to other machines, and they appear as any
other HYSYS object in the program. You could easily develop an
extension, test it, market it and sell it to other HYSYS users as a
third party add-in.
The Customization Guide’s purpose is threefold:
• To introduce the user to the functionality of HYSYS
automation and extensibility.
• To demonstrate different methods of accessing and using
HYSYS objects.
• To provide straightforward examples that teach you the
basics and allow you to begin customizing HYSYS.
Within the HYSYS environment, several tools are provided so
you can begin writing code for automation and extensions:
1.2 Automation &
Extensibility
1.2.1 Automation
Automation allows programmers to expose objects within a
program for use by other applications. The exposed objects
provide the means by which different applications can interact
with each other and the operating system. Automation is a
standard based on Microsoft's Component Object Model (COM).
It is not necessary to understand all the intricacies of
Automation or COM in order to utilize the functionality they
provide.
Automation evolved from what was once called OLE, which
stands for Object Linking and Embedding. This allowed you to
take a particular object such as a spreadsheet and embed it into
Tool Description
The Macro Language
Editor
An interactive design environment for developing,
testing and executing WinWrap basic scripts.
User Variables and the
User Unit Operation
Allow you to increase the functionality of HYSYS
by creating your own variables or unit operations.
For more information on
User Variables and User
Unit Ops see Chapter 5
- User Variables and
Chapter 6 - User Unit
Operation.1-3
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
1-4 Automation & Extensibility
ww
Thanother object such as a text document. Changes to values in
the spreadsheet would automatically be updated in the text
document. This was a very powerful feature and was available to
users without the added complexity of writing code. It was
simply a matter of cutting and pasting the objects.
Automation is the ability to programmatically interact with an
application through objects exposed by developers of that
application. While HYSYS was being developed, code was added
to expose various objects in the program. By using an
Automation client like Visual Basic, the end user can write the
code to access these objects and interact with HYSYS. The end
user does not need to see the HYSYS source code or even
understand what was required to expose the objects. All that is
required is the knowledge of those objects that are available.
Automation works in a client/server fashion. A server is
something that provides a service that can be used by clients if
they know the proper protocols. HYSYS is an Automation server
application. By writing a little Visual Basic code, it is possible to
send and receive information to and from HYSYS. The exposed
objects make it possible to perform nearly any action that is
accomplished through the HYSYS graphical user interface.
You can use Automation to access COMThermo in HYSYS to
calculate COMThermo properties such as fugacity coefficients, K-
values, entropy, and enthalpy
1.2.2 Extensions
The HYSYS architecture allows direct extensibility for unit
operations, kinetic reactions, and property packages.
Extensibility can be described as the ability to augment existing
functionality in a direct and seamless manner. Unit operation
extensions look and feel like the existing operations in HYSYS
but the algorithms used by the extension reside in a separate
Windows DLL. Similarly, kinetic reaction extensions and
property package extensions appear seamlessly in the basis
environment.1-4
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Introduction 1-5
ww
ThA HYSYS extension is typically composed of two distinct and
interdependent components; an ActiveX Server DLL and an
Extension Definition File (EDF). The ActiveX Server DLL contains
the actual code for the extensions and can be created in any
OLE controller language such as Visual Basic, C++, or Delphi.
Nearly any other type of compiled code base can be accessed
via a short wrapper utilizing Visual Basic or C++. The Server is a
program that exposes a class with a set of properties and
methods. For HYSYS extensions, the exposed class contains
methods recognized by HYSYS (for example, when dealing with
a Unit Operation Extension, HYSYS looks for a method named
Initialize that takes one argument and returns a long variable).
The EDF file acts as the interface view within HYSYS as well as
the point for variable declaration and storage. It is created
through the Extension View Editor which is included with your
copy of HYSYS. The View Editor is similar to the tool used by
AspenTech Developers when creating the property views for
HYSYS.
How Does a Hysys Extension Work?
When HYSYS first starts up, it looks in the system registry, at a
specific location, to see if any extensions exist for the machine.
If an extension does exist it is added to the appropriate menu
within HYSYS. Unit operation extensions show up in the UnitOps
property view when the Extensions radio button is selected.
Kinetic reaction extensions show up in the Reactions property
view which is brought up when the Add Rxn button is clicked on
the Reactions tab of the Simulation Basis Manager property
view. Property package extensions show up in the Property
Package Selection group found on the Set Up tab of the Fluid
Package property view.
Once you find the appropriate extension, you can select it and
begin using it as though it were a built-in HYSYS object. 1-5
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
1-6 Customizing HYSYS
ww
Th1.3 Customizing HYSYS
HYSYS can be programmatically run from any tool that supports
Automation. You can set up scripts that do repetitive tasks, or
you can set up programs of your own that uses HYSYS as the
calculation engine.
For example, the simulation of a plant can be easily hidden by a
front-end created in Microsoft Excel. This front-end could be a
yield prediction program of some sort that uses a rigorous
simulation underneath. Another example would be a proprietary
equipment sizing program that uses HYSYS to generate fluid
properties for the calculations.
When creating these programs, HYSYS can be run invisibly. You
do not need to know the source of the calculations, nor do you
need to deal with another program on the desktop.
Third party tools are not required to access the automation
capabilities of HYSYS. HYSYS provides an Internal Macro Engine
that supports the same syntax as Microsoft Visual Basic. With
this engine, you can automate tasks in HYSYS without the need
for another program.1-6
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Introduction 1-7
ww
Th1.3.1 HYSYS & the Macro
Language Editor
The Macro Language Editor is accessed by selecting the Macro
Language Editor command from the Tools menu in the
Simulation environment.
The editor is an interactive design environment for developing,
testing and executing WinWrap Basic automation scripts. The
editor, which uses a syntax that is very similar to Microsoft®’s
Visual Basic, allows you to write code that interacts with HYSYS.
Two objects can be accessed directly from any point in a macro:
• Application
• ActiveCase
These special commands allow you to generalize your macros so
that they can be run under many different situations. If you
reference the ActiveCase object, your macro works for any
Simulation Case that is currently open in the HYSYS
environment.
Figure 1.1
For more information on
the Macro Language
Editor, consult the online
help that accompanies
the editor. You can find
the online help in the
Help menu in the Editor’s
menu bar.1-7
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
1-8 Customizing HYSYS
ww
ThThe Macro Language Editor now has two new features:
• Autocompletion feature, which helps you complete the
user variable codes and helps you debug the program
with flyby evaluation.
For example, if you want to specify “SimulationCase”,
you just need to type up the first few letters of the
variable, and the autocompletion feature will display all
variables with similar names in a drop-down list.
• List command feature, which shows you a list of valid
methods or properties depending on the context (type of
expression) you enter.
For example, if you type ActiveObject and type the
period, a drop-down list appears displaying a list of
methods that are applicable to the current object.
Figure 1.2
Figure 1.31-8
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Introduction 1-9
ww
Th1.3.2 Programming HYSYS
from External Programs
HYSYS can be accessed from external programs using
Automation. Programs such as Microsoft Visual Basic and
Microsoft Excel can use HYSYS as a calculation engine, allowing
you to create new applications that invisibly use HYSYS in the
background.
Two HYSYS objects can be created by an external program:
• The HYSYS Application object
• The HYSYS SimulationCase object
The Application object can be created using one of the
HYSYS.Application ProgIDs. The ProgID determines which
version of HYSYS is activated. Simulation Cases can be created
using the HYSYS.SimulationCase ProgID, or by calling GetObject
and passing the name of a Simulation Case. For example, this is
how you would create an Application object and a
SimulationCase object from Visual Basic:
Once the Application and Case objects have been created, other
HYSYS objects can be accessed through them. For example,
from the Case's flowsheet object (accessed through the
flowsheet property of the Case), you can create new Process
Streams and Unit Operations.
Dim App as Object
Set App = CreateObject(“HYSYS.Application”)
Dim HYCASE as Object
Set HYCASE = GetObject(“c:\hysys\cases\azeocol.hsc”)1-9
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
1-10 Customizing HYSYS
ww
ThVBA
Microsoft Excel and related products make use of Visual Basic
for Applications (VBA). VBA is a high level programming
language that is oriented around an object framework and event
driven execution. Visual Basic is termed “visual” because most
applications are created around a graphical interface and Visual
Basic is designed to allow code associated with the interface to
be added easily and intuitively.
Event driven programming is quite different from typical
structured programming. In a structured program, execution
begins at the top of the program and executes for the most part
in a sequential manner. When the bottom of the program is
reached the application exits and is finished. In event driven
programming, the path of execution from the beginning of the
program to the end depends almost entirely on how the end
user interacts with the application.
Visual Basic for Applications is a large sub-set of the Visual Basic
language. It is a macro language that is integrated tightly in to
supporting applications. The syntax and functionality is identical
to straight Visual Basic.1-10
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-1
ww
Th2 Automation2-1
2.1 Introduction................................................................................... 2
2.2 Objects .......................................................................................... 2
2.2.1 Object Hierarchy ...................................................................... 3
2.2.2 HYSYS Type Library .................................................................. 4
2.2.3 Object Browser ........................................................................ 5
2.3 Automation Syntax ........................................................................ 9
2.4 Key HYSYS Objects ...................................................................... 17
2.4.1 HYSYS Object Overview .......................................................... 17
2.4.2 Container Objects................................................................... 18
2.4.3 Basis Objects......................................................................... 22
2.4.4 Oils Objects........................................................................... 26
2.4.5 Stream Objects...................................................................... 29
2.4.6 Operation Objects .................................................................. 33
2.4.7 Support Objects ..................................................................... 37
2.4.8 PFD Objects........................................................................... 43
2.5 Example 1: The Macro Language Editor........................................ 44
2.6 Example 2: Automation in Visual Basic ........................................ 50
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-2 Introduction
ww
Th2.1 Introduction
Automation, defined in its simplest terms, is the ability to drive
one application from another. For example, the developers of
Product A have decided in the design phase that it would make
their product more usable if they exposed Product A’s objects,
thereby making it accessible to Automation. Since Products B, C
and D all have the ability to connect to applications that have
exposed objects, each can programmatically interact with
Product A.
In the early product planning stages, the HYSYS development
team had the vision to begin exposing objects. That makes
HYSYS a very powerful and useful tool in the design of hybrid
solutions. Since access to an application through Automation is
language-independent, anyone who can write code in Visual
Basic, C++ or Java, to name three languages, can write
applications that interact with HYSYS. There are a number of
applications that can be used to access HYSYS through
Automation, including Microsoft Visual Basic, Microsoft Excel and
Visio. With so many combinations of applications that can
transfer information, the possibilities are numerous and the
potential for innovative solutions is endless.
2.2 Objects
The key to understanding Automation lies in the concept of
objects. An object is a container that holds a set of related
functions and variables. In Automation terminology, the
functions of an object are called methods and the variables are
called properties.
Consider the example of a car. If it were an object, a car would
have a set of properties such as: make, colour, number of
doors, etc. The car object may also have methods such as: turn
on, drive or open hood. By utilizing the properties and methods
of a car object it is possible to define, manipulate and interact
with the object.2-2
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-3
ww
ThEach property of the car is a variable that has a value associated
with it. The colour would be a string or hexadecimal number
associated with a specific colour. The gas mileage would be
single floating point value. Methods are nothing more than
functions and sub-routines associated with the object.
An object is a container that holds all the attributes associated
with it. An object could contain other objects that are logical
sub-set of the main object. The car object may contain other
objects such as engine or tire. These objects would have their
own set of independent properties and methods. An engine
would have properties related to the number of valves and the
size of the pistons. The tires would have properties such as
tread type or model number.
2.2.1 Object Hierarchy
The path that is followed to get to a specific property may
involve several objects. The path and structure of objects is
referred to as the object hierarchy. In Visual Basic the properties
and methods of an object are accessed by hooking together the
appropriate objects through a dot operator (.) function. Each dot
operator in the object hierarchy is a function call. In many cases
it is beneficial to reduce the number of calls by setting
intermediate object variables.
Figure 2.1
Object: Car
Properties: Colour, Make, Engine Methods: Drive, Refuel2-3
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-4 Objects
ww
ThFor instance, expanding on our previous example involving the
car, suppose there existed an object called Car and you wanted
to set the value of its engine size. You could approach the
problem in one of two ways.
If the Engine size is a property you wanted to access quite often
in your code, using the indirect method of specification may be
easier as it reduces the amount of code thereby reducing the
possibility of error.
2.2.2 HYSYS Type Library
In order to do anything with objects it is first necessary to know
what objects are available. When an application is exposed for
Automation, a separate file is usually created that lists all the
objects and their respective properties and methods. This file is
called the type library and nearly all programs that support
Automation have one of these files available. With the help of an
Object Browser, such as the one built in to MS Excel, you now
have a way to view all the objects, properties, and methods in
the application by examining the type library.
The HYSYS type library reveals over 340 objects that contain
over 5000 combined properties and methods. For every object,
the type library shows its associated properties and methods.
For every property, the type library shows its return type. For
every method, the type library shows what type of arguments
are required and what type of value might be returned.
Accessing a specific property or method is accomplished in a
hierarchical fashion by following a chain of exposed objects. The
first object in the chain should be an object from which all other
objects can be accessed. This object is typically the main
application or one of the open documents. In HYSYS, the
Direct specification of object property
Car.Engine.Size = 4
Indirect specification of object property
Dim Eng1 as Object
Set Eng1 = Car.Engine.Size
Eng1 = 42-4
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-5
ww
Thstarting objects are the SimulationCase and Application objects.
All other objects are accessible through these two starting
objects.
2.2.3 Object Browser
The type library itself does not exist in a form which is
immediately viewable to you. In order to view the type library,
you require the use of an application commonly referred to as
an Object Browser. The Object Browser interprets the type
library and displays the relevant information. Microsoft Excel
and Visual Basic both include a built in Object Browser.
Accessing the Object Browser in
Excel 97/2000/XP
1. Open the Tools menu.
2. Press ALT F11 (or select the Visual Basic Editor option
from Macro group).
3. Within the Visual Basic Editor, open the Tools menu.
4. Select the References command.
5. Select the checkbox next to the HYSYS 3.X Type Library.
6. Click the OK button.
7. Open the View menu and select the Object Browser
command (or press F2).
8. Open the Libraries/Workbooks drop-down list and select
HYSYS.2-5
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-6 Objects
ww
ThNavigating Through the type Library
This section shows how to navigate through the type library in
order to determine the object hierarchy necessary to access a
particular property. Consider the desired property is the
temperature of a stream called “Feed_Stream”.
The first step is to begin with one of the starting objects. The
Application and SimulationCase objects are the starting points in
HYSYS. You can visualize what is available from the Application
object by picturing the HYSYS application view when the
program is first started. You can do the same with the
SimulationCase object by thinking of all the information
contained within a case. Nearly all the objects of interest are
accessed from the SimulationCase object.
Selecting the SimulationCase object in the browser reveals all of
its related properties and methods. Examining the list of
properties does not reveal any type of stream like object so
there must be a connection through another object. The
properties that are links to other objects can be determined by
looking at the type shown when a property is selected. If the
type shown is not a string, Boolean, variant, double, integer, or
long then it is most likely an object. The object type shown is
found somewhere in the object list and is the next step to
determining the object hierarchy.
Figure 2.22-6
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-7
ww
ThWith prior experience in HYSYS the flowsheet object is a logical
choice. Selecting the flowsheet object in the object list shows
the associated properties and methods. There is an
EnergyStreams property, a MaterialStreams property, and a
Streams property. All three of these properties are of type
Streams and are therefore objects. In this case some previous
experience in using HYSYS would suggest that MaterialStreams
is the object of interest.
The MaterialStreams object is of type Streams. Examining the
Streams object does not reveal any temperature properties. The
Streams object is a collection object, which is simply an object
that is a collection of other objects with some properties and
methods for navigating through the collection.
Figure 2.32-7
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-8 Objects
ww
ThIn this case the Streams object is a collection of ProcessStream
objects.
The individual members of a collection object can be accessed
by index number (like an array) or directly by name. Either
approach can be used through the Item property. Examining the
ProcessStream object shows a property called
TemperatureValue, which is of type Double. This is the desired
property.
Figure 2.4
Figure 2.52-8
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-9
ww
ThThe resulting syntax for the desired property is:
2.3 Automation Syntax
Declaring Objects
An object in Visual Basic is another type of variable and should
be declared. Objects can be declared using the generic type
identifier object. The preferred method however uses the type
library reference to declare the object variables by an explicit
object name.
Once a reference to the type library has been established, the
actual name of the object as it appears in the type library can be
used. This is called early binding. It offers some advantages
over late binding, including speed and access to Microsoft’s
Intellisense® functionality when using Visual Basic or VBA.
SimulationCase.Flowsheet.Streams.
Item(“Feed_Stream”).TemperatureValue
Early Binding:
Dim|Public|Private objectvar As ObjectName as specified in the type library
Late Binding:
Dim|Public|Private objectvar As Object
Example: Late Binding
Public hyCase As Object
Public hyStream As Object
Example: Early Binding
Public hyCase As SimulationCase
Public hyStream As ProcessStream2-9
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-10 Automation Syntax
ww
ThSet Keyword
Connections or references to object variables are made by using
the Set keyword.
The example below assumes hycase is set to the SimulationCase
object.
GetObject, CreateObject
In order to begin communication between the client and server
applications, an initial link to the server application must be
established. In HYSYS this is accomplished through the starting
objects: Application or SimulationCase. The typical ActiveX
object structure supplies a starting object to access the
application interface and another to access the documents
within the application.
The CreateObject function starts a new instance of the main
application. CreateObject is used in HYSYS with the
Syntax:
Set objectvar = object.[object…].object | Nothing
Example: Set
Dim hyStream As ProcessStream
Set hyStream = hyCase.Flowsheet.MaterialStreams.Item(0)
Syntax for creating an instance of an application:
CreateObject(class)
GetObject([pathname] [, class])
where:
class = the starting object as specified in the type library.
In HYSYS there are two objects that can be used for
the class statement: HYSYS.Application or
HYSYS.SimulationCase.2-10
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-11
ww
ThHYSYS.Application class as specified in the type library. This
connects to the main application interface of HYSYS.
The GetObject function opens a specific document in the
currently running instance of the server application. If the
application is not running then a new instance of the application
starts. If a specific document is not specified with the GetObject
function the current instance of the application is connected or a
new instance of the application is started.
For application objects or document objects the codes are shown
below:
In the example below, hyCase is declared as type object so it is
using late binding. The hyCase variable is connected to a HYSYS
case by using the GetObject function and the Set keyword. The
second argument in the GetObject function is the starting
object.
The second example is identical to the first except that the
object variable hyCase is declared using the actual object name
as it appears in the type library. This assumes that a reference
to the type library has already been set.
Example: CreateObject and GetObject
Set applicationobj = CreateObject(“HYSYS.Application”)
or
Set applicationobj = GetObject(, “PROGRAM.Application”)
Set documentobj = GetObject(“c:\filepath”, “PROGRAM.Document”)
Example 1: Starting a HYSYS case through Automation
Dim hyCase As Object
Set hyCase = GetObject(“c:\samples\c-2.hsc”, “HYSYS.SimulationCase”)
Example 2: Starting a HYSYS case through Automation
Dim hyCase As SimulationCase
Set hyCase = GetObject(“c:\samples\c-2.hsc”, “HYSYS.SimulationCase”)2-11
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-12 Automation Syntax
ww
ThThe third example uses early binding in the object declaration.
The CreateObject command is used to bring up an instance of
HYSYS. The starting object here is the HYSYS.Application object
since a case is not initially being opened. The SimulationCases
object is accessed through the Application object and the Open
method of SimulationCases is used to bring up a specific HYSYS
case. The hyCase object is set to the active case through the
ActiveDocument property of hyApp.
Object Properties, Methods, &
Hierarchy
The sequence of objects is set through a special dot function.
Properties and methods for an object are also accessed through
the dot function. It is preferable to keep the sequence of objects
to a minimum since each dot function is a call to link between
the client and the server application.
The object hierarchy is an important and fundamental concept
for utilizing Automation. A particular property can only be
accessed by following a specific chain of objects. The chain
always begins with either the Application or SimulationCase
object and ends with the object containing the desired property.
Example 3: Starting a HYSYS case through Automation
Dim hyCase As SimulationCase
Dim hyApp As HYSYS.Application
Set hyApp = CreateObject(“HYSYS.Application”)
hyApp.SimulationCases.Open(“c:\HYSYS\samples\c-2.hsc”)
Set hyCase = hyApp.ActiveDocument
Syntax for setting objects and accessing properties:
Set objectvar = object.[object.object...].object
Variable = object.[object.object...].property
Syntax for accessing methods:
Function Method
returnvalue = object.method([argument1, argument2,...])
Sub-routine Method
object.method argument1, argument22-12
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-13
ww
ThThe methods of an object are accessed in the same fashion as
properties by utilizing the dot function. A method for a particular
object is nothing more then a function or sub-routine whose
behaviour is related to the object in some fashion.
Typically the methods of an object require arguments to be
passed when the method is called. The type library provides
information about which arguments are necessary to call a
particular method. A function returns a value.
The example below, starts up HYSYS and opens a specific case.
The temperature value of a specific stream is then obtained. The
temperature value is obtained through a connection of three
objects: SimulationCase, Flowsheet, and MaterialStreams.
The example below, also accesses the temperature value of a
specific stream but creates some intermediate objects so that
when the temperature value is actually requested the chain of
objects only contains one object.
Sub-routines in Visual Basic do not require parentheses
around the argument list.
Example 1: Accessing HYSYS object properties
Dim hyCase As SimulationCase
Dim TempVal As Double
Set hyCase = GetObject(“c:\c-2.hsc”,”HYSYS.SimulationCase”)
TempVal = hyCase.Flowsheet.MaterialStreams.Item(0).TemperatureValue
MsgBox TempVal
Example 2: Accessing HYSYS object properties
Dim hyCase As SimulationCase
Dim hyFlowsheet As Flowsheet
Dim hyStream As ProcessStream
Dim TempVal As Double
Set hyCase = GetObject(“c:\samples\c-2.hsc”, “HYSYS.SimulationCase”)
Set hyFlowsheet = hyCase.Flowsheet
Set hyStream = hyCase.Flowsheet.MaterialStreams.Item(0)
TempVal = hyStream.TemperatureValue
MsgBox TempVal2-13
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-14 Automation Syntax
ww
ThCollection Objects
A collection object is an object that contains a set of other
objects. This is similar to an array of objects. The difference
between an array of objects and a collection object is that a
collection object contains a set of properties and methods for
navigating and manipulating the objects in the collection.
The most commonly used properties are:
• Index. The Index property takes in a name and returns
a number value associated with the object’s name.
• Item. The Item property takes an index value or name
or integer number as the argument and returns a
reference to the object within the collection.
• Count. The Count property returns the number of items
in the collection.
A special type of For loop, called For Each, is available for
enumerating through the objects within the collection. The For
Each loop provides a means for enumerating through the
collection without explicitly specifying how many items are in
the collection. This helps avoid having to make additional
function calls to the Count and Item properties of the collection
object in order to perform the same type of loop.
Syntax: Typical Properties of a Collections Object
Item(index) Accesses a particular member of the collection by
number.
Index(name) Determines the index number for a member in
the collection by its name.
Count Returns the number of objects in the collection.
Syntax: Enumeration of Objects
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]2-14
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-15
ww
ThThe example below, connects to a collection of streams by
setting the hyStreams object. A For loop is created that uses the
Count and Item properties of a collection in order to display a
property view that contains the stream name. The items in the
collection are indexed beginning with 0. The Count property
returns the actual number of objects in the collection so it is
necessary to subtract one in order to access all the objects in
the collection.
The example below, is identical to the first example except that
a For Each loop is used instead of the standard For loop in order
to enumerate through the Streams collection.
Variants
A property can return a variety of variable types. Values such as
temperature and pressure are returned as doubles or 32-bit
floating-point values. The stream name property returns a string
value. Visual Basic provides an additional variable called a
variant. A variant is a variable that can take on the form of any
type of variable including, Integers, Double, String, Array, and
Objects.
Example 1: Accessing Collection Objects
Dim hyStreams As Streams
Dim hyStream As ProcessStream
Set hyStreams = hyCase.Flowsheet.MaterialStreams
For j = 0 To hyStreams.Count - 1
MsgBox hyStreams.Item(j).name
Next j
Example 2: Accessing Collection Objects
Dim hyStreams As Streams
Dim hyStream As ProcessStream
Set hyStreams = hyCase.Flowsheet.MaterialStreams
For Each hyStream In hyStreams
MsgBox hyStream.name
Next hyStream2-15
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-16 Automation Syntax
ww
ThIf the property of an object returns an array whose size can vary
depending upon the case, then a variant is used to access that
value. For example, the ComponentMassFractionValue property
of a ProcessStream returns an array of doubles sized to the
number of components associated with that stream.
In Visual Basic, if a variable is not explicitly declared then it is
implicitly a variant. Variants have considerably more storage
associated with their use, so for a large application it is good
practice to limit the number of variants being used. It is also just
good programming practice to explicitly declare variables
whenever possible.
The dimensions of the array depend upon what property is being
called. The following table lists the most common properties
that return arrays and what is the dimension of the array.
The example below, shows how to get an array of stage
pressures in a column.
The hyOp object is declared as a ColumnOp as specified in
the type library. The operations collection is filtered to only
include columns by using the word “ColumnOp”. HyOp is set
to the first column in the operations collection.
HyStagePressure is set equal to an array of doubles returned
by the ColumnOp object. Since the number of stages in this
column may not be known the Ubound function is used to
Common Variant of HYSYS Returning Property
Component Mass Fractions One Dimensional array
Column Component Fraction Values Two Dimensional array
Interaction Parameters Two Dimensional array
Example 1: Using Variants in HYSYS
Dim hyOp As ColumnOp
Dim hyStagePressure As Variant
Set hyOp = hyCase.Flowsheet.Operations(“ColumnOp”).Item(0)
hyStagePressure = hyOp.PressureValues
For j = 0 To UBound(hyStagePressure)
MsgBox “Stage “ & j +1 & “ Pressure = “ & hyStagePressure(j)
Next j2-16
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-17
ww
Thdetermine the upper bound of the one dimensional array. A
property view prints out the pressure value for each stage in
the column.
The example below, accesses the VapourComponentFraction
property of a column.
The array is set to hyStageCompFrac. This array is two-
dimensional. The first dimension represents the components
in the systems as specified in the fluid package. The second
dimension represents the stages in the column. A property
view displays the vapour fraction of component 1 for each
stage of the column.
2.4 Key HYSYS Objects
2.4.1 HYSYS Object Overview
There are over 340 automation objects exposed in HYSYS.
These objects collectively contain of over 5000 properties and
methods. One of the more time consuming and difficult tasks in
learning to use Automation objects is determining what objects
are available and how to get at a property of interest.
The following sub-sections are designed to explore key HYSYS
objects in more detail and hopefully provide the necessary
information required to access nearly any object, property, or
method in HYSYS. Because of the large number of key objects
and their attributes, the objects within HYSYS have been divided
Example 2: Using Variants in HYSYS
Dim hyOp As ColumnOp
Dim hyStageCompFrac As Variant
Set hyOp = hyCase.Flowsheet.Operations(“ColumnOp”).Item(0)
hyStageCompFrac = hyOp.VapourComponentFraction
For j = 0 To UBound(hyStageCompFrac,2)
MsgBox “Stage “ & j +1 & “ Component 1 Vapour Fraction = “ &
hyStageCompFrac(0,j)
Next j2-17
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-18 Key HYSYS Objects
ww
Thin seven distinct categories. These object categories are:
Container Objects, Support Objects, Oil Objects, Basis Objects,
Stream Objects, Operation Objects, Extension Objects, and PFD
Objects.
2.4.2 Container Objects
This category refers to objects that house other objects or form
the basis from which a large number of objects are derived. For
instance, the Application object can contain several
SimulationCase objects. The SimulationCase object contains all
the remaining objects associated with that case. The flowsheet
object is a repository for all the streams and unit operations of
the case. The flowsheet can also contain another flowsheet,
Application or SimulationCase.
Application and SimulationCase
The Application object is the top most object in HYSYS and
represents the HYSYS program itself. From the Application
object, nearly all the objects listed in the HYSYS type library can
be accessed. The SimulationCase object is the starting object for
accessing or opening specific simulation cases.
Syntax: Connecting to the Application
Set hyApp = CreateObject(“HYSYS.Application”)
Syntax: Connecting to the Simulation Case
Through GetObject
Set hyCase = GetObject(“filepath”, “HYSYS.SimulationCase”)
Through the Application Object
Set hyCase = hyApp.ActiveDocument
Through SimulationCases Collection Object
Set hyCase = hyApp.SimulationCases.Item(“CaseName”)2-18
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-19
ww
ThUsing GetObject and CreateObject
The SimulationCase object and the Application object can be
created directly through the GetObject function in Visual Basic.
The CreateObject function can also be used to access the
Application object. In general the starting object for most
Automation procedures is the SimulationCase object.
The example below, uses the GetObject function to start-up
HYSYS with the specified case.
The example below, connects to the HYSYS Application object
and enumerates through all the currently open cases. If a case
name matches the specified string then a SimulationCase object
is set to that case. The FOR loop cycles through the list of cases
based on the count value. In Visual Basic arrays and collections
are base 0 unless otherwise specified.
Example 1: Accessing the HYSYS Container Objects
Dim hyCase As SimulationCase
Set hyCase = GetObject(“c:\hysys\cases\c-2.hsc”, “HYSYS.SimulationCase”)
Example 2: Accessing the HYSYS Container Objects
Dim hyApp As HYSYS.Application
Dim hyCases As SimulationCases
Dim hyCase As SimulationCase
Set hyApp = CreateObject(“HYSYS.Application”)
Set hyCases = hyApp.SimulationCases
For j = 0 To hycases.Count - 1
If hycases.Item(j).name = “ethanol.hsc” Then
Set hyCase = hyCases.Item(j)
End If
Next j2-19
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-20 Key HYSYS Objects
ww
ThStarting a Particular Version of HYSYS
To start a particular version of HYSYS via OLE, use one of the
following HYSYS.Application ProgIDs.
Some ProgIDs activate the most currently registered version of
HYSYS. HYSYS versions 2004.2 and earlier register
automatically each time they run. However, HYSYS 2006
registers only at installation. You can manually register and un-
register HYSYS 2006 using the following commands:
HYSYS /regserver
HYSYS /unregserver
You can also re-register HYSYS 2006 by selecting the Restore
File Associations item in the HYSYS 2006 group on the Start
menu.
If you open a case using GetObject (“casename.hcs”), the case
will open with the version of HYSYS that was last registered.
ProgID Description
HYSYS.Application Activates the most currently registered
version of HYSYS. For example, if HYSYS
2004.2 is started up after HYSYS 2006 is
installed, HYSYS 2004.2 will be activated.
Note: HYSYS versions 2004.2 and earlier
register automatically each time they run.
HYSYS.Application.2006 Activates HYSYS 2006 as long as it is
registered.
HYSYS.Application.Latest Activates the latest version of HYSYS that is
registered.
HYSYS.Application.3.0 Activates HYSYS 2004.2 or earlier version,
whichever is registered.
HYSYS.Application.NewInstance Starts a new instance of the most currently
registered version of HYSYS. For example, if
HYSYS 2004.2 is started up after HYSYS 2006
is installed, HYSYS 2004.2 will be activated.
Note: HYSYS versions 2004.2 and earlier
register automatically each time they run.
HYSYS.Application.NewInstance.2006 Starts a new instance of HYSYS 2006 as long
as it is registered.
HYSYS.Application.NewInstance.Latest Starts a new instance of the latest version of
HYSYS that is registered.
HYSYS.Application.NewInstance3.0 Starts a new instance of HYSYS 2004.2 or
earlier version, whichever is registered.2-20
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-21
ww
ThVB6 supports an additional parameter for GetObject that allows
the case to be open in the version specified. For example, this
code would open the case in HYSYS 2006:
GetObject (“case.hsc”, “HYSYS.SimulationCase.2006”)
Flowsheet(s)
The main flowsheet object is accessed through the
SimulationCase object. The flowsheet object is a container of all
the ProcessStream and Operations objects as well as a link to
the FluidPackage object associated with that flowsheet. Each
flowsheet and sub-flowsheet can have its own fluid package and
likewise its own property package and set of components. Sub-
flowsheets can be accessed from the main flowsheet object
through the flowsheet collection object.
The above syntax, shows how to connect to the flowsheet object
of the HYSYS case. This assumes the hyCase variable is already
set to the SimulationCase object in HYSYS. The remaining
examples in this module assume a SimulationCase object
'hyCase' is already set.
The example below, shows how to connect to a sub-flowsheet of
a flowsheet. Sub-flowsheets are accessed from the main
flowsheet. The main flowsheet is accessed through the
SimulationCase.
Syntax: Flowsheet Object
Dim hyFlowsheet As Flowsheet
Set hyFlowsheet = hyCase.Flowsheet
Example: Connecting Flowsheets
Dim hyFlowsheet As Flowsheet
Dim hySubFlowsheets As Flowsheets
Dim hySubFlowsheet As Flowsheet
Set hyFlowsheet = hyCase.Flowsheet
Set hySubFlowsheets = hyFlowsheet.Flowsheets
Set hySubFlowsheet = hySubFlowsheets.Item(0)2-21
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-22 Key HYSYS Objects
ww
Th2.4.3 Basis Objects
The Basis objects refer predominantly to objects handled by the
HYSYS BasisManager. The BasisManager object in HYSYS is
responsible for handling the global aspects of a HYSYS
simulation case. These objects include reactions, components,
and property packages.
The BasisManager object is accessed through the
SimulationCase object. From the BasisManager object the
FluidPackages and HypoGroups collection objects are accessed.
Changing the objects accessed directly or indirectly through the
BasisManager such as FluidPackages, PropertyPackage,
Components, and Hypotheticals requires notification to the
HYSYS simulation environment. The BasisManager object
contains methods that allow changes to the basis to take place
smoothly. The following methods must be used on the outer
limits of any code that makes changes to Basis objects.
FluidPackage(s)
Although both examples of syntax shown below lead you to a
FluidPackage object, there are differences that exist which are
only apparent when attempting to use the fluid package.
The FluidPackages object returned by the BasisManager object
is a collection object containing all FluidPackage objects in a
case. Each FluidPackage object can have its own
Syntax: Changing Basis Values
SimulationCase.BasisManager.StartBasisChange
... changes to components, interaction parameters, reactions, etc.
SimulationCase.BasisManager.EndBasisChange
Syntax: Accessing FluidPackages
From the BasisManager
SimulationCase.BasisManager.FluidPackages.Item(0)
From the Flowsheet
SimulationCase.Flowsheet.FluidPackage2-22
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-23
ww
ThPropertyPackage object and Components object. When you
access the fluid package in this way, changes can be made to
the property package and the list of components.
When obtaining a reference to the FluidPackage object from the
flowsheet object, you are accessing the one fluid package
associated with the flowsheet. You can view the property
package or component list of the FluidPackage object, however
you are not able to make any changes.
The example below, displays the number of FluidPackage
objects in a case and sets a FluidPackage object to the first
member of the FluidPackages collection.
PropPackage (PropertyPackage)
The PropPackage object is accessed through the FluidPackage
object. Each FluidPackage object can have a single PropPackage
object. The type of property package can be determined through
the PropPackage TypeName property or through the
PropertyPackageName property of the FluidPackage object. Each
property package has a set of unique properties and methods
along with the common ones shared among all property
packages.
Example: FluidPackage
Dim hyFluidPackages As FluidPackages
Dim hyFluidPackage As FluidPackage
Set hyFluidPackages = hyCase.BasisManager.FluidPackages
MsgBox “Number of Fluid Packages = “ & hyFluidPackages.Count
Set hyFluidPackage = hyFluidPackages.Item(0)
Syntax to determine the type of property package
SimulationCase.BasisManager.Fluidpackages.Item(0).PropPackage.TypeName
or
SimulationCase.BasisManager.Fluidpackages.Item(0).PropertyPackageName2-23
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-24 Key HYSYS Objects
ww
ThThe example below, connects to the FluidPackages collection
object and checks each member FluidPackage to see if it
contains the PengRobinson property package.
Component(s)
The Components object is accessed through the FluidPackage
object. Each FluidPackage can have its own unique set of
Components.
Example: Property Package
Dim hyFluidPackages As FluidPackages
Dim hyFluidPackage As FluidPackage
Dim hyBasis As BasisManager
Dim hyPropPackage As PropPackage
Set hyBasis = hyCase.BasisManager
Set hyFluidPackages = hyBasis.FluidPackages
For Each hyFluidPackage In hyFluidPackages
If hyFluidPackage.PropertyPackageName = “PengRobinson” Then
MsgBox “PengRobinson Property Package is Present”
Set hyPropPackage = hyFluidPackage.PropPackage
End If
Next hyFluidPackage
Syntax for accessing components
From the BasisManager
SimulationCase.BasisManager.FluidPackages.Item(0).Components
From the Flowsheet
SimulationCase.Flowsheet.Components2-24
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-25
ww
ThThe example below, shows how to access the Components
object associated with a particular FluidPackage object. In this
example each component's normal boiling point is checked and
a tally of all the components whose boiling point is below 0°C is
counted.
Hypotheticals
The HypoGroups collection object is accessed from the
BasisManager. This object contains a collection of HypoGroup
objects, each of which provides access to a HypoComponents
object. A HypoComponent can be entirely specified through
Automation and added to a HYSYS simulation case. Methods for
the HypoComponent object are used to estimate properties
based on the minimum data requirement.
Example: Components
Dim numComp As Integer
Dim hyFluidPackage As FluidPackage
Dim hyBasis As BasisManager
Dim hyComponents As Components
Dim hyComponent As Component
Set hyBasis = hyCase.BasisManager
Set hyFluidPackage = hyBasis.FluidPackages.Item(0)
Set hyComponents = hyFluidPackage.Components
numComp = 0
For Each hyComponent In hyComponents
If hyComponent.NormalBoilingPointValue < 0 Then
numComp = numComp + 1
End If
Next hyComponent
MsgBox numComp & “ components have NBP below 0"
Syntax: Hypotheticals
SimulationCase.BasisManager.HypoGroups.Item(0).HypoComponents.Item(0)2-25
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-26 Key HYSYS Objects
ww
ThThe example below, adds a hypothetical component and sets its
boiling point value in order to estimate the remaining properties.
The StartBasisChange and EndBasisChange methods are
invoked prior to adding this hypothetical to the case.
Hypotheticals have a * appended to the name once they are
created.
2.4.4 Oils Objects
Oils objects refer to the objects accessed through the Oil
Manager. The OilManager object is set through the
BasisManager and contains Assay and Blend objects.
OilManager
Set through the BasisManager, the OilManager object provides
access to the oils environment. Like changes made to the
objects accessed through the BasisManager, notification to the
simulation environment is required when modifying assays or
blends. This is accomplished by calling the StartOilChange and
EndOilChange methods. Calling the StartOilChange method
before calling the StartBasisChange method by default causes
the StartBasisChange method to be invoked.
Example: HypoComponent
Dim hypGroups As HypoGroups
Dim hypoComp As Object
hyCase.BasisManager.StartBasisChange
Set hypGroups = hyCase.BasisManager.HypoGroups
hypGroups.Add “myhypo”
hypGroups.Item(“myhypo”).HypoComponents.Add “mycomponent”, “userhypo”
Set hypoComp =
hypGroups.Item(“myhypo”).HypoComponents.Item(“mycomponent*”)
hypoComp.NormalBoilingPointValue = 300
hypoComp.Estimate
MsgBox hypoComp.NormalBoilingPointValue
hyCase.BasisManager.EndBasisChange2-26
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-27
ww
Th
Assays and Blends are not estimated until the EndOilChange
method is invoked.
AssaysCollection & Assays
The AssaysCollection object is accessed through the OilManager
object and contains the assay objects available within a
particular HYSYS case. There are eight types of assays available
and each of them has a specific set of properties and methods.
The properties associated with the hypocomponents generated
by the OilManager can be accessed through the Assay object.
Example: Accessing the Oil Manager Environment
Public hyOil As OilManager
hyCase.BasisManager.StartBasisChange
hyCase.BasisManager.StartOilChange
Set hyOil = hyCase.BasisManager.OilManager
'//code to manipulate oil manager objects
hyCase.BasisManager.EndOilChange
hyCase.BasisManager.EndBasisChange
AssayTypes:
• at_ASTMD2887 = 4
• at_BulkPropertiesOnly = 7
• at_Chromatograph = 5
• at_D1160 = 2
• at_D86 = 1
• at_D86D1160 = 3
• at_EFV = 6
• at_TBP = 0
Syntax: Assays
Referencing a Collection
Set hyAssays = hyCase.BasisManager.OilManager.Assays
Referencing a Member
Set hyAssay = hyCase.BasisManager.OilManager.Assays.Item(“name”)
Adding an Assay
hyCase.BasisManager.OilManager.Assays.Add “name”, AssayType2-27
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-28 Key HYSYS Objects
ww
ThBelow is an example on creating an assay.
Blend(s)
Blends are created through the BasisManager and can be
completed by specifying at least one assay. Multiple assays can
be used in a blend as long as flow rates for each of the assays is
specified. A large number of blend properties for the
hypocomponents created can be viewed.
Example: Creating Assays
Dim hyAssay As AssayTBP
Dim hyBasis As BasisManager
Set hyAssay = hyBasis.OilManager.Assays.Add(“AssayName”, “TBP”)
With hyAssay
.Basis = ab_LiquidVolumeFraction
.BulkMolecularWeight = 300
.BulkMassDensity.SetValue 783, “API”
Dim hyValue As Variant
Dim hyPercent As Variant
hyPercent = Array(0,10,20,30,40,50,60,70,80,90,98)
hyValue =
Array(26.67,123.89,176.11,221.11,275,335,399,490.56,590.56,691.67,
795.56)
.AssayPercentForBoilingTemperature = hyPercent
.BoilingTemperatureValue = hyValue
.Calculate
End With
Syntax for Blends
Referencing a Collection
Set hyBlends = hyCase.BasisManager.OilManager.Blends
Referencing a Member
Set hyBlend = hyCase.BasisManager.OilManager.Blend.Item(“blendname”)
Adding Assay to Blend
HyBlend.AddAssay “AssayName”
Installing to a ProcessStream
hyBlend.InstallIntoStream “StreamName”2-28
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-29
ww
ThThe example below, creates a blend, assigns one assay to the
blend, and then prints out the TBP values for the blend. The
blend is also assigned to a stream in the HYSYS case.
2.4.5 Stream Objects
The main objects of the stream category are the ProcessStream
and Fluid objects. The Fluid object is a type of Stream object
that is not connected to operations but can be derived from a
ProcessStream. The Fluid object can be manipulated without
effecting the operations and streams within the case. The
ProcessStream object can be accessed from either the flowsheet
or the operation to which it is connected.
ProcessStream
The Streams object is a collection object returned by the
flowsheet. The Streams collection contains one or more
ProcessStream objects. There are approximately 124 properties
associated with the ProcessStream, including attributes such as
temperature, pressure, density, and viscosity. These properties
return values of type Double. The ProcessStream object also
returns arrays as variants for properties such as
ComponentMassFraction.
Example: Blends
Dim hyBlend As Blend
'//create blend and assign assay
Set hyBlend = hyBasis.OilManager.Blends.Add(“BlendName”)
hyBlend.AddAssay “AssayName”
'//print out some properties
Dim hyVar As Variant
hyvar = hyBlend.TrueBPTemperatureValue
For i = 0 To UBound(hyVar)
Debug.Print hyVar(i)
Next i
hyBlend.InstallIntoStream “Blend_Stream”2-29
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-30 Key HYSYS Objects
ww
ThThe Fluid object contains a similar set of properties and
methods.
In most instances the collection object and member object of
the collection have nearly similar names. The name of the
collection object is normally the member name with an “s” at
the end. The Streams collection is an exception to this
statement, since it contains a collection of ProcessStream
objects. The flowsheet returns three stream collections;
MaterialStreams, EnergyStreams, and Streams. All three stream
collections accessed through the flowsheet are Streams objects.
The difference between the Streams collection objects relates to
how the member ProcessStream objects are filtered.
The example below, shows how to access a particular stream in
the system by index and how to retrieve the temperature value.
The remaining properties are accessed in a similar fashion.
Syntax for accessing the ProcessStream object
By Name
SimulationCase.Flowsheet.MaterialStreams(“streamname”)
SimulationCase.Flowsheet.MaterialStreams.Item(“streamname”)
By Index
SimulationCase.Flowsheet.MaterialStreams.Item(j)
Example 1: ProcessStream
Dim hyFlowsheet As Object
Dim hyStream As Object
Set hyFlowsheet = hyCase.Flowsheet
Set hyStream = hyFlowsheet.MaterialStreams.Item(0)
MsgBox “Stream Temperature = “ & hyStream.TemperatureValue2-30
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-31
ww
ThThe example below, shows how to access the MassFractionValue
for each component in the stream. An array of doubles is
returned to the variant hyCompFrac. The Ubound function is
used to determine the upper bound of the array and thus the
number of components. A separate object is set for the
component collection. The indexing between the array of mass
fractions and the list of components in the FluidPackage is
identical so it is easy enough to match the values with the
appropriate components.
Fluid
A Fluid object is derived from a single ProcessStream through
the DuplicateFluid method. A Fluid object is essentially an
internal copy of the ProcessStream that can be manipulated for
property calculation purposes. The ProcessStream and Fluid
share many of the same properties. A Fluid however can be
flashed without interfering with the simulation case.
Example 2: ProcessStream
Dim hyFlowsheet As Flowsheet
Dim hyStream As ProcessStream
Dim hyComponents As Components
Dim hyCompFrac As Variant
Set hyFlowsheet = hyCase.Flowsheet
Set hyComponents = hyCase.BasisManager.FluidPackages.Item(0).Components
Set hyStream = hyFlowsheet.MaterialStreams.Item(2)
hyCompFrac = hyStream.ComponentMassFractionValue
For j = 0 To UBound(hyCompFrac)
MsgBox “Component “ & hyComponents.Item(j) & “ Mass Fraction = “ &
hyCompFrac(j)
Next j
Syntax for creating a fluid
SimulationCase.Flowsheet.MaterialStreams(“streamname”).DuplicateFluid2-31
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-32 Key HYSYS Objects
ww
ThThe example below, shows how to create a Fluid off of a stream
and use the Fluid to perform a flash calculation. The
DuplicateFluid method returns a Fluid object. A variety of flashes
could have been performed, but in this case a pressure-vapour
fraction flash is run with the desired pressure and vapour
fraction used as arguments to the method.
FluidPhase(s)
The FluidPhases collection object is derived from the Fluid
object. Each FluidPhase in the collection contains a set of
properties and methods that are similar to the Fluid itself except
that the properties correspond to a specific phase of the Fluid.
Example: Fluid
Public Sub FluidExample(pressureval As Double)
Dim hyFluid As Fluid
Dim hyStream As ProcessStream
Set hyStream = hyCase.Flowsheet.MaterialStreams.Item(0)
Set hyFluid = hyStream.DuplicateFluid
hyFluid.PVFlash pressureval, 0
MsgBox “Bubble Point Temperature = “ & hyFluid.TemperatureValue
End Sub
PhaseTypes (constants):
• ptUnknownPhase
• ptCombinedLiquidPhase
• ptCombinedPhase
• ptLiquid2Phase
• ptLiquidPhase
• ptPolymerPhase
• ptSolidPhase
• ptVapourPhase2-32
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-33
ww
ThThe PhaseType property of the FluidPhase objects can be
accessed to determine the type of phase.
The example below, enumerates through the FluidPhases of a
Fluid and displays the phase type for each fluid in a property
view.
2.4.6 Operation Objects
A majority of the unit operations in HYSYS are accessible as
Automation objects. Operations can be accessed through the
flowsheet object. Each operation typically has a characteristic
set of properties and methods.
Syntax: FluidPhase(s)
Through Collection
Set hyFluidPhase = hyFluid.FluidPhases.Item(0)
HeavyLiquidPhase
Set hyFluidPhase = hyFluid.HeavyLiquidPhase
LightLiquidPhase
Set hyFluidPhase = hyFluid.LightLiquidPhase
VapourPhase
Set hyFluidPhase = hyFluid.VapourPhase
Example: FluidPhase
Dim i As Integer
Dim hyCase As SimulationCase
Dim hyfluid As Fluid
Dim hystream As ProcessStream
Dim hyPhase As FluidPhase
Dim hyPhases As FluidPhases
Set hystream = hyCase.Flowsheet.MaterialStreams.Item(0)
Set hyfluid = hystream.DuplicateFluid
Set hyPhases = hyfluid.FluidPhases
i = 1
For Each hyPhase In hyPhases
If hyPhase.PhaseType = ptVapourPhase Then
MsgBox “Phase “ & i & “ is the vapour phase”
i = i + 1
End If
Next2-33
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-34 Key HYSYS Objects
ww
ThOperations
All operations have a few properties and methods in common.
Operation objects contain properties for determining the feeds,
products, and additional objects connected to the operation. The
operation objects also contain methods for adding and removing
the operations from the flowsheet and the HYSYS case.
The Operations collection object obtained from the flowsheet
returns a collection of all the operations on that flowsheet. It is
possible to filter the collection of operations returned by
specifying the operation type. It is important to note however
that the operations object always returns a collection and not an
individual operation. The objects in the collection need to be
checked in order to find a specific type of operation.
The example below, enumerates through all the operations on
the flowsheet and displays the unit type in a property view.
Syntax for accessing operations
Getting all the operations on the flowsheet
SimulationCase.Flowsheet.Operations
Getting a specific collection of operations
SimulationCase.Flowsheet.Operations(“PumpOp”)
Getting to a specific operation by name
SimulationCase.Flowsheet.Operations.Item(“UnitName”)
Determining the type of operation
SimulationCase.Flowsheet.Operations.Item(0).TaggedName
Example: Operation
Dim i As Integer
Dim hyOperations As Operations
Set hyOperations = hyCase.Flowsheet.Operations
For i = 0 To hyOperations.Count - 1
MsgBox “Operation “ & hyOperations.Item(i).name & “
is unit type - & hyOperations.Item(i).TypeName
Next i2-34
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-35
ww
ThColumnOp & ColumnFlowsheet
The column operation is a special kind of operation in HYSYS
and actually contains its own flowsheet. The ColumnFlowsheet is
accessed either from the Columnop object or as a member of
the flowsheets object accessed through the main flowsheet. In
order to access the various temperatures, pressures, and
specifications for a column the ColumnFlowsheet must be
accessed.
The ColumnFlowsheet object contains a considerable amount of
information regarding the column. A variant is used to receive
an array of column pressure information and displays a stage by
stage breakdown of the pressure values.
Syntax: Accessing Columns
Set objColumn = SimulationCase.Flowsheet.Operations(“ColumnOp”).Item(0)
Set objColumnSubFlow = objColumn.ColumnFlowsheet
Example: Column Operation
Dim hyColumn As ColumnOp
Dim hyColumnSubFlowsheet As ColumnFlowsheet
Dim Pressure_Profile As Variant
Set hyColumn = hyCase.Flowsheet.Operations(“ColumnOp”).Item(0)
Set hyColumnSubFlowsheet = hyColumn.ColumnFlowsheet
Pressure_Profile = hyColumnSubFlowsheet.Pressures
For i = 0 To UBound(Pressure_Profile)
MsgBox “Stage “ & i + 1 & “ pressure = “ & Pressure_Profile(i)
Next i2-35
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-36 Key HYSYS Objects
ww
ThColumnSpecification(s)
A column is solved based on matching specifications related to
the available degrees of freedom. The ColumnSpecifications
collection object is accessed through the ColumnFlowsheet. The
ColumnSpecification contains information such as the goal
value, current value, and status.
The example below, enumerates through all the column
specifications and displays in a property view whether the
specification is active or an estimate.
Syntax: ColumnSpecification
Set hyColumn = hyCase.Flowsheet.Operations(“ColumnOp”).Item(0)
Set hyColumnFlowsheet = hyColumn.ColumnFlowsheet
By Index:
Set hyColumnSpec = hyColumnFlowsheet. Specifications.Item(0)
By name:
Set hyColumnSpec = hyColumnFlowsheet.Specifications.Item(“specname”)
Example: ColumnSpecification
Dim hyColumnSpec As ColumnSpecification
Dim hyColumnSpecs As ColumnSpecifications
Dim hyColumn As ColumnOp
Dim hyColumnFlowsheet As ColumnFlowsheet
Set hyColumn = hyCase.Flowsheet.Operations(“ColumnOp”).Item(1)
Set hyColumnFlowsheet = hyColumn.ColumnFlowsheet
Set hyColumnSpecs = hyColumnFlowsheet.Specifications
For Each hyColumnSpec In hyColumnSpecs
If hyColumnSpec.IsActive Then
MsgBox “Column spec '" & hyColumnSpec & “' is active.”
Else
MsgBox “Column spec '" & hyColumnSpec & “' is an estimate.”
End If
Next hyColumnSpec2-36
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-37
ww
ThColumnStage(s) & SeparationStage
The ColumnStages object is a collection of ColumnStage objects
accessed through ColumnFlowsheet. SeparationStage is an
object of ColumnStage and provides a variety of properties
related to the fluids residing on a particular column stage.
The example below, loops through each feed stage and displays
in the Debug property view its molar liquid flows.
2.4.7 Support Objects
Support objects are used primarily to perform a function or
service to an object in HYSYS. Support objects may not have a
visible equivalent in a HYSYS case when viewed within the
simulation environment. The support objects can be accessed by
several of the objects in HYSYS. The two most commonly
Syntax: ColumnStage(s)
By Index:
Set hyColumnStage = hyColumnFlowsheet.ColumnStages.Item(0)
By Name:
Set hyColumnStage = hyColumnFlowsheet.ColumnStages.Item(“1_Main TS”)
Syntax: SeparationStage
Set hySepStage = hyColumnStage.SeparationStage
Example: ColumnStage
Dim hyColumn As ColumnOp
Dim hyColumnFlowsheet As ColumnFlowsheet
Dim hyFeedStage As Object
Dim hySepStage As SeparationStage
Set hyColumn = hyCase.Flowsheet.Operations(“ColumnOp”).Item(0)
With hyColumn.ColumnFlowsheet
For Each hyFeedStage In .FeedStages
Debug.Print “Stage “ &.ColumnStages(hyFeedStage.name)
StageNumberValue & “ Molar Liquid Flow (kgmole/hr) is “
&.ColumnStages(hyFeedStage.name).
SeparationStage.MolarLiquidFlowValue
Next hyFeedStage
End With2-37
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-38 Key HYSYS Objects
ww
Thaccessed objects in this category are FixedAttachments and
RealVariable.
RealVariable/RealFlexVariable
The RealVariable object provides additional information about a
particular variable such as its units and whether it is calculated
or set. HYSYS performs all calculations in SI units regardless of
how the user preference settings are set. By default, the values
returned through Automation are also in SI units. It becomes
your responsibility to handle how units are handled when writing
applications.
A RealVariable contains a property called GetValue and SetValue
which allows one to specify the units that are to be used when
returning or setting the value.
The RealVariable object also contains a property called Value.
The Value property returns the actual value in SI units within
the HYSYS case. Many of the objects that return a RealVariable
for a given property also have a similarly named property with
the word value concatenated to it. The alternative property
allows direct access to the actual variable in SI units with one
less function call. An example for the ProcessStream object
would be the Temperature property that returns a RealVariable
and the TemperatureValue property, that returns a value in °C.
Syntax for using RealVariable
SimulationCase.Flowsheet.MaterialStreams.Item(0).property
RealVariable Properties/Methods
GetValue Gets the value in a specified unit.
SetValue Sets the value in a specified unit.
Status Returns calculated or specified
Value Value in SI units.2-38
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-39
ww
ThThe RealFlexVariable contains roughly the same properties and
methods as the RealVariable but is used for array values
returned to variants.
The presence of Flex in the object name indicates the
possibility of a dynamic array (in other words, has a
variable size, depending on what is being returned.)
The example below, shows how to get a stream property value
in a specific unit using the RealVariable method GetValue.
The example below, shows how to set a stream property value
in a specific unit using the RealVariable method SetValue.
The example below, checks how the temperature value of a
stream is determined by examining the state property.
Example 1: RealVariable
Dim hyStream As ProcessStream
Dim TemperatureVal As Double
Set hyStream = hyCase.Flowsheet.MaterialStreams.Item(0)
TemperatureVal = hyStream.Temperature.GetValue(“F”)
MsgBox hyStream.name & “ temperature(F) = “ & TemperatureVal
Example 2: RealVariable
Dim hyStream As ProcessStream
Dim TemperatureVal As Double
Set hyStream = hyCase.Flowsheet.MaterialStreams.Item(0)
TemperatureVal = 150
hyStream.Temperature.SetValue 150, “F”
Example 3: RealVariable
Dim hystream As ProcessStream
Set hystream = hyCase.Flowsheet.MaterialStreams.Item(0)
Select Case hystream.Temperature.State
Case vsCalculated
MsgBox “Temperature value is calculated.”
Case vsSpecified
MsgBox “Temperature value is specified.”
Case vsDefaultedValue
MsgBox “Temperature value is default.”
End Select2-39
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-40 Key HYSYS Objects
ww
ThThe constants vsCalculated, vsSpecified, and
vsDefaultedValue are integer variables specified in the type
library.
Fixed Attachments
The FixedAttachments object is a collection object accessed
from Operations or Stream objects. The FixedAttachments
collection object contains a set of objects related to the feeds,
products, or connected operations.
The example below, shows how to determine the streams
attached to a specific unit operation. This example selects the
first column in the operations collection object and then sets an
object to the attached feeds of the column. The names of the
feed streams to the column appear in a property view.
Syntax: Using FixedAttachments
Set FixAtch = SimulationCase.Flowsheet.Operations.Item(0).AttachedFeeds
Set hyStream = FixAttachObj.Item(0)
Types of objects a FixedAttachments Collection
AttachedFeeds - ProcessStream
AttachedProducts - ProcessStream
AttachedLogicalOps - UnitOperation
AttachedOpers - UnitOperation
Examples: FixedAttachments
Dim hyFeeds As FixedAttachments
Dim hyOp As ColumnOp
Set hyOp = hyCase.Flowsheet.Operations(“ColumnOp”).Item(0)
Set hyFeeds = hyOp.AttachedFeeds
For j = 0 To hyFeeds.Count - 1
MsgBox “FeedStream “ & j & “ Name = “ & hyFeeds.Item(j).name
Next j2-40
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-41
ww
ThSolver & Integrator
The Solver is accessed from the SimulationCase object. The
Solver object can be used to turn the calculations on and off.
When accessing HYSYS through Automation it is important to
note that HYSYS does not allow communication while it is
solving. If information is sent to HYSYS from a client application,
HYSYS does not return control to the calling program until
calculations are complete. If it is necessary to pass a large
amount of information to HYSYS it is best to turn the solver off
first and then turn it on once the information is sent. Otherwise,
HYSYS calculates after each piece of information is sent and it
takes much longer to transfer the data.
Syntax for the Solver and Integrator
Solver
SimulationCase.Solver.CanSolve = False
SimulationCase.Solver.CanSolve = True
Integrator
SimulationCase.Solver.Integrator.Active = True
SimulationCase.Solver.Integrator.Active = False
Example: Starting/Stopping the Solver
Dim hystream As ProcessStream
Set hystream = hyCase.Flowsheet.MaterialStreams.Item(0)
hyCase.Solver.CanSolve = False
hystream.Temperature.SetValue 100, “F”
hystream.Pressure.SetValue 1, “atm”
hystream.MassFlow.SetValue 1000, “lb/hr”
hyCase.Solver.CanSolve = True2-41
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-42 Key HYSYS Objects
ww
ThSpreadsheetOp &
SpreadsheetCell(s)
The SpreadsheetCells object is a collection of SpreadsheetCell
objects. The cell properties allow access to information related
to the HYSYS variable being imported or exported, the formulas
associated with the cell, and the value within the cell.
By utilizing the spreadsheet operation, it is possible to access
nearly every property or value in HYSYS even if the object
associated with that property is not exposed as an Automation
interface.
Syntax: SpreadsheetOp and SpreadsheetCell(s)
Set hySS = hyCase.Flowsheet.Operations.Item(“spreadsheetname”)
Set hyCell = hySS.Cell(columnindex, rowindex)
Example: Accessing Spreadsheet Cells
Dim hySS As SpreadsheetOp
Dim hyCell As SpreadsheetCell
Set hySS = hyCase.Flowsheet.Operations(“spreadsheetop”).Item(0)
Dim x As Variant, y As Variant
For i = 0 To 5
x = 1 ' col #
y = i ' row #
Set hycell = hySS.Cell(x,y)
Debug.Print “CELL VALUE = “ & hyCell.CellValue
Debug.Print “CELL FORMULA = “ & hyCell.CellText
Debug.Print “CELL PROPERTY = “ & hyCell.VariableName & “ (“ &
hyCell.Units & “)”
Next i2-42
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-43
ww
Th2.4.8 PFD Objects
PFD objects are used for the manipulation and automation of
PFDItems. A PFDItem is any item that is found on the HYSYS
PFD, such as a unit op or a stream. You can use PFD objects to
Move, Size, Mirror, Rotate, Hide, etc. any PFDItem. PFD objects
also allow you to import and display a selection of PFDItems in
to Visio, a CAD application or Excel (what items you get depends
on what parameters you specify). In addition to manipulating
the PFD you can use the PFDConnection object for such things
as finding the “stream line” route between two PFDItems.
Example: Nozzle Type
If nozzle.NozzleType = pfdInletFromMaterialStream Or
nozzle.NozzleType = pfdOutletToMaterialStream Or nozzle.NozzleType =
pfdInletFromStream Or nozzle.NozzleType = pfdOutletToStream Then
newLine.Line.ForeColor.RGB = RGB(0, 0, 128)
newShape.Fill.ForeColor.RGB = RGB(128, 128, 128)
ElseIf nozzle.NozzleType = pfdInletFromEnergyStream Or
nozzle.NozzleType = pfdOutletToEnergyStream Then
newLine.Line.ForeColor.RGB = RGB(128, 0, 0)
newShape.Fill.ForeColor.RGB = RGB(128, 128, 128)
ElseIf nozzle.NozzleType = pfdMaterialStreamInlet Or
nozzle.NozzleType = pfdMaterialStreamOutlet Then
newLine.Line.ForeColor.RGB = RGB(0, 0, 128)
newShape.Fill.ForeColor.RGB = RGB(0, 0, 128)
newShape.Line.ForeColor.RGB = RGB(0, 0, 128)
ElseIf nozzle.NozzleType = pfdEnergyStreamInlet Or nozzle.NozzleType
= pfdEnergyStreamOutlet Then
newLine.Line.ForeColor.RGB = RGB(128, 0, 0)
newShape.Fill.ForeColor.RGB = RGB(128, 0, 0)
newShape.Line.ForeColor.RGB = RGB(128, 0, 0)
Else
newLine.Line.ForeColor.RGB = RGB(0, 255, 0)
End If 2-43
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-44 Example 1: The Macro Language
ww
Th2.5 Example 1: The Macro
Language Editor
In this example, you use the HYSYS Macro Language Editor to
build a macro tool that displays the Mach number for a selected
stream over a number of different pipe sizes. The speed of
sound in the stream fluid also appears. The fluid velocity
calculated for each pipe size is the average fluid velocity; no
attempt is made to estimate the maximum velocity.
This complete example has also been pre-built and is located
in the HYSYS\Samples\OLE\macros\mach directory.
1. Begin by opening HYSYS and the Macro Language Editor
which is found under the Tools menu.
Figure 2.6 2-44
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-45
ww
Th2. Add a function that returns the Stream object that you
choose from a list. Creating separate functions allows for
easy re-use in other programs.
Code Explanation
Function SelectStream(simcase As Object) As Object Signifies the beginning of the
SelectStream function. This
function takes a SimulationCase
object and prompts the user to
select a Stream from a list of
streams in the case, returning
an interface to the Stream.
Set FS = simcase.Flowsheet Acquire the case flowsheet.
Set Strms = FS.MaterialStreams Acquire the collection of Streams
from the flowsheet.
Dim strmnames()
strmnames = Strms.Names
Build a string array of the
Stream names.
Begin Dialog UserDialog 390,210,”Streams in “ +
Right$(simcase.FullName, Len(simcase.FullName)-
Len(simcase.Path))
ListBox 20,35,350,119,strmnames(),.listsrc
Text 20,14,360,14,”Select a Stream for Mach
number estimation:”
OKButton 140,175,90,21
CancelButton 270,175,90,21
End Dialog
Generate a user property view
containing a list of Streams
Please notice that the first
button created automatically
becomes the default.
Use the Language Help option
provided in the Help menu to
explore the use of UserDialogs.
Dim dlg As UserDialog
If Dialog(dlg) = 0 Then End
Finally, run the Dialog and
terminate the macro if the user
cancels (i.e., Dialog function
returns 0).
Set SelectStream = Strms(dlg.listsrc) Set the function's return value
to the user selected stream
interface.
End Function Signifies the end of the function.
This line does not need to be
added.
The “_” appears at the end of any line of code indicates that
the following line is a continuation of the present line.2-45
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-46 Example 1: The Macro Language
ww
Th3. At this time it is probably a good idea to globally declare
some constants that are used in the Main sub-routine as
shown below.
4. You can now begin defining the Main sub-routine. Enter the
following code:
Figure 2.7
Code Explanation
Sub Main Signifies the beginning main
sub-routine.
pipeSizes(1) = 2
pipeSizes(2) = 3
pipeSizes(3) = 4
pipeSizes(4) = 6
pipeSizes(5) = 8
pipeSizes(6) = 10
pipeSizes(7) = 12
pipeSizes(8) = 16
Defines an array of pipe
sizes (in inches).
Dim simcase As Object
Set simcase = ActiveCase
If simcase Is Nothing Then
MsgBox “No HYSYS case is open.”
End
End If
Looks for an open active
case. If there is no active
case, it alerts the user and
terminates.
Dim strm As Object
Set strm = SelectStream(simcase)
Calls the SelectStream
function to select a stream
in the simcase.2-46
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-47
ww
ThSet flow = strm.MassFlow
If flow.IsKnown Then
flowValue = flow.GetValue(“lb/hr”)
flowValue = flowValue / 3600
Else
GoTo NoFlow
End If
Check to see if the selected
stream has a defined mass
flow rate. If the flow rate is
known, convert the flow
rate in to “lb/s”.
Set rho = strm.MassDensity
If rho.IsKnown Then
rhoValue = rho.GetValue(“lb/ft3”)
Else
GoTo NoRho
End If
Checks to see if the
stream’s mass density has
been calculated.
flowValue = flowValue / rhoValue Calculates volumetric flow
rate.
On Error GoTo NoCv
Cv = strm.MolarHeatCapacityValue / strm.CpCvValue
Proceeds to an error trap if
the Cv value of the stream
has not been calculated.
On Error GoTo NoZ
Z = strm.CompressibilityValue
Proceeds to an error trap if
the compressibility of the
stream has not been
calculated.
On Error GoTo NoTemp
T = strm.TemperatureValue + 273.15
Proceeds to an error trap if
the absolute temperature of
the stream cannot be
calculated.
On Error GoTo NoMolWt
MolWt = strm.MolecularWeightValue / 1000.0
Proceeds to an error trap if
the molecular weight of the
stream cannot be
calculated.
soundVel = Sqr(Z*R*T/MolWt*(1.0+Z*R/Cv))
soundVel = soundVel / 0.3048
soundVelTxt = Format(soundVel, “###,###,###.###”)
Calculates the Speed of
Sound of the stream and
converts it from m/s to ft/s.
Dim DispText() As String
ReDim DispText(nPipes + 2)
DispText(0) = “Pipe Size (in) Mach
Number “
DispText(1) = “------------------------------------
---------------------------”
Declares an array of String
types. The “+2” leaves
room for a two line header.
The two header lines are
assigned.
Please note there are
eighteen spaces between
“(in)” and “Mach” and four
spaces after “Number”.
There are approximately
seventy dashes in the line
DispText(1) = “---...”
Code Explanation2-47
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-48 Example 1: The Macro Language
ww
ThFor num = 1 To nPipes
rSquared = pipeSizes(num) * pipeSizes(num)/144.0/
4.0
Mach = flowValue / pi / rSquared / soundVel
sizetxt = Format(pipeSizes(num),
"###,###,###.###")
Machtxt = Format(Mach, "###,###,###.#####")
DispText(num + 1) = Format$(sizetxt,
"@@@@@@@@@@@@@@@") + " " +
Format$(Machtxt, "@@@@@@@@@@@@@@@")
Next num
For each pipe size, the Mach
number is calculated,
formatted and stored in the
previously created array of
strings.
Please notice that there are
eighteen spaces between
the quotation marks in the
sixth line of code (ninth line
displayed).
Begin Dialog UserDialog 360,217
ListBox 10,49,340,133,DispText(),.Field5
OKButton 250,189,90,21
Text 30,14,150,14,"Speed of Sound (ft/s):",
.Field2
TextBox 190,14,90,21,.Field1
End Dialog
Dim dlg2 As UserDialog
dlg2.Field1 = soundVelTxt
Dialog dlg2
End
Create a user property view
that displays the Speed of
Sound value as well as the
Mach number for each of
the pipe sizes.
Use the Language Help
option provided in the Help
menu to explore the use of
UserDialogs.
NoFlow:
MsgBox "Unknown mass flow in stream " + strm.name
End
NoRho:
MsgBox "Unknown density in stream " + strm.name
End
NoCv:
MsgBox "Unknown heat capacity in stream " +
strm.name
End
NoZ:
MsgBox "Unknown compressibility in stream " +
strm.name
End
NoTemp:
MsgBox "Unknown temperature in stream " +
strm.name
End
NoMolWt:
MsgBox "Unknown molecular weight in stream " +
strm.name
End
This is where you define the
error trap instances.
End Sub Signifies the end of the
method.
Code Explanation2-48
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-49
ww
Th5. Once you have finished adding this code, you should be
ready to run the program. First ensure that HYSYS has a
case loaded with at least one fully defined stream. You can
start the program using one of the following ways:
• Right-click on any area of the Macro Language Editor
property view, select Macro | Run command from the
Object Inspect menu.
• Pressing the F5 on the keyboard.
• Clicking the Start/Resume icon on the toolbar.
You should see a property view similar to the one shown
below:
6. Select a stream from the list and click the OK button. This
should result in a property view similar to the one shown
below.
Figure 2.8
Figure 2.9
Start/Resume icon2-49
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-50 Example 2: Automation in Visual
ww
Th7. Be sure to save the program by doing one of the following:
• Right-click on any area of the Macro Language Editor
property view, select File | Save from the Object
Inspect menu.
• Press the CTRL S hot key combination.
• Clicking the Save icon in the toolbar.
2.6 Example 2:
Automation in Visual
Basic
In this example HYSYS is used as the Automation server for a
unit conversion program. More specifically, you are accessing an
object called the UnitConversionManager which manages unit
conversion within HYSYS.
1. Open a new project in Visual Basic 6.0® and from the New
tab of the New Project property view select the Standard
EXE icon and click the Open button.
Although Visual Basic 5.0 is recommended for this example,
you can create this Automation application in Visual Basic
Editor provided in MS Excel 97® and MS Word 97®.
The completed Example 2 has been pre-built and is located in
the HYSYS\Samples\OLE\vb\ ucsm directory.
Save icon
Standard EXE icon2-50
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-51
ww
ThYour screen should appear similar to the figure below.
2. By default you should have a form associated with the
project. Begin, by giving the form a name. In the Name field
of the Properties tiled property view give the form the name:
frmUCSM.
3. In the Caption field type: UNIT CONVERSION MANAGER.
This caption should now appear in the Title Bar of the form.
4. Before adding objects to the form, resize the property view
to accommodate the different objects that are required. In
the Width field found in the Properties tiled property view
change the width of the form to 12600 or so that the form is
sufficiently wide enough to contain all the objects you are
adding (see Figure 2.14).
Figure 2.10
Toolbox Form Properties Tiled property view2-51
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-52 Example 2: Automation in Visual
ww
Th5. From the toolbox select the Combo Box icon and create a
combo box on the form as shown below.
6. Ensure that the combo box is the active control. This can be
done in one of two ways:
• Select the combo box on the form so that the object
guides appear around the object.
• From the drop-down list found at the top of the
Properties tiled property view select the name of the
combo box you have just created.
7. In Properties tiled property view, set the name of the Combo
Box as ddUnitSet in the Name field. If you want, you can
also change the default text that appears inside the combo
box by entering a new name in the Text field.
8. You can add a Label to the form (i.e., to identify the object
from others), by clicking the Label icon and drawing a label
on the form just above the combo box you have just created.
9. Ensuring that the Label control is active using one of the
methods suggested in #6, go to Properties tiled property
view and change the text in the Caption field to Unit
Conversion Set.
Figure 2.11
Figure 2.12
Combo Box icon
Label icon2-52
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-53
ww
Th10.Now add an Text Box next to the Combo Box you created.
Use the method described in Steps #6 - #7 to name this
Text Box ebFromValue. Repeat Steps #8 - #9 to add a
Label above the ebFromValue Text Box that reads From
Value.
11.Add the following objects to the property view using the
previously described methods.
Figure 2.13
Figure 2.14
Object Type - Label
Caption - From Unit Conversion
Object Type - Combo Box
Name - ddFromUnit
Text - ddFromUnit
Object Type - Label
Name - lbToValue
Caption - lbToValue
Object Type - Label
Caption - To Value
Object Type - Label
Caption - To Unit Conversion
Object Type - Combo Box
Name - ddToUnit
Text - ddToUnit2-53
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-54 Example 2: Automation in Visual
ww
Th12.Only two more objects are required on the form. Select the
Command icon control from the toolbox and add two
buttons to the property view as shown below.
13. You are now ready to begin defining the events behind the
form and objects. You can enter the code environment using
a number of methods:
• Click the View Code icon in the Project tiled property
view.
• Select the Code command from the View menu.
• Double-click the frmUCSM form.
Figure 2.15
Command icon
Object Type - Command icon
Name - btConvert
Caption - Convert
Object Type - Command icon
Name - btExit
Caption - Exit
View Code icon2-54
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-55
ww
ThThe following property view should appear:
14.Begin by declaring the following variables under the Option
Explicit declaration.
Figure 2.16
The Private Sub Form_Load() method definition is only
visible if you enter the code environment by double-clicking
the form.
Figure 2.17
If you attempt to use an undeclared variable, an error occurs
at compile time.2-55
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-56 Example 2: Automation in Visual
ww
Th15.The first sub-routine should already be declared. The
Form_Load sub-routine is the first sub-routine called once
the program is run. It is usually used to initialize the
variables and objects used by the program. Enter the
following code in to the Form_Load sub-routine.
16. The next section of code to be added tells the program what
is to occur when an option is selected in the ddUnitSet
combo box.
Code Explanation
Private Sub Form_Load() Signifies the Start of the form load sub-routine. You do
not have to add it as it should already be there.
ddUnitSet.Clear
ddFromUnit.Clear
ddToUnit.Clear
Clear the default text found inside the ddUnitSet,
ddFromUnit and ddToUnit combo boxes.
Set hyApp = CreateObject("HYSYS.Application")
Set UCSM = hyApp.UnitConversionSetManager
Connects to HYSYS and the HYSYS Unit Conversion Set
Manager.
For Each UCS In UCSM
ddUnitSet.AddItem UCS.Name
Next UCS
For each Unit Conversion Set found in the Unit
Conversion Set Manager add the Unit Set to
ddUnitSet combo box list.
ddUnitSet.ListIndex = -1
Indicates no item is currently selected in the ddUnitSet
combo box.
ebFromValue.Text = ""
lbToValue.Caption = ""
Clears the text that appears in the ebFromValue text
box and the lbToValue label.
End Sub Signifies the end of the initialization sub-routine. This
line does not need to be added.
Code Explanation
Private Sub ddUnitSet_Click() Signifies the Start of the sub-routine.
ddFromUnit.Clear
ddToUnit.Clear
Clears any list entries in the ddFromUnit and
ddToUnit combo boxes.
Set hyApp = CreateObject("HYSYS.Application")
Set UCSM = hyApp.UnitConversionSetManager
Connects to HYSYS and the HYSYS Unit Conversion Set
Manager.
UCSNumber = ddUnitSet.ListIndex
Once the selection is made in the ddUnitSet combo
box, the UCSNumber variable holds the internal
HYSYS index number of the selected Unit Set.
Set UCS = UCSM.Item(UCSNumber)
Find the selected Unit Conversion Set in Unit
Conversion Manager.
For Each UC In UCS
ddFromUnit.AddItem UC.Name
ddToUnit.AddItem UC.Name
Next UC
For each Unit Conversion type (UC) in the Unit
Conversion Set, add the Unit type to both the
ddFromUnit combo box (the unit type the program is
converting from) and the ddToUnit (the unit type the
program is converting to).
ddFromUnit.ListIndex = -1
ddToUnit.ListIndex = -1
Indicates no items are currently selected in the
ddFromUnit and ddToUnit combo box.2-56
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Automation 2-57
ww
Th17.The next 2 sub-routines reset the lbToValue label whenever
an option is selected in either the ddFromUnit or ddToUnit
combo box.
18. The final two sub-routines define the actions of the two
buttons: btConvert and btExit.
lbToValue.Caption = "" Clears any text that appears in the lbToValue label.
End Sub Signifies the end of the sub-routine. This line does not
need to be added.
Code Explanation
Code Explanation
Private Sub
ddFromUnit_Click()
Signifies the Start of the sub-routine.
lbToValue.Caption = "" Clears any text that appears in the lbToValue label.
End Sub Signifies the end of the sub-routine. This line does not need to
be added.
Code Explanation
Private Sub ddToUnit_Click() Signifies the Start of the sub-routine.
lbToValue.Caption = "" Clears any text that appears in the lbToValue label.
End Sub Signifies the end of the sub-routine. This line does not need to
be added.
Code Explanation
Private Sub btConvert_Click() Signifies the Start of the sub-routine.
Set hyApp = CreateObject("HYSYS.Application")
Set UCSM = hyApp.UnitConversionSetManager
Connects to HYSYS and the HYSYS Unit
Conversion Set Manager.
FromValue = CDbl(Val(ebFromValue.Text))
Takes the value entered in the ebFromValue text
box and converts in to a numerical variable type.
ebFromValue.Text = CStr(FromValue)
Set ebFromValue text box text equal to
FromValue double.
UCSNumber = ddUnitSet.ListIndex
FromNumber = ddFromUnit.ListIndex
ToNumber = ddToUnit.ListIndex
Gets current selection in the three drop-down lists
(combo boxes).
If FromNumber < 0 Or ToNumber < 0 Then
lbToValue.Caption = ""
Exit Sub
End If
If no selection is made in either the ddFromUnit
or ddToUnit combo boxes, exit the sub-routine.
Set UCS = UCSM.Item(UCSNumber)
Set FromUC = UCS.Item(FromNumber)
Set ToUC = UCS.Item(ToNumber)
Chooses a specific UCS from UCSM. It takes the
Unit conversion type you want to change from,
and the Unit Conversion type you want to change
to.2-57
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
2-58 Example 2: Automation in Visual
ww
Th19.You are now ready to compile and run the program. Before
you begin, please ensure that you have a copy of HYSYS on
the computer.
20. To compile the program do one of the following:
• Click the Start icon in the toolbar.
• Select Start command from the Run menu.
• Press F5 from the keyboard.
VB informs you of any errors that occur during compile time.
Intermediate = FromUC.ToCalculationUnit(FromValue)
ToValue = ToUC.FromCalculationUnit(Intermediate)
lbToValue.Caption = CStr(ToValue)
Converts the contents of the ddFromValue
combo box from the FromUC units to HYSYS
internal units (Intermediate). It then converts
the Intermediate value from internal units to the
ToUC units. It then displays the converted value
in the lbToValue label.
End Sub Signifies the end of the sub-routine. This line does
not need to be added.
Code Explanation
Private Sub btExit_Click() Signifies the Start of the sub-routine.
Unload Me
End
Unloads the form and ends the program.
End Sub Signifies the end of the sub-routine. This line does
not need to be added.
Code Explanation
Start icon2-58
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-1
ww
Th3 Extensibilityw.cadfamily.com EMa
e document is for study 3.1 Introduction................................................................................... 3
3.2 Implementing Interfaces ............................................................... 5
3.2.1 Implementing an Interface Through a Dispatch Interface............... 5
3.2.2 Implementing an Interface Through a Custom Interface ................ 6
3.3 Data Types..................................................................................... 6
3.4 Extension Development Kit ............................................................ 7
3.5 Creating an Extension .................................................................... 9
3.5.1 In Visual Basic ......................................................................... 9
3.5.2 In C++ ................................................................................. 13
3.5.3 In C# or VB.NET .................................................................... 17
3.6 Registering Extensions ................................................................ 21
3.6.1 Registering Extensions Written in C++ ...................................... 22
3.6.2 Registering Extensions Written in Visual Basic ............................ 24
3.6.3 Registering Extensions Written in C# or VB.NET ......................... 25
3.7 Extension Interface Details.......................................................... 26
3.7.1 ExtnContainer Interface .......................................................... 26
3.7.2 ExtensionObject Interface ....................................................... 28
3.8 Extension Reaction Kinetics ......................................................... 28
3.8.1 ExtnKineticReaction Interface................................................... 30
3.8.2 ExtnKineticReactionContainer Interface ..................................... 31
3.8.3 Kinetic Reaction Example ........................................................ 31
3.9 Extension Property Packages....................................................... 46
3.9.1 ExtnPPkgContainer Interface.................................................... 503-1
il:cadserv21@hotmail.com
only,if tort to your rights,please inform us,we will delete
3-2 Extensibility
www.cadfamily.com EMa
The document is for study 3.9.2 ExtnPropertyPackage Interface .................................................51
3.10 Extension Unit Operations ..........................................................52
3.10.1 ExtnUnitOperationContainer Interface....................................53
3.10.2 ExtnUnitOperation Interface .................................................54
3.10.3 Passes...............................................................................54
3.10.4 Extension Unit Operation Example.........................................56
3.11 References..................................................................................803-2
il:cadserv21@hotmail.com
only,if tort to your rights,please inform us,we will delete
Extensibility 3-3
ww
Th3.1 Introduction
HYSYS provides the unique capability of enhancing its
functionality through the addition of custom objects to a
simulation. With its open concept, the functionality of HYSYS
can be extended to include your unique or proprietary
calculations. Currently, you can add:
• Extension Unit Operations
• Extension Reaction Kinetics
• Extension Property Packages
Extensions are packaged in to two distinct files making them
easy to transfer to different machines. The extension code
becomes part of a DLL (dynamic linked library), that hides its
proprietary information, making it an excellent vehicle for
commercial distribution. Extensions become part of the
simulation and participate in simulation calculations like any
other HYSYS object. For example, each extension unit operation
has a corresponding PFD icon and property view. Also, the
Extension has its Execute method called by the Steady-State
Solver. Unlike applications which interact with HYSYS through
Automation, extensions exist in process with the HYSYS
applications. New extensions can be written in any language
that supports Automation (formerly OLE Automation). This
provides much flexibility to the end user, who can develop the
extension in languages such as C++ or Visual Basic. By its very
nature, Visual Basic provides the easiest development
environment in which to create unit operation and kinetic
reaction extensions. The Extension Property Package interface
must be implemented as a custom interface, therefore C++
must be used.
Each type of extension is represented in HYSYS by an Extension
Container. This object is the gateway through which HYSYS
communicates with the extension. The Container can also
provide a number of services to the extension, such as
performing Mass Balances or allowing access to the Status Bar.3-3
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-4 Introduction
ww
ThHYSYS finds extensions by looking for specific keys in the
System Registry. When an extension is registered on a
computer, information about it is added to the Registry. Upon
start-up, HYSYS scans the Registry for this information, and
adds user-specified descriptions to the appropriate lists within
the program. For instance, when a unit operation extension is
created with the description provided as “MY Unit Op”. This text
appears in the HYSYS UnitOps property view in the Available
Unit Operations pane so that the user can create instances of
them.
When the user asks for an extension to be created, HYSYS
instantiates the object and calls its Initialize method. At this
point, the extension code gains access to its Container. After the
extension has been initialized, it behaves like any other HYSYS
object of the same class.
All extensions must support at least two interfaces:
• The ExtensionObject interface
• At least one other interface particular to the type of
extension
Containers support one interface, which is particular to the type
of container.
Figure 3.1
HYSYS
Extension
CodeContainer3-4
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-5
ww
Th3.2 Implementing
Interfaces
An extension implements an interface if it supports the methods
in that interface. There are two different ways of implementing
an interface.
3.2.1 Implementing an
Interface Through a
Dispatch Interface
An extension can implement interfaces through Dispatch
interfaces. This can be done in Visual Basic if the extension is
implemented as a Visual Basic Class.
When an extension is implemented in this manner, only the
methods of the interface that are required for minimal operation
of the extension need be used. All other methods may be
ignored, or they can be provided if the extension implements
that functionality.
For example, an extension Unit Operation can be implemented
by supporting only the Initialize and Execute methods. The
BasisChanged method need only be implemented if the
extension needs to be notified when the Basis of the simulation
has changed.3-5
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-6 Data Types
ww
Th3.2.2 Implementing an
Interface Through a
Custom Interface
An extension can also be implemented by overloading the
Custom interfaces defined for the extension. For example, an
extension Unit Operation can be created by overloading the
ExtensionObject interface and the ExtnUnitOperation interface.
When an extension is created in this manner, all methods of the
interface must be overloaded (this is a requirement of the C++
language definition). If a method does not contain any
functionality, however, the error condition E_NOTIMPL should be
returned to indicate to HYSYS that the method is not being
used. Using the Extension Unit Operation as an example once
again; each of the methods in its two supported interfaces must
be overloaded, but only the Initialize and Execute methods need
return anything other than E_NOTIMPL.
3.3 Data Types
This documentation for the most part uses Visual Basic syntax in
its sample code and examples. The following table provides a
map of Visual Basic types to C++, .NET, C#, and VB.NET types.
Visual Basic Type C++ Type .NET Type C# Type VB.NET Type
Variant VARIANT System.Object object Object
String BSTR System.String string String
Boolean VARIANT_BOOL System.Boolean bool Boolean
Long long System.Int32 int Integer
Integer short System.Int16 short Short
Double double System.Double double Double
Single float System.Single float Single
arrays SAFEARRAY System.Array Array or specific
(string[], int[],
double[])
Array or specific
(string(), int(),
double())3-6
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-7
ww
Th3.4 Extension
Development Kit
A number of tools are provided in the HYSYS Extension
Development Kit. These tools are not required to build
extensions for HYSYS, but they make the job much easier.
Included in the kit are the following:
When sending an array of numbers to HYSYS they should
always be of type REAL or LONG.
File Description
hysys.tlb The HYSYS Type Library, that contains definitions for all
objects exposed by HYSYS, as well as definitions for
interfaces required by HYSYS Extensions. Programming
languages such as Visual Basic use this file to determine
what a particular object contains. Many programs
provide browsers to look at the contents of this file. For
example, Excel provides an Object Browser that can be
used to view the properties of methods of each object
and to help navigate the object model. Unlike the other
files in the table, the HYSYS Type Library is always
installed, even when you do not install the Extension
Development Kit.
extsdk.bas Contains constants defined by HYSYS in a format that
can easily be included in a Visual Basic project. This
allows the extension developer to refer to HYSYS
constants through Const definitions, rather than
through numbers. This information can also be read
from the HYSYS Type Library, if your programming
language supports this.
extsdk.cpp and
extsdk.hpp
Contain support code that can be included in a C++
project. They implement a ClassFactory for any
extensions in the project and also implement the
DllRegisterServer and DllUnregisterServer methods.
These files compile in both Microsoft Visual C++ and
Borland C++.
hysys.hh Contains definitions of all the interfaces and
enumerations found in the HYSYS Type Library.
Including this file in your C++ source allows you to call
methods on HYSYS interfaces.
hysysiid.cc Instantiates all of the GUIDs defined by HYSYS. It can
be included as part of a C++ project to allow reference
to HYSYS GUIDs.3-7
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-8 Extension Development Kit
ww
ThThe HYSYS View
Editor
Allows you to:
• Define extension information for the registration
program.
• Define Variables for HYSYS to create and manage
on behalf of an extension.
• Create property views for an extension.
Aspentech.
HYSYS.Interop.
dll
The HYSYS Interop Assembly contains .NET definitions
for all objects exposed by HYSYS as well as definitions
for interfaces required by HYSYS Extensions.
.NET programming languages such as C# or Visual
Basic use this file to determine what a particular object
contains. Visual Studio provides an object browser that
can be used to look at the contents of this file. Like the
HYSYS Type Library, the HYSYS Interop Assembly is
always installed, even when you do not install the
Extension Development Kit.
File Description3-8
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-9
ww
Th3.5 Creating an Extension
3.5.1 In Visual Basic
Creating an extension in Visual Basic is a very straightforward
procedure. The following six steps can be used as a general
framework:
1. Create the Extension Definition.
2. Create the Object property views.
3. Implement the Required Methods.
4. Register the Extension.
5. Debug the Extension.
6. Distribute the Extension.
These steps are explained in more detail in the following
sections.
Create the Extension Definition
The EDF contains important information about an extension that
is required by the extension's container in HYSYS. Specifically, it
contains information about the variables that the extension own
(that are managed by the container), and it can also contain one
or more property views for the object.
For each extension, you must provide either a CLSID or a
ProgID. Other information that can be provided at this point
includes: the extension description, from which you identify the
extension within HYSYS, the extension type and the number of
property views. For extensions written in Visual Basic, you must
specify a ProgID. The selection of the ProgID is explained in the
following sub-section entitled: Register the Extension.
The extension definition file, which contains the definition of
the extension is created using the View Editor.3-9
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-10 Creating an Extension
ww
ThOnce the preliminary definition information is provided, you
specify the variables that the object owns and that are visible to
the user. These variables are of the following types:
Numeric Variables and Text Variables may or may not be
persistent. If they are, their values are stored when the
Simulation Case containing the extension is saved.
Create the Object Property View(s)
A property view for your extension is not necessary, but quite
often you want the user to be able to interact with your object.
The View Editor can be used to create property views for your
object.
Views are created by adding widgets to the DefaultView form.
Select a widget with the secondary mouse button, drag it on to
the DefaultView form, and drop it. You can then position the
widget to your liking. Double-click the widget to access its
Properties property view, from which you can specify detailed
information for the widget. If necessary, you can associate a
variable with the widget.
It is possible to create an EDF with 0 views.
Variable Type Description
Numeric • Represent numerical quantities and have a
Variable Type that allows HYSYS to manage Unit
Conversions for the user.
• May have zero, one, or two dimensions.
• Can also trigger the steady state solver when
they are changed. If this is the case, the variable
operates like other HYSYS variables in that the
solver performs consistency checking when
values are changed.
Text • Represents a string.
• May be zero- or one-dimensional.
Message Usually associated with buttons in a property view.
Messages are sent through the VariableChanged
method of an extension.
A widget is an equivalent term for a Visual Basic control.
For more information on
the View Editor see
Chapter 4 - Extension
View Editor.3-10
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-11
ww
ThEach DefaultView form must have a unique name. The object’s
default property view must be called DefaultView as it is the
property view HYSYS attempts to open when the object is
instantiated, provided the functionality of the OnView method is
not overridden.
Implement the Required Methods
To implement an extension from Visual Basic, you must create a
project containing a Class Module. This Class Module must
implement whatever methods are required by the container. For
example, to implement an Extension Unit Operation, you must
implement an Initialize method and an Execute method, and
these methods must have the same parameters as defined by
the interface.
Register the Extension
Before you register your extension, you must ensure that the
ProgID defined by your Visual Basic project is the same as that
which you entered in the EDF for this object. ProgIDs are
defined by Visual Basic in the following form:
ProjectName.ClassName
where:
ProjectName = the name of the project (which is set on the
Project tab of the Options property view in VB 5.0)
ClassName = the name of the class (which is set through the
Name parameter of the class' property view).
For Example, a class called Extension1 in a project called
AspenTechExtensionProject would have a ProgID of
AspenTechExtensionProject.Extension1.
You can register extensions on the Extensions tab of the Session
Preferences property view.
For more information on
extension registration
see Section 3.6 -
Registering
Extensions.3-11
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-12 Creating an Extension
ww
ThDebug the Extension
To debug the extension, you can set breakpoints on just about
any line in your Visual Basic class. Initially, you should probably
set a breakpoint on the Initialize method. Then, start the
extension (via the Start button or the Start command in the Run
menu).
Next, start HYSYS and create an instance of your extension. This
is done in the same manner as you would create other objects of
the same class. For example, extension Unit Operations can be
created through the UnitOps property view (accessed though
the F12 key).
When you create an instance of your extension, HYSYS creates a
container for it. This container first creates an instance of your
Visual Basic class, and then calls its Initialize method. At this
point, your breakpoint in Visual Basic should be reached. Now
you can inspect variables and step though your code.
You can also use the Debug object in Visual Basic to print
information to the Debug property view while the extension
runs.
Distribute the Extension
Once you are confident that your extension is behaving properly,
you can create an ActiveX DLL file. Create the DLL file by
selecting the appropriate option from Visual Basic’s File menu.
The end result of this step is an extension that you can
distribute without exposing any proprietary information or
methods.
To distribute your extension, you must provide the DLL file, the
EDF file, and any other files required by your extension (i.e., a
separate FORTRAN DLL called from your extension). You must
register your extension on each individual machine that uses the
extension calculations. You can use the registration tool found
on the Extensions tab of the Session Preferences property view
for this, or you can include this step in your own setup program.
For more information on
debugging, please
consult your Visual Basic
manual and help files.3-12
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-13
ww
Th3.5.2 In C++
The following six steps provide a framework for creating an
extension in C++:
1. Create the Extension Definition.
2. Implement the Required Interfaces.
3. Implement the ClassFactory.
4. Create and Register the DLL.
5. Debug the Extension.
6. Distribute the Extension.
These steps are explained in more detail in the following
sections.
Create the Extension Definition
The EDF contains important information about an extension that
is required by the extension's container in HYSYS. Specifically, it
contains information about the variables that the extension own
(that are managed by the container), and it may also contain
one or more property views for the object.
For each extension, you must provide either a CLSID or a
ProgID. Other information that can be provided at this point
includes: the extension description, from which you identify the
extension within HYSYS, the extension type and the number of
property views. The selection of the ProgID is explained in the
following sub-section entitled: Register the Extension.
The extension definition file, which contains the definition of
the extension is created using the View Editor.
It is possible to create an EDF with 0 views.3-13
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-14 Creating an Extension
ww
ThOnce the preliminary definition information is provided, you
specify the variables that the object owns and that is visible to
the user. These variables are of the following types:
Numeric Variables and Text Variables may or may not be
persistent. If they are, their values are stored when the
Simulation Case containing the extension is saved.
Implement the Required Interfaces
To create an extension in C++, you must create a class that
implements the required interfaces. For example, an Extension
Unit Operation must implement the ExtensionObject interface
and the ExtensionUnitOperation interface. This calculation can
be done through inheritance or aggregation. HYSYS functions if
either approach is taken, as long as the interfaces are supported
through the COM QueryInterface mechanism.
To implement an extension, you must provide code for the
standard COM IUnknown methods (AddRef, Release,
QueryInterface), as well as any methods required by the
interfaces you are supporting. Other methods may return
E_NOTIMPL if you choose not to implement them.
Variable Type Description
Numeric • Represent numerical quantities and have a
Variable Type that allows HYSYS to manage Unit
Conversions for the user.
• May have zero, one, or two dimensions.
• Can also trigger the steady state solver when
they are changed. If this is the case, the variable
operates like other HYSYS variables in that the
solver performs consistency checking when
values are changed.
Text • Represents a string.
• May be zero- or one-dimensional.
Message Usually associated with buttons in a property view.
Messages are sent through the VariableChanged
method of an extension.
For more information on
the View Editor see
Chapter 4 - Extension
View Editor.3-14
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-15
ww
ThDefinitions of the interfaces that you must implement (as well as
any interfaces provided by HYSYS objects) are provided in the
hysys.hh file, that is included in the Extension Development Kit.
You must include this file in any source files that access the
defined interfaces.
Implement the Class Factory
When HYSYS creates an instance of your extension object, it
accesses the COM Library which calls the function
DllGetClassObject which is contained in the DLL. DllGetObject
creates the requested class factory. You can implement a
ClassFactory yourself, or you can use the one provided in
extsdk.cpp (which is included in the Extension Development
Kit).
If you choose to use the ClassFactory provided by extsdk.cpp,
you must implement the REGISTER_EXTENSION macro
somewhere in your code. This macro provides information to the
ClassFactory on how to create an instance of your extension.
The syntax of this macro is:
REGISTER_EXTENSION(ClassName, clsid, VisibleDescription)
where:
ClassName = the C++ name of the class
clsid = the CLSID of the class
VisibleDescription = a string containing a description of the
class that a user can understand
You must implement this macro once for every extension in your
DLL.3-15
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-16 Creating an Extension
ww
ThCreate & Register the DLL
When you build your project, you must implement it as a 32-bit
Dynamic Link Library (DLL). This DLL must contain code for your
extension, a ClassFactory to create your extensions, and a
DllRegisterServer entry point.
The Extension Development Kit provides extsdk.cpp, which
contains a ClassFactory and an implementation of
DllRegisterServer. If you use this ClassFactory, you must include
this file in your project.
You can register your DLL on the Extensions tab of the Session
Preferences property view.
Debug the Extension
You can debug your extension by putting a call to the Win32
function DebugBreak in your code. When HYSYS executes this
part of your code, you are allowed to start your debugger and
debug the code from there. You are then able to inspect
variables, and trace the execution of your extension's code. You
can also debug your extension in MS DevStudio by setting
breakpoints in the code. Specifying the path of the HYSYS
executable file in the Executable for debug session field on the
Debug tab of the Project Settings property view and launch
VC++ auto debug.
You can load your extension by starting HYSYS and creating an
instance of the extension. HYSYS creates a container, and this
container then calls the extension's Initialize method.
Distribute the Extension
Once you are confident that your extension is behaving properly,
you can create an ActiveX DLL file. The end result of this step is
an extension that you can distribute without exposing any
proprietary information or methods.
For more information on
extension registration
see Section 3.6 -
Registering
Extensions.3-16
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-17
ww
ThTo distribute your extension, you must provide the DLL file, the
EDF file, and any other files required by your extension (i.e., a
separate FORTRAN DLL called from you extension). You must
register your extension on each individual machine that uses the
extension calculations. You can use the registration tool found
on the Extensions tab of the Session Preferences property view
for this, or you can include this step in your own setup program.
3.5.3 In C# or VB.NET
Creating an extension in Visual Basic is a very straightforward
procedure. The following six steps can be used as a general
framework:
1. Create the Extension Definition.
2. Create the Object property views.
3. Implement the Required Methods.
4. Register the Extension.
5. Debug the Extension.
6. Distribute the Extension.
These steps are explained in more detail in the following
sections.
Create the Extension Definition
The EDF contains important information about an extension that
is required by the extension's container in HYSYS. Specifically, it
contains information about the variables that the extension own
(that are managed by the container), and it may also contain
one or more property views for the object.
For each extension, you must provide either a CLSID or a
ProgID. Other information that can be provided at this point
includes: the extension description, from which you identify the
extension within HYSYS, the extension type and the number of
The extension definition file, which contains the definition of
the extension is created using the View Editor.3-17
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-18 Creating an Extension
ww
Thproperty views. The selection of the ProgID is explained in the
following sub-section entitled: Register the Extension.
Once the preliminary definition information is provided, you
specify the variables that the object owns and that are visible to
the user. These variables are of the following types:
Numeric Variables and Text Variables may or may not be
persistent. If they are, their values are stored when the
Simulation Case containing the extension is saved.
Create the Object Property View(s)
A property view for your extension is not necessary, but quite
often you want the user to be able to interact with your object.
The View Editor can be used to create property views for your
object.
Views are created by adding widgets to the DefaultView form.
Select a widget with the secondary mouse button, drag it onto
the DefaultView form, and drop it. You can then position the
widget to your liking. Double-click the widget to access its
Properties property view, from which you can specify detailed
information for the widget. If necessary, you can associate a
It is possible to create an EDF with 0 views.
Variable Type Description
Numeric • Represent numerical quantities and have a
Variable Type that allows HYSYS to manage Unit
Conversions for the user.
• May have zero, one, or two dimensions.
• Can also trigger the steady state solver when
they are changed. If this is the case, the variable
operates like other HYSYS variables in that the
solver performs consistency checking when
values are changed.
Text • Represents a string.
• May be zero- or one-dimensional.
Message Usually associated with buttons in a property view.
Messages are sent through the VariableChanged
method of an extension.3-18
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-19
ww
Thvariable with the widget.
Each DefaultView form must have a unique name. The object’s
default property view must be called DefaultView as it is the
property view HYSYS attempts to open when the object is
instantiated, provided the functionality of the OnView method is
not overridden.
Implement the Required Methods
To implement an extension in C# or VB.NET, you must first
create a Class Library project. In the project, you must then add
a reference to the HYSYS Interoperability Library
(Aspentech.HYSYS.Interop.dll) which can be found in the root
directory of the install location for Aspen HYSYS 2006.
Next, you must create a class that implements the required
interfaces. For example, an Extension Unit Operation must
implement the ExtensionObject interface and the
ExtensionUnitOperation interface.
The class should have the appropriate attributes from the
System.Runtime.InteropServices namespace required to
export a class to COM. These include but are not limited to
ComVisible, ClassInterface, GuidAttribute, and
ProgIdAttribute. ComVisible must be set to true;
ClassInterface is recommend to be set to AutoDispatch which
is the default; GuidAttribute represents the CLSID and will be
generated if not specified (its highly recommended that you
specify this manually); ProgIdAttribute is optional unless you
refer to this class using the ProgID in the Extension Definition.
Register the Extension
You can register extensions on the Extensions tab of the Session
Preferences property view or using the regextn.exe command-
line executable.
A widget is an equivalent term for a control.
For more information on
extension registration
see Section 3.6 -
Registering
Extensions.3-19
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-20 Creating an Extension
ww
ThDebug the Extension
To debug the extension, you can set breakpoints on just about
any line in your class. Initially, you should probably set a
breakpoint on the Initialize method. Then, set HYSYS.exe as the
external program in the Project Properties Debug page.
You can debug your extension in Microsoft Visual Studio 2003 or
2005 by setting breakpoints in the code and by attaching to
running copy of HYSYS from the Attach to Process dialog from
the Tool menu. When attaching the extension to a running
HYSYS case, ensure that you select the managed code debug
option and not native code debug option. You can also start
HYSYS from Microsoft Visual Studio by specifying the path of the
HYSYS executable file in the Start external program field on the
Debug tab of the Project Settings property view.
You can load your extension by starting HYSYS and creating an
instance of the extension. HYSYS creates a container, and this
container then calls the Initialize method of that extension. You
can also use the System.Diagnostics.Debug.Print method in
.NET to print information to the Output Debug view while the
extension runs.
Note: Microsoft Visual Studio .NET 2003 cannot debug a
managed process if .NET 2.0 is being used (HYSYS uses .NET
2.0 by default). You can override this behaviour and force .NET
1.1 to be used so that Visual Studio .NET 2003 can debug the
extension by adding a file called hysys.exe.config to same
directory as hysys.exe that states:
Distribute the Extension
Once you are confident that your extension is behaving properly,
you can create an ActiveX DLL file. The end result of this step is
an extension that you can distribute without exposing any 3-20
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-21
ww
Thproprietary information or methods.
To distribute your extension, you must provide the DLL file, the
EDF file, and any other files required by your extension (i.e., a
separate FORTRAN DLL called from you extension). You must
register your extension on each individual machine that uses the
extension calculations. You can use the registration tool found
on the Extensions tab of the Session Preferences property view
for this, or you can include this step in your own setup program.
3.6 Registering Extensions
In order for HYSYS to find extensions, they must be registered
in the Extensions tab of the Session Preferences property view.
HYSYS looks for extensions in the:
HKEY_CLASSES_ROOT\Software\AspenTech\HYSYS\1.1\Extension
s key.
Each extension should have the following information under this
key:
All this information is provided when the EDF is created in the
View Editor.
Extensions can be registered with either a CLSID (Class
Identifier) or a ProgID (Program Identifier). It is recommended
that ProgID be used for extensions created in Visual Basic, and
CLSID be used for all other extensions.
The Extension Definition File entry gives the name of the
KeyName = Descriptive Name of Extension
ExtensionDefinitionFile = name of Extension Definition File
ExtensionType = type, class
CLSID = CLSID of Extension or
ProgID = ProgID of Extension
Only one of the ProgID or CLSID values can be used.
See Chapter 4 -
Extension View Editor
for more information on
creating an EDF.3-21
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-22 Registering Extensions
ww
ThExtension Definition File for the object.
The type of the extension is given by the ExtensionType entry.
The type can be UnitOperation, PropertyPackage or
KineticReaction. The class descriptor is optional, and currently is
ignored if present.
3.6.1 Registering Extensions
Written in C++
When you create an extension in C++, you must implement a
DllRegisterServer function in the DLL containing the extension.
This function is called from HYSYS when registering the
extension. The file extsdk.cpp that is included with the
Extension Development Kit provides code that implements this
function.
To register an extension written in C++, simply use the
following procedure:
1. Start HYSYS. From the Tools menu, select Preferences
command. The Session Preferences property view opens.
2. Go to the Extensions tab and click the Register an
Extension button. This opens the Select an Extension to
be Registered property view.
Ensure that the EDF and extension DLL are in the same
directory.3-22
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-23
ww
Th3. Use the File Path group to find the directory in which the
DLL file is saved. Once you find the DLL file, select it and
click the OK button.
The Extensions tab should now appear similar to the figure
below.
You are now ready to use the extension in HYSYS.
Figure 3.2
Figure 3.33-23
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-24 Registering Extensions
ww
Th3.6.2 Registering Extensions
Written in Visual Basic
Extensions written in Visual Basic may be run from within Visual
Basic, or may be compiled to an ActiveX DLL file. Either way,
Visual Basic takes care of registering half of the information
required for HYSYS to find the extension. The HYSYS
registration tool provided in the Session Preferences property
view may be used to register the other half.
Running Within Visual Basic
If you are running your extension within the Visual Basic
environment, Visual Basic temporarily adds information to the
registry every time the project is run. This information changes
every time you run the project. The extra information needed
can be added by going to the Extensions tab of the Session
Preferences property view and registering the EDF file. When
run this way, information about where to find an extension is
added to the registry, but information on how to create it is not.
Compiled DLL Files
When you compile your extension to an ActiveX DLL file, you
must do both parts of the registration. You can use the
procedure described in the Section 3.6.1 - Registering
Extensions Written in C++ to register the DLL files in the
HYSYS Session Preferences.
HYSYS loads the DLL file and registers it, and then it takes the
name of the DLL file and looks for an Extension Definition File
with the same name in the same directory to complete the
registration.
To view EDF files in Select an Extension to be Registered
property view, you must change the settings in the File Filter
drop-down list from Application Extensions (*.dll) to
Extension Definition Files (*.edf).
Refer to Section 3.6.1 -
Registering
Extensions Written in
C++, for the step by
step procedure for
registering HYSYS
extensions. 3-24
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-25
ww
Th3.6.3 Registering Extensions
Written in C# or VB.NET
To register an extension written in C# or VB.NET, use the
following procedure:
1. Start HYSYS. From the Tools menu, select Preferences
command. The Session Preferences property view opens.
2. Go to the Extensions tab and click the Register an
Extension button. This opens the Select an Extension to
be Registered property view.
3. Use the File Path group to find the directory in which the
DLL file is saved. Once you find the DLL file, select it and
click the OK button.
The Extensions tab should now appear similar to the figure
Figure 3.43-25
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-26 Extension Interface Details
ww
Thbelow.
You are now ready to use the extension in HYSYS.
3.7 Extension Interface
Details
Three types of extensions can currently be created for use
within HYSYS:
• Unit Operations
• Kinetic Reactions
• Property Packages
Each extension type is associated with a unique container
interface derived from the ExtnContainer object. For instance
Unit Operation Extensions have an ExtnUnitOperation interface.
3.7.1 ExtnContainer Interface
Each type of extension has a unique container associated with it.
Each container implements an interface that provides methods
Figure 3.53-26
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-27
ww
Thand properties for the extension.
Derived from Properties Methods
IDispatch • ExtensionInterface
• FPStatus
• OnOleEnabledThread
• SimulationCase
• StatusBar
• ClearStatusBar
• FindVariable
• OpenContainerStorage
• OpenView
• Trace
• WaitForTurn3-27
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-28 Extension Reaction Kinetics
ww
Th3.7.2 ExtensionObject
Interface
Every extension must implement the ExtensionObject interface.
This interface defines methods that are common to all HYSYS
extensions. No methods in this interface are mandatory; that is,
all methods may be ignored if the extension does not implement
them.
3.8 Extension Reaction
Kinetics
You can add your own Reaction Kinetics expressions to HYSYS
though the Reaction Kinetics Extension. These extensions
appear to the user like any other HYSYS reaction type.
Additionally, you can specify which components partake in the
expression, as well as define new properties for the reactants.
To implement an extension Kinetic Reaction, you must
implement two interfaces
The container for the extension supports the
ExtnKineticReactionContainer interface. This acts as the
interface to all the widgets and variables in the HYSYS standard
kinetic reaction property view.
Derived from Properties Methods
IDispatch none • OnHelp
• Save
• StatusQuery
• Terminate
• VariableChanged
• VariableChanging
Interface Description
ExtensionObject Called when reaction extension is added to the
simulation.
ExtnKineticReaction Called when the reaction extension is used.3-28
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-29
ww
ThThese previously described interfaces allow a reaction to be
implemented and associated with a HYSYS case through a fluid
package. The Reaction Extension also requires the definition of
two methods in order for the extension to be viable:
Method Description Details
Initialize The Initialize method is
called whenever the
extension is first added
or whenever a case
containing the
extension is reopened.
This is also the
procedure where you
would usually set the
state of the properties
and define the
reactants used.
ByVal Container as
ExtnUnitOperationContainer
The kinetic reaction container object.
ByVal IsRecalling as Boolean
Value related to the state of the extension. False if
created for the first time. True if there is an
existing extension.
Initialize as Long (Return Value)
Return value must be the current HYSYS build. A
constant extnCurrentVersion is provided in the
type library for this purpose.
ReactionRate Called when the
reaction extension is
used. The method is a
function that returns
true when successful
and false if an error
occurs. The calculation
involves returning a
rate value through the
‘Rate’ argument while
the HYSYS solver
iteratively calls the
ReactionRate method.
ByVal hyFluid as Fluid
Fluid based on the input stream to the operation.
ByVal RxnTemperatureInC as Double
Reaction Temperature in HYSYS internal units of
Celsius.
ByVal RxnVolumeInKmolPerM3 as Double
Reaction volume in HYSYS internal units of cubic
meters.
Rate as Double
Rate value, passed by reference, so its value can
manipulated and permanently altered within the
method.
ReactionRate as Boolean
True if rate could be calculated, False if there is an
error.3-29
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-30 Extension Reaction Kinetics
ww
ThExtension Definition Files
An extension definition file is required for the kinetic reaction
extension. Since HYSYS uses a specific interface for reaction
extensions, the property view within the EDF is not the primary
property view when the extension is accessed in HYSYS. If you
do create a customized property view in the View Editor, you can
access it through the View Extension Parameters button
found on the Parameters tab.
3.8.1 ExtnKineticReaction
Interface
The ExtnKineticReaction interface must be implemented by all
extension kinetic reactions. In addition to the Initialize and
Reaction Rate methods which are mandatory, the interface also
has the following associated properties and methods:
Figure 3.6
Derived from Properties Methods
IUnknown IsReady • BasisChanged
• ReactionRate23-30
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-31
ww
Th3.8.2 ExtnKineticReactionCont
ainer Interface
The ExtnKineticReactionContainer interface is passed to an
extension Kinetic Reaction in its Initialize method.
3.8.3 Kinetic Reaction Example
In this example, you use Visual Basic 5.0 to build a reaction
kinetics extension for a reaction involving vinyl acetate.
1. Create a new project in Visual Basic 5.0 from the New tab of
the New Project property view.
2. Select the ActiveX.DLL icon as the project type and click
the Open button.
Derived from Properties Methods
ExtnContainer • BaseReactant
• BasisConversion
• MaxTemperature
• MinTemperature
• Phase
• RateConversion
• Reactants
• ReactionBasis
• AddReactantProperty
• RemoveReactantProperty
• SetReactionPropertyState
ActiveXDLL icon3-31
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-32 Extension Reaction Kinetics
ww
Th3. Make sure that the HYSYS 3.* Type Library checkbox is
selected in the References property view, which is accessed
by selecting the References command from the Project
menu.
4. In the Properties tiled property view, ensure that the
Instancing drop-down list is set to 5-MultiUse.
5. In the Properties tiled property view, rename the class
module VinylAc.
6. Save the class and project by selecting Save Project
command from the File menu. Save the class and project as
VinylAc.cls and VinylAc.vbp
7. You are now ready to define the class. Begin by defining the
global variables in the Project VinylAc Code property view:
Figure 3.7
Code Explanation
Option Explicit Used to force explicit declaration of
all variables in that module.
Dim hyContainer As Object
Dim hyBulkDens As Object
Declare the global HYSYS objects.
The hy prefix is a convention to
identify variables which come from
HYSYS.
Properties property view3-32
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-33
ww
Th8. The first function declared is the Initialize function. It is
called when the extension is first added to HYSYS or when a
case containing the extension is loaded.
Code Explanation
Public Function Initialize(ByVal Container As
Object, ByVal IsRecalling As Boolean) As Long
Initialize is called when the extension is
first added to the simulation or when a
simulation case containing the extension
is loaded.
On Error GoTo ErrorTrap Enable Error trapping.
Dim hyReactant As Reactant Declare KineticReactionContainer
variable.
Initialize = extnCurrentVersion Reference the current HYSYS version
Set hyContainer = Container This reference lets the extension interact
with HYSYS through the extension
container, the
ExtnKineticReactionContainer object.
Methods from the ExtensionObject object
are also available.
Set hyBulkDens =
hyContainer.FindVariable("BulkDens").Variabl
e
Set an object reference to the BulkDens
variable, which is created in the EDF file.
If IsRecalling = False Then
hyBulkDens.Value = 2700
The variable IsRecalling is only False
when the extension is first added to the
simulation. This sets a default for
BulkDens (2700 kg catalyst/m3 reactor
volume).
hyContainer.Phase = ptVapourPhase
hyContainer.ReactionBasis =
rbPartialPressBasis
Setting the remaining reaction properties
(usually found on the Basis tab of the
Reaction property view). The Phase of
the reaction is to be Vapour and the
reaction Basis is to be Partial Pressure.
hyContainer.Reactants.RemoveAll This initializes the reactants list by
removing any reactants that may be
specified.
Set hyReactant =
hyContainer.Reactants.Add("Ethylene")
hyReactant.StoichiometricCoefficientValue
= -1
hyContainer.BaseReactant = hyReactant
Adds the component Ethylene as a
Reactant. It sets the stoichiometric
coefficient of ethylene as -1 (i.e., 1 mole
of ethylene being consumed). You are
also specifying ethylene to be the base
reactant.3-33
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-34 Extension Reaction Kinetics
ww
Th Set hyReactant =
hyContainer.Reactants.Add("AceticAcid")
hyReactant.StoichiometricCoefficientValue
= -1
Set hyReactant =
hyContainer.Reactants.Add("Oxygen")
hyReactant.StoichiometricCoefficientValue
= -0.5
Set hyReactant =
hyContainer.Reactants.Add("VinylAcetate")
hyReactant.StoichiometricCoefficientValue
= 1
Set hyReactant =
hyContainer.Reactants.Add("H2O")
hyReactant.StoichiometricCoefficientValue
= 1
Adds the remaining components and
specifies their stoichiometric coefficients.
hyContainer.BasisConversion = "psia" Sets the Basis Conversion units to psia.
The Rate Conversion units is left in
HYSYS internal units of kg mole/m3-s.
With hyContainer
.SetReactionPropertyState rpReactants,
vsCalculated
.SetReactionPropertyState
rpStoichiometricCoefficients, vsCalculated
.SetReactionPropertyState
rpMinTemperature, vsCalculated
.SetReactionPropertyState
rpMaxTemperature, vsCalculated
.SetReactionPropertyState
rpReactionBasis, vsCalculated
.SetReactionPropertyState
rpReactionPhase, vsCalculated
.SetReactionPropertyState
rpBaseReactant, vsCalculated
.SetReactionPropertyState
rpBasisConversion, vsCalculated
.SetReactionPropertyState
rpRateConversion, vsCalculated
End With
Sets the property states as Calculated so
that they cannot be modified.
The With statement is used for efficiency
since each line uses the
SetReactionPropertyState method of
the hyContainer object.
End If
ErrorTrap: Line to which the On Error statement
branches if an error occurs
End Function Signifies the end of the function. This line
does not need to be added.
Code Explanation3-34
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-35
ww
Th9. The other function that is required to implement a kinetic
reaction extension is the ReactionRate function.
Code Explanation
Public Function ReactionRate(ByVal Fluid As
Object, ByVal RxnTemperatureInC As Double,
ByVal RxnVolumeInKmolPerM3 As Double, rate As
Double) As Boolean
This function is called whenever the
extension is executed.
On Error GoTo ErrorTrap Enable Error trapping.
Dim TotalPressure As Double
Dim RxnTemperatureinK As Double
Dim EthyleneIndex As Integer
Dim AceticAcidIndex As Integer
Dim OxygenIndex As Integer
Dim WaterIndex As Integer
Dim ComponentFracs As Variant
Dim EthylenePP As Double
Dim AceticAcidPP As Double
Dim OxygenPP As Double
Dim WaterPP As Double
Declare local variables.
If hyBulkDens.Value <= 0 Then
hyBulkDens.Value = 2700
Check to see if the value of hyBulkDens >
0. If not, then sets it to the default value
of 2700 kg catalyst/m3 reactor volume.
TotalPressure =
Fluid.Pressure.GetValue("psia")
Gets the overall pressure of the reaction
in psia.
RxnTemperatureinK = RxnTemperatureInC +
273.15
Get the temperature of the reaction K.
EthyleneIndex =
Fluid.Components.Index("Ethylene")
AceticAcidIndex =
Fluid.Components.Index("AceticAcid")
OxygenIndex =
Fluid.Components.Index("Oxygen")
WaterIndex = Fluid.Components.Index("H2O")
Get component index numbers. These
index numbers are later used to
reference the components and their
properties.
ComponentFracs = Fluid.MolarFractionsValue Set ComponentFracs equal to the
component molar fractions of the fluid.
EthylenePP = ComponentFracs(EthyleneIndex) *
TotalPressure
AceticAcidPP =
ComponentFracs(AceticAcidIndex) *
TotalPressure
OxygenPP = ComponentFracs(OxygenIndex) *
TotalPressure
WaterPP = ComponentFracs(WaterIndex) *
TotalPressure
Get partial pressure of components in
psia by multiplying component mole
fraction by total pressure (Smith and Van
Ness, p. 300).3-35
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-36 Extension Reaction Kinetics
ww
Th10.Select Make VinylAc.dll command from the File menu. The
Make Project property view appears.
11.Select the folder you want to save the VinylAc.dll file in, and
click the OK button.
rate = 0.1036 * Exp(-3674 /
RxnTemperatureinK) * OxygenPP * EthylenePP *
AceticAcidPP * (1 + 1.7 * WaterPP) / ((1 +
0.583 * OxygenPP * (1 + 1.7 * WaterPP)) * (1 +
6.8 * AceticAcidPP)) * hyBulkDens.Value *
1000
Calculate the reaction rate1. The rate is in
g mol AceticAcid consumed/min-g
catalyst. hyBulkDens.Value is
multiplied by 1000 to convert it to g
catalyst/m3 reactor volume.
rate = rate / 1000 / 60 Since the units required by HYSYS are kg
mole/m3-s, divide by 1000 g mol/kg mol
and divide by 60 s/min.
ReactionRate = True Tell HYSYS that the calculation worked as
expected.
ErrorTrap: Line to which the On Error statement
branches if an error occurs.
End Function Signifies the end of the function. This line
does not need to be added.
Code Explanation
Figure 3.83-36
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-37
ww
ThCreating the Extension Definition File (EDF)
In order to complete the Kinetic Reaction Extension, you must
create an EDF. This is done through the Extension View Editor.
1. Open the Extension View Editor and open a new EDF by
doing one of the following:
• Select New command under the File menu in the menu
bar
• Use the hot key combination CTRL N
• Click the New File icon
The default View Manager property view appears as shown
below:
2. Click the Objects Manager icon to open the Objects
Manager property view.
3. In the ProgID/CLSID field enter RxnExtn.VinylAc as the
extension ID.
4. Enter an appropriate description for the extension in the
Description field, such as Vinyl Acetate Reaction
Extension as shown in Figure 3.10.
If it has been installed, the Extension View Editor is found in
the same launch point in the Start menu as HYSYS.
Figure 3.9
For more information on
installing and accessing
the View Editor, see
Section 4.1.1 -
Accessing the View
Editor.
New File icon
The file path in
the View File
group may be
different,
depending on
where you
installed HYSYS.
Objects Manager icon3-37
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-38 Extension Reaction Kinetics
ww
Th5. Select Kinetic Reaction as extension type in the Type drop-
down list.
6. Specify the information in the Variables of Selected Object
group as shown below, and select the Persistent checkbox.
7. Click the Close button. This returns you to the Views
Manager property view.
Figure 3.10
Figure 3.113-38
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-39
ww
Th8. From the Existing Views list, select the DefaultView and click
the Edit button. The DefaultView form appears. It consists of
several default objects that are not used in this example.
These objects have to be deleted.
9. Begin by deleting the Page Tabs widget. Select the tabs
found at the bottom of the DefaultView form as shown below
and press the DELETE key.
10.Delete the Name Static Text widget and the Object Name
Text Entry widget using the method described in the step
above.
11.Resize the DefaultView form into a smaller property view, as
shown below.
Figure 3.12
Figure 3.13
Page
Tabs
Static
Text
Text
Entry3-39
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-40 Extension Reaction Kinetics
ww
ThAdding Widgets to the DefaultView form
1. From the Widgets Palette select a Numerical Input widget.
2. Right-click, hold, and drag the widget into the DefaultView
form.
3. When you find an appropriate part of the property view to
place the widget, release the mouse button and the widget
should drop into place.
Use the drag and drop method described in the above steps
to add the two Static Text widgets and a Button widget as
shown below.
4. Now the widgets must be defined. To open a widget’s
properties do one of the following:
• Double-click on the widget
• Right-click the widget and select
Properties command from the Object Inspect menu,
where Widget Type would be Button for a Button widget.
Figure 3.143-40
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-41
ww
Th5. For the upper Static Text widget specify properties as shown
below. When you are finished click the OK button.
6. For the lower Static Text widget specify properties as shown
below. When you are finished click the OK button.
Figure 3.15
Figure 3.163-41
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-42 Extension Reaction Kinetics
ww
Th7. For the Numerical Input widget specify properties as shown
below. When you are finished click the OK button.
The Target Moniker field is specified by clicking the
Ellipsis icon associated with the field and selecting Bulk
Density from the Select Number Variable property view.
8. Open the Properties property view of the Button widget.
9. In the Label field specify the button label as &Close where
the & indicates the hot key underscore designation (in other
words, pressing ALT + hot key brings focus to this object).
10.Click the Ellipsis icon associated with the Message field
to open the Edit Messages property view.
Figure 3.173-42
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-43
ww
Th11.Click the Insert button on the Edit Messages property view.
The Select Message property view appears. Select the Close
the View message from the list.
12.Click the OK button to add this message to this button. The
Edit Messages property view appears as shown below.
13.Click the OK button on the Edit Messages property view to
close this property view and return to the Button Properties
property view.
Figure 3.18
Figure 3.193-43
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-44 Extension Reaction Kinetics
ww
Th14.Specify the Name field as shown below. When you are
finished click the OK button.
The property view now appears as shown below.
15.Select Save command from the File menu and save the EDF
file as “VinylAc.edf” in the same directory as the DLL file.
Attaching the Extension to HYSYS
You are now ready to attach the extension to HYSYS. The
following steps demonstrate how to attach an extension within
HYSYS.
1. Start HYSYS. From the Tools menu, select Preferences
command. The Session Preferences property view appears.
2. Go to the Extensions tab and click the Register an
Extension button. The Select an Extension to be Registered
property view appears.
Figure 3.20
Figure 3.213-44
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-45
ww
Th3. Use the File Path group to find the directory in which the
VinylAc.dll file is saved in. Once you find the DLL file, select
it and click the OK button.
4. The HYSYS Extension Registration property view appears
and displays whether the registration was successful or not.
Click the OK button to close the property view.
The Extensions tab should now appear similar to the figure
below.
Figure 3.22
Figure 3.233-45
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-46 Extension Property Packages
ww
Th5. You can now go to the Reactions tab of the Simulation Basis
Manager property view and add a VinylAcetate Reaction
Extension from the Reactions property view.
3.9 Extension Property
Packages
You can put your own physical property calculations into HYSYS
as an Extension Property Package, which appears to the user as
any other property package in the program.
HYSYS makes calls to property packages under a number of
different situations. Calls are made in both Steady State and
Dynamics mode.
To implement an Extension Property Package, you must
implement two interfaces:
Many different methods must be supported by Extension
Property Packages; however, depending on what functionality is
supported, certain methods may be left unimplemented. The
extension must let its container know which features it supports
through the ExtensionPPkgInit structure passed to the extension
in its Initialize method.
Figure 3.24
Interface Description
ExtensionObject Called when the property package extension
is added to the simulation.
ExtnPropertyPackage Called when the property package extension
is used.3-46
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-47
ww
ThThe ExtnPropertyPackage interface is not a dual interface; for
efficiency, non-ActiveX Automation compatible data types are
passed as parameters. This means that Extension Property
Packages cannot be easily written in Visual Basic, and cannot be
implemented as Local Servers.
Initialization
When an Extension Property Package is initialized, it must fill in
the ExtensionPPkgInit structure passed to it by its container.
This structure lets the container know which features the
extension supports, such as requirements for a component slate
and whether or not the property package can handle changes to
the component slate order.
An Extension Property Packages can be as simple as a steam
table, or as complex as an activity model or equation of state
package. HYSYS behaves differently for property packages of
differing functionality. For example, if a given property package
cannot handle hypothetical components, you are not allowed
access to the Oil Environment for that property package.
Component Slates
If the Extension Property Packages has a fixed component slate,
HYSYS pre-selects those components, and does not allow the
user to remove them or add other components. The extension
lets its container know of this restriction by setting the
NumberOfPreselectedComponents member of the
ExtensionPPkgInit structure to a non-zero value. HYSYS then
calls the extension's GetPreselectedCompIDs method at a later
point. If zero is passed for the
NumberOfPreselectedComponents member, HYSYS allows you
to select whatever components are available.
Filtering of the component list is done through the
implementation of the IsComponentAllowed method. This
method returns True if the component with the passed
ComponentID is supported by the property package, or False if
it is not. If the extension has a fixed component slate (that is, it 3-47
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-48 Extension Property Packages
ww
Thhas returned a non-zero for NumberOfPreselectedComponents),
the container handles the implementation of the
IsComponentAllowed method, allowing the extension developer
to return E_NOTIMPL for the method.
If the property package cannot handle changes to the
component slate, the CanExchangeComponents flag can be set
in the ExtensionPPkgInit structure. If this flag has been set,
HYSYS only allows you to add or remove components from the
end of the list.
ExtensionPPkgInit structure
This structure is passed to an Extension Property Packages in its
Initialize method. The extension must fill in the structure
according to its capabilities.
typedef struct
{
long StructSize;
long Version;
long NumberOfPreselectedComponents;
enum DynamicPropertyMethod DynPropMethod;
VARIANT_BOOL IsActivityModelType;
VARIANT_BOOL CanExchangeComponents;
VARIANT_BOOL CanCalculateFugacity;
VARIANT_BOOL CanCalculateLLE;
VARIANT_BOOL CanHandleOilHypos;
VARIANT_BOOL UseGFlashInDynamics;
VARIANT_BOOL CanHandleInsideOutPHFlash;
} ExtensionPPkgInit;
Data Member Details
StructSize This data member contains the size of the
ExtensionPPkgInit structure.
Version This data member must be filled in with
extnCurrentVersion.
NumberOfPreselectedComponents If the property package has a fixed component
slate, this number should be a non-zero value.
DynPropMethod This must be set to the type of Dynamic Property
Method to be used with the property package. See
DynamicPropertyMethod_enum in the type
library.3-48
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-49
ww
ThIsActivityModelType This should be set to True if the property package
can be considered an activity model property
package. A number of flash algorithms in HYSYS
optimize their algorithms based on the value of
this data member.
CanExchangeComponents This member should be set to True if the property
package can handle changes to the location of
components in the component slate.
CanCalculateFugacity This should be set to True if the property package
has implemented the ComputePhaseFugacities
method. If it is set to False, this method is never
called.
CanCalculateLLE This should be set to True if the property package
can calculate liquid-liquid equilibrium calculations
using the inside-out algorithm. If this is set to
True, the property package must implement the
ComputeHInnerParamsLL and ComputeKFactorsLL
methods.
CanHandleOilHypos If the property package can handle Oil
hypotheticals, this should be set to True. If it is set
to False, the user is not allowed in to the Oil
Environment.
UseGFlashInDynamics This flag is used to optimize thermodynamic
calculations in dynamics. If is recommended that
this be set to True unless the property package is
an equation of state.
CanHandleInsideOutPHFlash This flag disables the inside-out enthalpy flash if it
is set to False. It is recommended that this flag be
set to True unless the property package operates
on a narrow temperature range.
Data Member Details3-49
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-50 Extension Property Packages
ww
Th3.9.1 ExtnPPkgContainer
Interface
The ExtnPPkgContainer interface is passed to an Extension
Property Package in its Initialize method.
Derived from Properties Methods
ExtnContainer • NumberOfComponents
• BreakRequested
• ExtensionInterface
• FPStatus
• name
• OnOleEnabledThread
• SimulationCase
• StatusBar
• BuildPlot
• BuildPlot2
• BuildPlotWithCallback
• ClearStatusBar
• DeletePlot
• FindVariable
• GetComponent
• GetPlot
• GetPlot2
• OpenContainerStorage
• OpenView
• Trace
• WaitForTurn3-50
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-51
ww
Th3.9.2 ExtnPropertyPackage
Interface
The ExtnPropertyPackage interface must be implemented by all
Extension Property Packages. Only the Initialize method must
be supported, all others could return E_NOTIMPL.
Derived from Properties Methods
IUnknown none AddComponent
ComponentChanged
ComputeHInnerParamsLL
ComputeHInnerParamsVL
ComputeKFactors
ComputeKFactorsLL
ComputeKFactorsVL
ComputeLiquidMolarDensity
ComputeLiquidSurfaceTension
ComputePhaseActivity
ComputePhaseFugacities
ComputePhaseProperties
ComputePhaseThermalConductivity
ComputePhaseViscosity
CopyPropertyPackage
DynTreatComponentAsInert
EndBasisChange
ExchangeComponents
ExchangeTwoPhases
GetPreSelectedCompIDs
GuessBubblePointTemperature
Initialize
InitializeKFactors
IsComponentAllowed
OrderPhases
QueryEndBasisChange
RemoveComponent
StartBasisChange
The ExtnPropertyPackage interface is not a dual interface,
and methods of the interface will not be called through the
Dispatch Invoke mechanism.3-51
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-52 Extension Unit Operations
ww
Th3.10 Extension Unit
Operations
You can implement Unit Operation calculations in HYSYS by
creating an Extension Unit Operation.
To implement an Extension Unit Operation, you must implement
two interfaces:
These objects allow the unit operation to function in the HYSYS
environment. The minimum requirements for the Unit Operation
Extensions is the definition of two methods:
Interface Description
ExtensionObject Called when unit operation extension is added to
the simulation.
ExtnUnitOperation Called when the unit operation extension is used.
Method Description
Initialize The Initialize method is called whenever the extension is first
added or whenever a case containing the extension is reopened.
The Initialize method is a function that expects the current build
value of HYSYS to be returned. By referencing the HYSYS Type
Library it is possible to use the constant extnCurrentVersion to
return the proper build value.
The Initialize method passes two arguments when it is called.
The first argument is the extension container object. With the
extension container object, all the variables declared in the EDF
can be accessed. The second argument “IsRecalling” is used to
determine if the extension is being added for the first time or if
the case already contained the extension. This flag can be used
to set default values or to assure that the values specified by
the user are not overwritten by the default values.3-52
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-53
ww
ThExtension Definition Files
An extension definition file is required for the custom unit
operation’s visual interface within the HYSYS environment and
also for the object interface to the ActiveX Server DLL. Variables
that are used through the interface need to be declared in the
EDF.
3.10.1 ExtnUnitOperationCont
ainer Interface
The ExtnUnitOperationContainer interface is passed to an
extension Unit Operation in its Initialize method.
Execute Extension Unit Operations perform their calculations within their
Execute method. This method is called by the Steady State
Solver during the Execute Passes; it must not be called directly
by the extension.
The Execute method is called whenever a stream connected to
the extension is changed or when any of the variables marked
as trigger solve in the EDF are changed. HYSYS automatically
calls the Execute method and pass the Forgetting argument.
The Forgetting argument relates to how HYSYS solves based on
the degrees of freedom approach. Whenever a variable is
changed within HYSYS, all the values associated or utilizing that
value as a basis for calculation must be forgotten. This Forget
process propagates throughout the simulation model. It is a
good idea to check the Forgetting argument prior to executing
code. Especially if values that are forgotten are used in the
calculation. A forgotten value is set to the empty state, which,
for HYSYS is the number -32767.
Method Description
Derived from Properties Methods
ExtnContainer • BreakRequested
• ExtensionInterface
• Flowsheet
• FPStatus
• name
• OnOleEnabledThread
• SimulationCase
• StatusBar
AddSolverNotification
Balance
BuildPlot
BuildPlot2
BuildPlotWithCallback
ClearStatusBar
CreateFluid
DeletePlot
FindFluid
FindVariable
GetPlot
GetPlot2
OpenContainerStorage
OpenView
RemoveSolverNotification
SolveComplete
Trace
TriggerSolve3-53
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-54 Extension Unit Operations
ww
Th3.10.2 ExtnUnitOperation
Interface
The ExtnUnitOperation interface must be implemented by all
Extension Unit Operations. Only two methods (the Initialize
method and the Execute method) are mandatory.
3.10.3 Passes
Execute Passes
The Solver performs steady state calculations in two passes: the
Forget Pass and the Calculate Pass. Normally, extension Unit
Operations need not know which pass is underway, but an
IsForgetting parameter is passed to the extension's Execute
method so the extension can optimize calculations if necessary.
The Solver propagates information through the flowsheet via the
Solver Notification links that are set up when connections are
made between objects. Whenever a Unit Operation changes the
value of a variable within a linked object, that object's Execute
method is called. If that object then changes the value of a
variable in another object, the Solver then moves on to that
object.
The propagation of information is completed when no object can
calculate any new information, or if calculated values are within
a tolerance of the value previously calculated. When new values
are within the tolerance, the linked object does not have its
Execute method called.
If two objects calculate the same value in to an object, and
these values are not within the tolerance, an Inconsistency
Derived from Properties Methods
IDispatch none • BasisChanged
• Execute
• Initialize3-54
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-55
ww
Thcondition occurs. When this happens, the Solver stops and
switches in to Hold Mode. To allow different objects to calculate
different values because of changes in the flowsheet, it is
necessary that values that depend on another changing value be
forgotten. This forgetting occurs during the Forget Pass.
Forget Pass
When the value of a variable changes, the Solver first does one
Solve Pass on the flowsheet with the value marked as unknown.
Each object that is linked to the object with the changed variable
has its Execute method called, and the object must perform as
many calculations as it can with the remaining known
information.
Any calculations that were performed based on the value of the
newly forgotten variable in the last pass are not able to be
calculated during this pass. After the object has finished its
Execute call, the Solver then determines which variables the
object calculated last time that have not been touched this time.
These variables are then marked as unknown, and the Solver
propagates this information to other linked objects in the
flowsheet.
Normally, an object need not behave any differently during the
Forget Pass than during the Calculate Pass. In order to prevent
unnecessary propagation of forgotten information (and
therefore the unnecessary recalculation of this information in
the Calculate Pass), the object must still calculate all that it can
to ensure that the variables it calculated last time are touched.
Calculate Pass
After all information based on the previous value of a variable
has been forgotten, the new value is set in to the variable and
the second Solver pass (the Calculate Pass) is started. In this
pass, each object affected by the change in the variable has its
Execute method called. Any changes these objects make are
propagated through the flowsheet as the variables in other
objects are touched.3-55
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-56 Extension Unit Operations
ww
ThThe Execute method of an object can be called more than once
in either of the Solve Passes, as variables in the object are
touched by other objects in the flowsheet.
3.10.4 Extension Unit
Operation Example
In this example, you use Visual Basic 5.0 to build a unit
operation extension that saturates a feed stream with Water.
1. Open a new project in Visual Basic 5.0 and from the New
tab of the New Project property view select the ActiveX.DLL
icon and click the Open button.
2. Make sure that the HYSYS 3.* Type Library checkbox is
selected in the References property view, which is accessed
by selecting References command from the Project menu.
3. In the Properties tiled property view, rename the class
module Saturate, and ensure that the Instancing field is set
to 5-MultiUse.
Figure 3.25
ActiveXDLL icon
Properties tiled property
view3-56
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-57
ww
Th4. Rename the project name to UnitOpExtn as shown.
5. Save the class and project by selecting Save Project
command from the File menu. Save the class and project as
Saturate.cls and Saturate.vbp.
6. Begin by defining the global variables in the Project Code
Editor:
Figure 3.26
Code Explanation
Option Explicit Used to force explicit declaration of all variables in
that module.
Declare the global HYSYS objects. The hy prefix is
a convention to identify variables which come from
HYSYS.
Dim hyContainer As
ExtnUnitOperationContainer
• The extension unit operation container
object.
Dim hyFeedStrm As Object • The extension feed stream object.
Dim hyProdStrm As Object • The extension product stream object.
Dim hyWatStrm As Object • The extension water stream object.
Declare objects used internally:
Dim Components As Object • The HYSYS Components collection object.
Dim Component As Object • A single HYSYS Component object.
Dim WorkFluid As Object • A fluid object used for calculations.
Dim WatFluid As Object • A water fluid object.
Dim Streams(0 To 2) As Object • An array of ProcessStream objects.
Dim myOp As Object • Object reference to the Extension Interface.
Declare variables used internally:
Dim WaterPresent As Boolean • Indicates if water is present.3-57
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-58 Extension Unit Operations
ww
Th7. The first function declared is the Initialize function. It is
called when the extension is first added to HYSYS or when a
case containing the extension is loaded.
Dim H2O As Integer • The index for water.
Dim Temp As Variant • Temporary variable.
Dim MoleFl As Variant • Array of molar flows.
Dim Count As Integer • Count variable.
Dim i As Integer • Count variable.
Dim IsKnownFeedArray As Variant • Are the feed streams in the array valid.
Dim CalcError(0 to 1) As Boolean • Error level used to display status messages.
Dim IsIgnoredBool As Boolean • Indicates if the unit op is ignored.
Const conEmpty As Integer = -32767 • -32767 is used internally by HYSYS to
represent an empty value.
Code Explanation
Code Explanation
Public Function Initialize(ByVal Container As
Object, ByVal IsRecalling As Boolean) As Long
Initialize is called when the extension is
first added to the simulation or when a
simulation case containing the extension
is loaded.
On Error GoTo ErrorTrap Enable Error trapping.
CalcError(0) = False
CalcError(1) = False
Initialize variables.
Initialize = extnCurrentVersion Reference the current HYSYS version.
Set hyContainer = Container
Set myOp = hyContainer.ExtensionInterface
This reference lets the extension interact
with HYSYS through the extension
container, the
ExtnUnitOperationContainer object.
Methods from the ExtensionObject
object are also available.
Set Components =
hyContainer.Flowsheet.FluidPackage.Component
s
WaterPresent = False
For Each Component In Components
If Component.Name = "H2O" Then
WaterPresent = True
Next
If WaterPresent Then H2O =
Components.Index("H2O")
Get the list of components that are
currently attached to the fluid package.
For each component in the list, determine
if water is one of the components.
If water is present, determine the
internal index number of water.3-58
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-59
ww
Th8. The other function that is required to implement a Unit
Operation Extension is the Execute function.
Set hyFeedStrm =
hyContainer.FindVariable("FeedStream").Varia
ble.object
Set hyProdStrm =
hyContainer.FindVariable("ProductStream").Va
riable.object
Set hyWatStrm =
hyContainer.FindVariable("WaterStream").Vari
able.object
Set an object reference to the Feed,
Product and Water stream attachment
objects in the EDF.
If IsRecalling = False Then
End If
IsRecalling is False when the extension
is first added to the simulation,
IsRecalling is True when a saved
simulation case containing the extension
is loaded. The If statement uses
IsRecalling to set defaults. Saturate has
no default values, so none are set here.
ErrorTrap: Line to which the On Error statement
branches if an error occurs.
End Function Signifies the end of the function. This line
does not need to be added.
Code Explanation
Code Explanation
Public Sub Execute(ByVal Forgetting As Boolean) This sub-routine is called whenever the
extension is executed.
On Error GoTo ErrorTrap Enable Error trapping.
If Not Forgetting Then When a change is made to a variable
which affects the extension, HYSYS
performs a Forgetting pass and two
Calculation Passes. The Forgetting pass is
used to identify the streams, unit
operations, etc. affected by the change.
The first Calculation pass is used to allow
the extension to complete its internal
calculations. The second Calculation pass
is made so that external references made
by the extension use correct values. If
the extension makes no external
references, then the second pass can be
bypassed using the SolveComplete
method of the Container object. This
command is included later in the code.
For efficiency, no calculations are made
during the Forgetting pass.3-59
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-60 Extension Unit Operations
ww
Th Set Components =
hyContainer.Flowsheet.FluidPackage.Component
s
WaterPresent = False
For Each Component In Components
If Component.Name = "H2O" Then
WaterPresent = True
Next Component
If Not WaterPresent Then GoTo ErrorTrap
Determine if water is present (ensure it
hasn't been removed).
H2O = Components.Index("H2O") Get the index for water.
Set hyFeedStrm =
hyContainer.FindVariable("FeedStream").Varia
ble.object
Set hyProdStrm =
hyContainer.FindVariable("ProductStream").Va
riable.object
Set hyWatStrm =
hyContainer.FindVariable("WaterStream").Vari
able.object
Set an object reference to the Feed,
Product and Water stream attachment
objects in the EDF.
If hyFeedStrm Is Nothing Then GoTo
ErrorTrap
If hyWatStrm Is Nothing Then GoTo ErrorTrap
If hyProdStrm Is Nothing Then GoTo
ErrorTrap
If the streams are not attached, then
exit.
If hyFeedStrm.TemperatureValue = conEmpty
Then GoTo ErrorTrap
If hyFeedStrm.PressureValue = conEmpty
Then GoTo ErrorTrap
If hyFeedStrm.MolarFlowValue = conEmpty
Then GoTo ErrorTrap
Temp = hyFeedStrm.ComponentMolarFraction
If (Temp(0) = conEmpty) Then GoTo ErrorTrap
Determine if the feed stream has the
information required.
Set WorkFluid = hyFeedStrm.DuplicateFluid
MoleFl = WorkFluid.MolarFractionsValue
Create a duplicate fluid object of
hyFeedStrm and creates an array
containing the mole fraction of each
component in the fluid.
For i = 0 To Components.Count - 1
MoleFl(i) = MoleFl(i) / 10
Next
MoleFl(H2O) = 0.9 + MoleFl(H2O)
WorkFluid.MolarFractionsValue = MoleFl
For every component in the fluid, divide
the mole fraction by a factor of 10. This
means that the current composition of
the stream now only make up 10% of the
fluid composition. Make the remaining
90% water.
Code Explanation3-60
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-61
ww
Th WorkFluid.TPFlash
hyFeedStrm.TemperatureValue,
hyFeedStrm.PressureValue
If WorkFluid.FluidPhases.Count = 1 Then
CalcError(0) = True
GoTo ErrorTrap
End If
Do a TP Flash on the fluid at the
temperature and pressure of the stream
hyFeedStrm. If there is a second phase
then an error has occurred.
Temp = hyWatStrm.ComponentMolarFraction
If Temp(0) = conEmpty Then
MoleFl =
hyWatStrm.ComponentMolarFraction
Creates a temporary array containing the
component molar fraction values of the
stream object hyWatStrm (the water
stream).
If the mole fraction of the first component
in the stream is not specified, then do the
following:
For i = 0 To Components.Count - 1
MoleFl(i) = 0
Next i
MoleFl(H2O) = 1
Set the mole fraction of every component
in the temporary array to be zero. Then
set the mole fraction of water to be 1.
hyWatStrm.ComponentMolarFraction.Erase
hyWatStrm.ComponentMolarFraction.Calculate
MoleFl
Deletes the current component molar
fraction values of the stream
hyWatStrm. It then sets the component
fraction of the stream to the contents of
the temporary array MoleFl.
ElseIf Temp(H2O) = 0 Then
CalcError(1) = True
GoTo ErrorTrap
End If
Else if the mole fraction of water in the
stream hyWatStrm is zero then an error
has occurred.
With hyWatStrm
.Pressure.Erase
.Pressure.Calculate
hyFeedStrm.PressureValue
.Temperature.Erase
.Temperature.Calculate
hyFeedStrm.TemperatureValue
End With
Resets the water stream temperature and
pressure at the new molar composition.
If hyFeedStrm.MolarFlowValue = 0 Then
hyWatStrm.MolarFlow.Calculate 0
GoTo EndCalcs
End If
If the feed stream molar flow is 0 then
exit.
Set WorkFluid = hyFeedStrm.DuplicateFluid
Set WatFluid = hyWatStrm.DuplicateFluid
Count = 0
Creates a duplicate fluid of the feed and
water streams and sets the counter
variable Count to zero.
If WorkFluid.FluidPhases.Count > 1 Then
hyWatStrm.MolarFlow.Calculate 0
GoTo EndCalcs
End If
If the number of phases in the feed
stream fluid is greater than 1, then set
the molar flow of the water stream to
zero.
Code Explanation3-61
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-62 Extension Unit Operations
ww
Th Do While WorkFluid.FluidPhases.Count = 1
Count = Count + 1
Set WorkFluid =
hyFeedStrm.DuplicateFluid
WatFluid.MolarFlowValue =
WorkFluid.MolarFlowValue * (Count / 20)
WorkFluid.AddFluid WatFluid
WorkFluid.TPFlash
hyFeedStrm.TemperatureValue,
hyFeedStrm.PressureValue
Loop
Determine water stream flow required to
saturate feed stream.
While the number of phases in the feed
stream is still one, increase the molar
flow of the water stream. Add the feed
and water streams and reflash the
stream at the feed stream’s temperature
and pressure.
MoleFl =
WorkFluid.HeavyLiquidPhase.MolarFlowsValue
Set MoleFl to the values of the
component molar flows of the heavy
liquid phase of the fluid object WorkFluid.
Temp = WatFluid.MolarFlowValue -
MoleFl(H2O)
If Temp < 0 Then Temp = 0
hyWatStrm.MolarFlow.Calculate Temp
Set the variable Temp to be the
difference between the flow rate of the
water stream and component molar flow
rate of water in the heavy liquid phase of
the saturated stream. If the difference is
negative (i.e., no water is required), set
the molar flow rate of the water fluid to
zero.
EndCalcs: Begin the end calculations procedure.
WorkFluid.Erase
WatFluid.Erase
Erase contents of the fluid.
With hyProdStrm
.Pressure.Erase
.Pressure.Calculate
hyFeedStrm.PressureValue
.Temperature.Erase
.Temperature.Calculate
hyFeedStrm.TemperatureValue
End With
Set product stream temperature and
pressure values.
If hyFeedStrm.MolarFlowValue = 0 Then
hyProdStrm.ComponentMolarFraction.Calculate
hyFeedStrm.ComponentMolarFractionValue
hyProdStrm.MolarFlow.Calculate
hyFeedStrm.MolarFlowValue
If feed stream molar flow is 0 then
calculate product stream as feed stream.
Else
Set Streams(0) = hyFeedStrm
Set Streams(1) = hyWatStrm
Set Streams(2) = hyProdStrm
hyContainer.Balance btMoleBalance, 2,
Streams
End If
If feed stream molar flow is not 0, then
perform a mole balance.
Code Explanation3-62
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-63
ww
Th9. While the Initialize and Execute methods are required for the
implementation of the unit operation extension, it is strongly
recommended you also include a Status Query method that
accurately assesses how the extension is performing.
hyContainer.SolveComplete This line prevents a second Calculation
pass, because it is not required. See the
comment associated with the If Not
Forgetting Then line of code at the
beginning of the code. Read the section
on the SolveComplete method in
Extending HYSYS Help file for more
information.
CalcError(0) = False
CalcError(1) = False
End If
Reset error flags.
ErrorTrap: Line to which the On Error statement
branches if an error occurs.
End Sub Signifies the end of the sub-routine. This
line does not need to be added.
Code Explanation
Code Explanation
Public Sub StatusQuery(hyStatus As ObjectStatus) The StatusQuery sub-routine of the
extension is used to display appropriate
messages on the extension property view
(EDF file) in HYSYS. This sub-routine is
called whenever some change is made to
the extension, whether it is a result of a
solver pass or user interaction.
Dim OK As Boolean
OK = True
Declare and initialize the OK flag.
If WaterPresent = False Then
Call
hyStatus.AddStatusCondition(slMissingRequire
dInformation, 1, "Water is Required as a
Component")
OK = False
End If
If there is no water present in the fluid
package, an error message appears
telling you water is required.
If hyFeedStrm Is Nothing Then
Call
hyStatus.AddStatusCondition(slMissingRequire
dInformation, 2, "Feed Stream Required")
OK = False
End If
If there is no feed stream attached to the
unit op, an error message appears telling
you that a feed stream is required.3-63
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-64 Extension Unit Operations
ww
ThIf hyWatStrm Is Nothing Then
Call
hyStatus.AddStatusCondition(slMissingRequire
dInformation, 4, "Water Stream Required")
OK = False
End If
If there is no water stream attached to
the unit op, an error message appears
telling you that a water stream is
required.
If hyProdStrm Is Nothing Then
Call
hyStatus.AddStatusCondition(slMissingRequire
dInformation, 3, "Product Stream Required")
OK = False
End If
If there is no product stream attached to
the unit op, an error message appears
telling you that a product stream is
required.
If myOp.IsIgnored = True Then
Call
hyStatus.AddStatusCondition(slWarning, 11,
"Ignored")
OK = False
End If
If the Ignored checkbox is selected then
send an Ignored message to the status
bar.
If OK = False Then Exit Sub These next message can wait until the
connections are made so skip them.
If Not hyFeedStrm.Temperature.IsKnown Then
Call
hyStatus.AddStatusCondition(slMissingOptiona
lInformation, 5, "Unknown Feed Temperature")
OK = False
End If
If the feed stream temperature is not
known, then send an Unknown Feed
Temperature message to the status bar.
If Not hyFeedStrm.Pressure.IsKnown Then
Call
hyStatus.AddStatusCondition(slMissingOptiona
lInformation, 6, "Unknown Feed Pressure")
OK = False
End If
If the feed stream pressure is not known,
then send an Unknown Feed Pressure
message to the status bar.
If Not hyFeedStrm.MolarFlow.IsKnown Then
Call
hyStatus.AddStatusCondition(slMissingOptiona
lInformation, 7, "Unknown Feed Flow")
OK = False
End If
If the feed stream molar flow rate is not
known, then send an Unknown Feed Flow
message to the status bar.
Code Explanation3-64
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-65
ww
Th10.Select Make Saturate.dll command from the File menu.
Creating the Extension Definition File (EDF)
In order to complete the Unit Operation Extension, you must
create an EDF. This is done through the HYSYS Extension View
Editor.
1. Open the Extension View Editor. Open a new EDF by doing
one of the following:
• Select New command under File menu in the menu bar
• Use the hot key combination CTRL N
• Click the New File icon
IsKnownFeedArray =
hyFeedStrm.ComponentMolarFraction.IsKnown
If Not IsKnownFeedArray(0) Then
Call
hyStatus.AddStatusCondition(slMissingOptiona
lInformation, 8, "Unknown Feed Composition")
OK = False
End If
Check to see if the feed stream’s
composition has been set. If it has not,
an error message is sent to the status bar
indicating an Unknown Feed Composition.
If CalcError(0) Then
Call hyStatus.AddStatusCondition(slError,
9, "Feed Cannot be Saturated with Water")
OK = False
End If
If the first error flag has been tripped, it
sends a message to the status bar
indicating that the Feed Cannot be
Saturated with Water.
If CalcError(1) Then
Call hyStatus.AddStatusCondition(slError,
10, "Water is required in Water Stream")
OK = False
End If
If the second error flag has been tripped,
it sends a message to the status bar
indicating that Water is Required in the
Water Stream.
End Sub Signifies the end of the sub-routine. This
line does not need to be added.
Code Explanation
If it has been installed, the Extension View Editor is found in
the same launch point in the Start menu as HYSYS.
For more information on
installing and accessing
the View Editor, see
Section 4.1.1 -
Accessing the View
Editor.
New File icon3-65
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-66 Extension Unit Operations
ww
ThThe default View Editor should appear as shown below:
2. Click the Objects Manager icon to view the Objects
Manager property view.
3. In the ProgID/CLSID cell enter UnitOpExtn.Saturate as the
extension ID.
4. Enter an appropriate description for the extension in the
Description cell, such as Saturate Extension.
5. Select Unit Operation as the extension type in the Type
drop-down list.
6. In the Variables of Selected Object group declare the
following variables:
Figure 3.27
The file path in
the View File
group may be
different,
depending on
where you
installed HYSYS.
Objects Manager icon
Tag Description Type Persistent
Attachment
Type
Flow
Direction
N
Dimensions
FeedStream FeedStrm Attachment Active Material
Stream
Feed None
ProductStream ProductStrm Attachment Active Material
Stream
Product None
WaterStream WaterStrm Attachment Active Material
Stream
Feed None3-66
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-67
ww
ThThe Object Manager property view now appears similar to
the figure below.
7. Click the Close button. This returns you to the Views
Manager property view.
Figure 3.28
Figure 3.293-67
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-68 Extension Unit Operations
ww
Th8. From the Existing Views list, select DefaultView and click
the Edit button. The DefaultView form appears.
Defining the Tabs
1. To open the Properties property view of the Page Tabs
widget (or for any widget), do one of the following:
• Double-click on the widget
• Right-click the widget and select
Properties command from the Object Inspect menu,
where Widget Type would be Button for a Button widget.
2. The Page Tabs Properties property view appears. Click the
Ellipsis icon associated with the Target Moniker field.
Figure 3.303-68
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-69
ww
Th3. The Select Number Variable property view appears. From the
list select Current Page and click the OK button.
4. In the Label field of the Static Tabs group change the two
entries Page1 and Page2 to Connections and
Worksheet, respectively.
5. Close the Page Tabs Properties property view by clicking the
OK button.
6. Now controls must be added to the tabs. Open the Visibility
Manager property view by right-clicking the DefaultView
form background and selecting Open Visibility Manager
command from the Object Inspect menu.
Figure 3.31
Figure 3.323-69
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-70 Extension Unit Operations
ww
Th7. A default controller has already been set up for the page
tabs called PageController. Click the Edit button to view
the Visibility Controller Properties property view.
8. In the States matrix, you should notice two entries: Page1
and Page2. Rename these two states Connections and
Worksheet, respectively, to coordinate the states to
respective tab names.
9. Click the OK button to return to the Visibility Manager
property view.
The names of the two radio buttons that appear in the
PageController group have changed to the names of the two
page tabs.
Adding Widgets to Connections Tab
You are now ready to add widgets to the Connections tab on the
DefaultView form.
1. From the Widgets Palette select the Attachment Name
widget. Right-click, hold, and drag the widget on to the
DefaultView form. Move the widget to the left side of the
property view.
2. Add two more Attachment Name widgets to the property
view using the drag and drop method described in the step
above. Stagger the two widgets in the upper and lower
corners of the right side as shown in Figure 3.34.
Figure 3.333-70
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-71
ww
Th3. Place a Static Text widget above each Attachment Name
widget.
4. First the Feed widgets (i.e., the Attachment Name and Static
Text widget on the left) is defined. For the Feed Static Text
widget specify properties as shown below. When you are
finished click the OK button.
Figure 3.34
Figure 3.353-71
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-72 Extension Unit Operations
ww
Th5. For the Feed Attachment Name widget specify properties
as shown below. When you are finished click the OK button.
The Target Moniker field is specified by clicking the
Ellipsis icon associated with the field and selecting
FeedStrm from the Select Attachment property view.
6. For the Water Stream Static Text widget specify properties
as shown below. When you are finished click the OK button.
Figure 3.36
Figure 3.373-72
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-73
ww
Th7. For the Water Attachment Name widget specify properties
as shown below. When you are finished click the OK button.
The Target Moniker field is specified by clicking the Ellipsis
icon associated with the field and selecting WaterStrm
from the Select Attachment property view.
8. For the Product Stream Static Text widget specify
properties as shown below. When you are finished click the
OK button.
Figure 3.38
Figure 3.393-73
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-74 Extension Unit Operations
ww
Th9. For the Product Attachment Name widget specify
properties as shown below. When you are finished click the
OK button.
The Target Moniker field is specified by clicking the
Ellipsis icon associated with the field and selecting
ProductStrm from the Select Attachment property view.
The DefaultView form now appears as shown in the figure
below.
Figure 3.40
Figure 3.413-74
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-75
ww
ThAdding Widgets to Worksheet Tab
The next step is to add widgets to the Worksheet tab on the
DefaultView form.
1. In the Visibility Manager property view, select the
Worksheet radio button.
To open the Visibility Manager property view, right-click the
DefaultView form background and select Open Visibility
Manager command from the Object Inspect menu.
2. Insert a Matrix widget on the Worksheet tab. Resize the
widget so that about 1 cm space appears between the
matrix and tab borders.
3. Open the Matrix Properties property view. In the Fly By field
enter Properties of connected streams.
4. In the Cells group change the value in the Width field to 46
and the value in the Wrap field to 2.
5. In the Labels group set the Labels drop-down list to Row,
the Show Units drop-down list to Row, and the Left Width
field to 74.
Figure 3.423-75
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-76 Extension Unit Operations
ww
Th6. Select the Vertical Direction checkbox. The Matrix
Properties property view should appear similar to the figure
below.
7. The Data Set list should contain a default data set. Click the
Insert button to open the Select a Data Type property view
and add a new data set to the list.
8. On the Select a Data Type property view, select Text as the
data type and click the OK button.
9. A Text Data Set Properties property view appears. Change
the name of the data set to WRKName.
10.Click the Ellipsis icon associated with the Moniker field to
open the Select Text Variable property view.
11.On the Select Text Variable property view, select
WaterStrm from the Base Object drop-down list.
Figure 3.43
Figure 3.443-76
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-77
ww
Th12. From the list select Object Name as shown in the figure
below and click the OK button.
13. The Select Text Variable property view closes, and you are
returned to the Text Data Set Properties property view.
14. In the Label group enter Name as the label associated with
field and click the OK button to close the Data Set Properties
property view.
15. Insert a Numeric data set as described in the above steps
#7 and #8.
16.A Numeric Data Set Properties property view appears.
Change the name of the data set to WRKFlow.
17.Click the Ellipsis icon associated with the Moniker field to
open the Select Number Variable property view.
18.On the Select Number Variable property view, select
WaterStrm from the Base Object drop-down list.
Figure 3.45
Figure 3.463-77
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-78 Extension Unit Operations
ww
Th19. From the list select Molar Flow and click the OK button.
The Select Number Variable property view closes, and you
are returned to the Numeric Data Set Properties property
view.
20. In the Label group enter Molar Flow as the label associated
with field and click the OK button to close the Numeric Data
Set Properties property view.
21.Click the OK button on the Matrix Properties property view
to close the property view. The DefaultView form appears
similar to the figure shown below.
Other data sets can be added for other streams and other
stream properties, however for the sake of brevity, these are
Figure 3.47
Figure 3.483-78
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extensibility 3-79
ww
Ththe only two cells defined.
22.Select Save command from the File menu and save the EDF
as Saturate.edf in the same directory as the DLL file.
Attaching the Extension to HYSYS
You are now ready to attach the extension to HYSYS. The
following steps demonstrates how to attach an extension within
HYSYS.
1. Start HYSYS. From the Tools menu, select Preferences
command. The Session Preferences property view appears.
2. Go to the Extensions tab and click the Register an
Extension button. The Select an Extension to be Registered
property view appears.
3. Use the File Path group to find the directory in which the
Saturate.dll file is saved in. Once you find the DLL, select it
and click the OK button.
The Extensions tab now appears similar to the figure below.
Figure 3.493-79
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
3-80 References
ww
Th4. You can now go in to the main Simulation environment and
from the UnitOps property view find the Saturate
Extension in the Available Unit Operations list.
3.11 References
1 "An Industrial Design/Control Study for the Vinyl Acetate Monomer
Process", Luyben & Tyreus, p.4.
Figure 3.503-80
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-1
ww
Th4 Extension View Editorw.cadfamily.com EMa
e document is for study 4.1 Introduction................................................................................... 3
4.1.1 Accessing the View Editor.......................................................... 4
4.1.2 Creating a New EDF File ............................................................ 5
4.1.3 Editing an Existing EDF File........................................................ 8
4.2 Using the View Editor..................................................................... 8
4.2.1 Manipulating Widgets................................................................ 8
4.2.2 DefaultView Form Toolbar........................................................ 11
4.2.3 Visibility Manager ................................................................... 16
4.2.4 Objects Manager Property View................................................ 23
4.2.5 Views Manager ...................................................................... 27
4.3 Widget Properties ........................................................................ 28
4.3.1 Common Widget Properties ..................................................... 32
4.3.2 DefaultView Form Object ......................................................... 34
4.3.3 Button Widget ....................................................................... 38
4.3.4 Static Text Widget .................................................................. 40
4.3.5 Text Entry Widget................................................................... 42
4.3.6 Rich Text Entry Widget............................................................ 44
4.3.7 Format Entry Widget............................................................... 45
4.3.8 Numerical Input Widget .......................................................... 46
4.3.9 Matrix Widget ........................................................................ 47
4.3.10 Checkbox Widget.................................................................. 56
4.3.11 Radio Buttons Widget............................................................ 57
4.3.12 Graphic Button Widget .......................................................... 59
4.3.13 Group Widget....................................................................... 62
4.3.14 Page Tabs Widget ................................................................. 63
4.3.15 Ply Picker Widget.................................................................. 65
4.3.16 Attachment Name Widget ...................................................... 67
4.3.17 Enumeration Widget ............................................................. 694-1
il:cadserv21@hotmail.com
only,if tort to your rights,please inform us,we will delete
4-2 Extension View Editor
www.cadfamily.com EMa
The document is for study 4.3.18 Unit Enumeration Widget........................................................70
4.3.19 Text List Widget ....................................................................72
4.3.20 Enumeration List Widget ........................................................74
4.3.21 Attachment List Widget ..........................................................77
4.3.22 Level Widget.........................................................................80
4.3.23 Plot Widget...........................................................................83
4.3.24 Worksheet Matrix Widget........................................................84
4.3.25 ACTIVEX Container Widget .....................................................874-2
il:cadserv21@hotmail.com
only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-3
ww
Th4.1 Introduction
The View Editor can be used to create or modify Extension
Definition Files (*.edf). Users that are accessing the automation
and extension capabilities of HYSYS generally make use of EDF
files. The extension definition file acts as the interface view
within HYSYS as well as the point for variable declaration and
storage.
Figure 4.14-3
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-4 Introduction
ww
Th4.1.1 Accessing the View
Editor
Access to the View Editor is provided with each commercial
release of HYSYS. However, it is not available unless you have
selected the Extension SDK option during the HYSYS
installation.
During the installation procedure, HYSYS adds the viewed.exe
application to the directory that currently holds your HYSYS
files. You can access the View Editor by either:
• Selecting the View Editor option in the Start menu
where it should reside in the same launch group as
HYSYS.
• Finding the directory name used to store your HYSYS
files and double-clicking on viewed.exe in File Manager
or Windows Explorer.
Figure 4.2
The Extension Development SDK files option is not activated
by default as it requires additional hard drive space.4-4
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-5
ww
ThThe View Editor appears as shown below:
You can now either open an existing EDF or create a new EDF.
4.1.2 Creating a New EDF File
Once the View Editor has been accessed, you can create a EDF
by following this simple procedure:
1. Do one of the following:
• Select New command under File menu in the menu bar
• Use the hot key combination CTRL N
• Click the New File icon
Figure 4.3
New File icon4-5
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-6 Introduction
ww
ThThe Views Manager property view and the Widgets Palette
appears as shown in the figure below.
Figure 4.44-6
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-7
ww
Th2. Assuming, at this time, that only one property view exists
for this EDF file, click the Edit button to open the
DefaultView form.
The DefaultView form contains three widgets: Text Entry
widget, Static Text widget, and Page Tabs widget.
3. Delete these widgets if you do not require them. To delete a
widget, simply click on the widget and do either of the
following:
• Right-click the widget and select the Delete command
from the Object Inspect menu.
• Press the DELETE key.
4. Place the widgets you want on the DefaultView form and, if
needed, modify the widget properties.
5. Move and resize the widgets if required.
6. Save your work by clicking the Save View File icon and
providing an appropriate name for the EDF file.
Figure 4.5
Save View File icon4-7
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-8 Using the View Editor
ww
Th4.1.3 Editing an Existing EDF
File
1. To open an existing EDF file, do one of the following:
• Select Open under File in the menu bar.
• Use the hot key combination CTRL O.
• Click the Open View File icon.
2. Select the EDF file from the Open View File property view
and click the Open button.
3. Edit the EDF file and save the file before exiting the program.
4.2 Using the View Editor
4.2.1 Manipulating Widgets
Adding Widgets
You can add a widget to your property view by using the
following procedure:
1. Select the widget you want to add in the Widgets Palette.
2. Right-click, hold, and drag the widget to the location on the
property view where you want to place it.
3. When the widget can be properly placed on the property
view, the cursor changes to a Bull’s Eye. Release the mouse
button and the widget appears on the property view.
The default sized widget appears on the DefaultView form where
you released the mouse button. Re-sizing handles are shown
around the border of the widget, when the widget is selected.
To edit an existing file, its ‘write’ attribute must be enabled
(it cannot be read-only).
Open File icon
Drag Cursor
Bull’s Eye Cursor4-8
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-9
ww
ThAlternate Approach
An alternate approach to the above steps #2 through #3 is to
select the Lock checkbox found at the bottom of the Widgets
Palette. Once the option is activated, the mouse cursor changes
in to a cross-hair cursor whenever the mouse cursor is placed
over the DefaultView form. You can then use the cross-hair
cursor to draw the currently selected widget in the Widget
Palette by clicking and dragging the cursor in the DefaultView
form.
With the Lock checkbox selected, you can add multiple widgets
of the same type simply by clicking on the DefaultView form
multiple times.
Figure 4.64-9
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-10 Using the View Editor
ww
ThDeleting a Widget
To delete a widget simply select the widget and do one of the
following:
• Press the DELETE key.
• Right-click the widget and from the resulting Object
Inspect menu, select the Delete
command.
Re-sizing a Widget
To re-size the widget using the mouse:
1. Select the widget.
2. Place the cursor over one of the re-sizing handles.
3. Hold down the primary mouse button and drag in one of the
directions indicated by the double-headed arrow.
You can also select multiple widgets by dragging a frame around
the widgets of choice or by selecting individual widgets while
holding down the CTRL key. You can then simultaneously resize
Notice the cursor changes to a double-headed arrow.
Figure 4.74-10
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-11
ww
Thall selected widgets by resizing the anchor widget, which is the
widget displayed with the resizing handles.
To re-size the widget using the Properties property view:
1. Open the widget’s Properties property view.
2. On the widget’s Properties property view, enter the new
width and height of the widget in the XY table shown in the
figure below.
Moving a Widget
To move a widget:
1. Select a widget.
You can also select multiple widgets by dragging a frame
around the widgets of choice or by selecting individual
widgets while holding down the CTRL key.
2. Hold down the primary mouse button and drag the widget to
a new location.
4.2.2 DefaultView Form
Toolbar
When you are creating a new property view or editing an
existing property view, there is a toolbar containing buttons on
the DefaultView form. These buttons can be used to access
some of the widget properties without opening the particular
widget property view.
Figure 4.8
You can also move the widget by
entering new coordinate values in the
Position row.4-11
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-12 Using the View Editor
ww
ThActive Location Settings
Tab Order Icon
When this icon is clicked, an integer value appears over each
widget on the DefaultView form that can capture the focus. The
sequence of the integer values determines the order in which
the widgets attain the focus when the TAB key is pressed.
As widgets are placed on the DefaultView form, the View Editor
assigns the next available integer value to the new widget. It is
possible for you to change the tab order that is assigned to the
widgets.
A HYSYS valve property view is shown in the figure below and it
is used to demonstrate the re-arranging of the tab order.
The tab order is indicated by the integer values in the black dots
covering the widgets. From the Name field (#6), pressing TAB
moves the focus to the Ignored checkbox (#7), then to the
Delete button (#8) and so on.
Notice that static text widgets such as Name, Inlet and Outlet
also receive tab order values. These values should always be
Figure 4.9
Tab Order icon4-12
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-13
ww
Thone below the value on the widget with which the static text is
associated. This enables the associated widget to get the focus
when the static text hot key is pressed. For example, when the
user presses ALT N, the focus should be in the text entry cell
where the name can be input. Since the static text Name widget
(#5) cannot accept the focus, the next integer value is used
(#6).
There are two approaches to changing the tab order. You can
click either the Select #1 or the Select Sequentially button. The
following sections describe each buttons in detail.
Select #1 Button
When you click this button, the View Editor allows you to select
a different widget to carry the value #1 in the tab order. When a
new #1 is selected, the tab order remains the same, but the
integer values are rotated to accommodate the new #1
selection.
For example, if you clicked the Select #1 button for the
valve property view shown previously, and then selected the
Text Entry Outlet widget (current #3), this widget would
become #1.
Figure 4.104-13
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-14 Using the View Editor
ww
ThAll other widgets would have their integer values increase by
1 with the old #1, the Static Text Inlet widget, becoming #8.
If this new order was not what you wanted, you could continue
with a user selected order. Notice the Select Sequentially button
has changed to a selected Select #2 button. So you can select
the widget that you would like to be #2 in the tab order. After
you select a widget to by #2, the Select #2 button changes to
Select #3 button. So you can choose the #3 widget in the tab
order. The sequence number button increase with each selection
until the highest number has been designated to a widget.
When the highest number (like number 9 from the figure above)
has been designated, the sequence number goes back to #1
and you can resequence the property view again. You can keep
resequencing the tab order until the Tab Order icon is clicked
again or the property view is closed.
Select Sequentially Button
When you click the Select Sequentially button, the View Editor
allows you to select a current widget tab order value which
begins the sequence of values for changes. For instance, if you
clicked this button and then clicked the #4 widget, the Select
Sequentially button would change in to a Select #5 button. Once
you selected the widget that you would like to be #5 in the tab
order, the button would change to a Select #6 button. This
continues until the Tab Order icon is clicked again or the
property view is closed.
Sizing Icons
• Stretch Width
Clicking the Stretch Width icon toggles the X-direction
Stretch checkbox (found in the widget’s Properties
property view) for the selected widget. When the
Stretch checkbox is selected, the width of the widget
increases as the DefaultView form is expanded
horizontally. Stretching is related to the Tie To Corner
and the Tie Reference properties.
Stretch Width icon4-14
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-15
ww
Th• Stretch Height
Clicking the Stretch Height icon toggles the Y-
direction Stretch checkbox (found in the widget’s
Properties property view) for the selected widget. This
icon is disabled for those widgets that are not designed
to stretch vertically (vertically-challenged widgets).
When the Stretch checkbox is selected, the height of the
widget increases as the DefaultView form is expanded
vertically. Stretching is related to the Tie To Corner and
the Tie Reference properties.
Alignment Icons
These icons are disabled unless you select multiple widgets on a
DefaultView form. The icons that become available depends on
the orientation of the widgets that you have selected.
For instance, if you select two static text widgets, one being
below the other, the icons that become available allow you to
choose a left, centre or right alignment according to the widget
that is chosen as the anchor widget.
The anchor widget is the widget that serves as the basis for
alignment and is identified by the resizing handles around its
outline. The other widgets in the group selection become the
widgets that are moved. To change the anchor widget, simply
select another of the selected widgets. This changes the
selected widget’s outline from the solid black line to a thinner
outline with resizing handles.
Figure 4.11
Stretch Height icon
In the property view shown on the left, Object B is the anchor
widget. When the Align to Top icon is clicked, Object A is aligned
to the top of Object B resulting in the property view on the right.
If you wanted to align Object B to A you would select Object A
again and Object A would become the anchor widget.4-15
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-16 Using the View Editor
ww
ThThe Alignment icons that are available:
4.2.3 Visibility Manager
The Visibility Manager is used when you want to show or hide
certain parts of your property view at specific times. In other
words, it allows you to discretely select what is to be shown
based on the conditions of the property view (i.e., static - done
by the view designer) or the state of the application (i.e.,
dynamic - manipulated through code).
Name Description Icon
Align to Left Lines up the selected widgets according to the
leftmost point of the anchor widget.
Align to
Right
Lines up the selected widgets according to the
rightmost point of the anchor widget.
Align to Top Lines up the selected widgets according to the
topmost point of the anchor widget.
Align to
Bottom
Lines up the selected widgets according to the
bottommost point of the anchor widget.
Align at
Centre
There are two of these icons, although only one is
shown at any given time. The one that appears
depend on the orientation of the selected widgets.
Clicking the icon lines up the selected widgets
according to the centre point of the anchor widget,
either in a vertical (X-axis centre point) or
horizontal (Y-axis centre point) fashion, depending
on the icon being shown.
Equally
Space
There are two of these icons, although only one is
shown at any given time. The one that appears
depend on the orientation of the selected widgets.
For this icon to become available, at least three
widgets must be selected. Clicking the icon
vertically or horizontally spaces the widgets,
depending on the icon being shown.4-16
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-17
ww
ThFor instance, many HYSYS property views have tabs along the
lower part of the property view which enable different
information to be grouped and shown at different times. When
the second tab on a property view is selected, the information
from the first tab is typically hidden and the information specific
to the second tab is shown.
Although the Visibility Manager is used mainly with tabs, it can
be used with other widgets. Other selection devices, such as
radio buttons and checkboxes can prompt the use of this tool to
selectively show and hide information.
The Visibility Manager can be accessed by right-clicking
anywhere on the DefaultView form and selecting the Open
Visibility Manager command from the Object Inspect menu.
The Visibility Manager largely consists of the Create Controller
button and the controls you have created. A control is denoted
by the presence of a group containing an Edit and Delete button.
Each control allows you to create States, or instances when
widgets or events occur. The default property view of the
Visibility Manager, shown in the figure below, consists of a
default PageController control which controls the visibility of the
two tabs.
Figure 4.12
Figure 4.134-17
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-18 Using the View Editor
ww
ThAn example, if you were to select the Page2 radio button, you
would see the Page 2 tab. Only the widgets placed on this tab
would automatically set to be visible on the tab in the
DefaultView form.
Clicking the Create Controller button adds a new controller
group to the Visibility Manager property view. The name of the
control is the name shared by the group. You can delete a
controller by clicking the Delete button associated with the
controller group. You can also edit the controller by clicking the
Edit button.
Clicking the Edit button opens the Visibility Controller Properties
property view.
The Visibility Controller Properties property view is where
individual object states are set. The property view consists of 10
objects:
Figure 4.14
Object Description
Name The controller name. The name entered in to this field is
the name of that appears in the Visibility Manager.
Moniker Clicking the Ellipsis icon associated with this field,
opens the Select Number Variable property view. You can
select the moniker type you want to associate to the
controller using the Select Number Variable property view.
Visibility Manager
property view
Refer to Moniker
Specification sub-
section from Section 4.3
- Widget Properties for
more information.4-18
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-19
ww
ThUsing Tabs
A property view created through the View Editor can contain
multiple tabbed sections within the same property view. Double-
clicking on the tabs of a property view opens the tab Properties
property view. Labels are added for each new tab to be
displayed.
1. To add a tab to a property view, right-click, hold, and drag
the Page Tab widget from the Widget Palette into the
DefaultView form.
2. Resize the tab size to your specifications.
States This group has three different fields that require
specification:
• Name. The name of the state. This appears as a radio
button in the controller group on the Visibility Manager
property view.
• Low. The low value for the state.
• High. The high value for the state.
Insert State Click this button to add a new state to the list.
Delete State Select a state and click this button to delete the currently
selected state.
Apply Click this button to apply any changes made on the
Properties property view to the Visibility Manager property
view.
Select
Widgets
Click this button to open the Visibility Controller Widget
Selections property view which allows you to associate
widgets with the state.
Activation Click this button to open the Visibility Controller Activation
property view which allows you to create a hierarchy of
visibility states.
Figure 4.15
Object Description4-19
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-20 Using the View Editor
ww
Th3. Right-click the DefaultView form background and select
Open Visibility Manager command from the Object
Inspect menu.
4. The Visibility Manager property view appears. Click the
Create Controller button.
5. A VisController group appears above the Page Controller
group as shown in the figure below.
6. Click the Edit button in the VisController group, to open the
Visibility Controller Properties property view.
7. Click the Ellipsis icon associated with Moniker field to
open the Select Number Variable property view.
Figure 4.16
Figure 4.17
Page Tabs Object Inspect
menu4-20
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-21
ww
Th8. Select Current Page from the list in the Select Number
Variable property view, and click the OK button.
9. Enter a name for the first tab in the Name column of the
States group.
10.Enter an integer value in the Low and High cells beside the
Name cell from the above step. The integer value for both
Low and High cells have to be the same.
If the values entered for the Low and High cells is not for the
first tab, increment the values by one for each tabbed sheet
(i.e., High and Low for first tab is 0, High and Low for second
tab is 1).
Figure 4.18
Figure 4.194-21
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-22 Using the View Editor
ww
Th11.Repeat #9 and #10 for each tab.
12.Click the Select Widgets button. Select the checkbox under
the appropriate tab name for each widget that appears only
on that tab. For widgets that appears on all tabs, do not
select any checkboxes.
High and Low Integer Values
The values for High and Low in the Visibility Controller
Properties property view do not always have to be the same.
You can use the Visibility Manager to selectively show widgets
according to values in the application. For example, if you want
to show a static text widget when the pressure of a specific
stream was between 150 and 200 kPa, you could specify the
moniker representing the stream pressure in the Moniker field of
the Visibility Controller Properties property view and then use
the Low and High cells to specify the pressure range.
It is required that the High/Low values provided (in #10) for
each tab match the Value for each tab in the Static Tabs
group of the tab Properties property view. It is highly
recommended that you match the tab Name (#9) in the
Visibility Controller Properties property view with the Label
in the tab Properties property view.
Figure 4.204-22
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-23
ww
Th4.2.4 Objects Manager
Property View
The Objects Manager provides a property view in which you can
enter crucial information related to extensions. This information
is used to register an extension properly and to declare the
variables and objects used by the extension.
You can access the Objects Manager property view by either:
• Clicking the Objects Manager icon on the Views
Manager property view.
• Selecting Objects Manager under View in the menu
bar.
Objects Manager icon
Figure 4.21
The Object Manager
property view consists
of:
• the Object
Definition matrix
• the Attributes of
Selected Object
group
• the Variables of
Selected Object
group4-23
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-24 Using the View Editor
ww
ThObject Definition Matrix
The Object Definition matrix consists of four columns:
Attributes of Selected Object Group
The Attributes of Selected Object group allows you to transfer
the attributes of operation types to your unit operation
extension. This allows you to find your extension unit operation
not only under the Extension categories but also under the
category of the operation whose attributes you have selected.
For instance if you add the attributes of the Reactor to your
extension, when you want to find your extension in the UnitOps
property view, you are able find it by selecting either the
Reactors or Extensions radio buttons.
Column Description
ProgID/
CLSID
The entry in this cell identifies the name of the object that
owns the property views shown in the Existing Views group
of the Views Manager property view.
This information must match what is in the registry and is
used by HYSYS to access the proper DLL file.
Description This is the text that appears in the appropriate location
within HYSYS in order to select the extension.
Type This specifies the type of extension. The choices include:
• Unit Operation
• Property Package
• Kinetic Reaction
• Exchanger Design, Base
• Exchanger Design, End Point
• Exchanger Design, Simple
• Exchanger Design, Weighted
• DeltaP (Pressure Drop) Correlation
• Sim Case Translator
• ExternalAddIn
• Pipe Deposition Correlation
• Property Balance
This selection impacts the list of internal AspenTech
variables that are visible when the Ellipsis icon is
clicked on a widget Properties property view.
Views The number of property views associated with this
extension.4-24
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-25
ww
ThVariables of Selected Object Group
In the Variables of Selected Object group, you can specify all
variable-related information for the selected object in the
ProgID/CLSID cell. Once these variables are created, you can
use them as monikers to associate a particular variable with a
widget on your property view. Variables are defined in the table
that contains three columns:
The group also consists of several additional objects that,
depending on the type of the currently selected variable in the
matrix:
Column Description
Tag Represents the internal name of the variable that is stored to
disk (usually input as the same as Name). You cannot have 2
identical tags for the same object.
Name Represents the variable name which is visible on property
views in the program (usually the same as Tag). This name
should be unique such that you can identify it in the program.
Unlike the Tag, spaces are allowed in this text string.
Type Variable types include:
• Real Number. Numeric variable for which you can
specify the dimensions and unit type.
• Enumeration. A related set of identifiers, each of which
is associated with an integer value; you can specify the
dimensions and create the enumeration through the
Enumeration Values button.
• Text. A string variable for which you can specify the
dimensions.
• Attachment. Represents a variable associated with an
object that is attached to another object (i.e., a feed
stream is attached to the inlet of a pump, so the feed
stream name is of type Attachment); allows you to
specify the dimensions, attachment type and flow
direction.
• Message. A variable holding information passed when a
button is clicked.
Object Description
Persistent Select this checkbox if you want this variable value to be
saved with the simulation case. Pertains to all variables
except Message variables.
Triggers
Solve
Select this checkbox if you want changes in the variable to
set off a smart solve (solve whatever needs to be solved).
The checkbox is enabled for all variables ONLY when the
object in question is a Unit Operation. For Real Number and
Enumeration types, this checkbox is selected by default.4-25
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-26 Using the View Editor
ww
ThAttachment
Type
For Attachment variables, you can specify the attachment
type as one of the following:
• Stream. Generic specification, implying that the
stream can be either material or energy.
• Material Stream. The attachment is a material
stream and cannot be an energy stream.
• Energy Stream. The attachment is an energy stream
and cannot be a material stream.
Flow
Direction
The choice for Flow Direction impacts the PFD in its
presentation of nozzles for unit operations in Attach Mode.
For Attachment variables, you can specify the flow direction
as one of the following:
• Unknown. The PFD does not know until run-time if
the attachment is a feed or product; depends if the
attachment is already attached to something.
• Feed. Only feed nozzles are presented by the PFD.
• Product. Only product nozzles are presented by the
PFD.
Numeric
Type
For variables of type Real Number, a unit type can be
specified. This guarantees that the appropriate value
appears by the property view according to the user
specified unit set.
N
Dimensions
For all variable types except Message, the variable
dimensions can be specified as one of the following:
• None. Single value.
• Vector. One dimensional array.
• Matrix. Two dimensional array.
• Cube. Three dimensional array.
Only the Real Number variable type has access to all
dimension types. The other variable types have access to
only None and Vector.
Enumeration
Values
Button
When you click the Enumeration Values button, the
Enumeration Values property view appears (as shown in
Figure 4.22), on which you can create your enumeration.
Simply enter the labels and the integer values with which
the labels are associated.
Figure 4.22
Object Description4-26
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-27
ww
Th4.2.5 Views Manager
The Views Manager property view consists of two groups: View
File and Selected Object.
Selected Objects Group
The Selected Object group consists of a drop-down list with an
associated Objects Manager icon and the Existing Views list. The
drop-down list allows you to select one of the objects defined in
the Objects Manager property view. The Objects Manager icon
opens the Objects Manager property view.
The Existing Views list displays all of the existing property views
associated with the selected object.
Figure 4.23
Each *.edf file can have an unlimited number of objects
associated with it, each of which can have an unlimited
number of property views.
The View File group
contains the path and
name of the current
*.edf file.
When the Views Manager
property view is opened
for a new property view
file, HYSYS automatically
creates a property view
named DefaultView in
Existing Views list.
Objects Manager icon4-27
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-28 Widget Properties
ww
ThFrom the Views Manager property view, you can click any of the
buttons that pertain to the Existing Views list:
4.3 Widget Properties
As mentioned earlier in this guide, a property view is the
interface seen within the HYSYS environment. Views can contain
several tabs and pages of information. The controls placed on
the property view are referred to within the View Editor as
widgets. These include many of the typical control features
associated with windows programs such as text fields/cells,
checkboxes, drop-down lists, buttons, etc.
The Properties property view of a specific widget can be
accessed by either:
• Double-clicking on the widget
• Right-clicking the widget and selecting
Properties command from the Object Inspect menu,
where Widget Type would be the Button for a button
widget.
The properties of the DefaultView form itself can also be
accessed in either of the aforementioned ways.
When dealing with the properties of a widget and where
applicable, you can access options for the cell/field by clicking
the Ellipsis icon . A property view is presented from which
you can make a selection that is appropriate for the widget
property.
For extensions, the most important feature involves associating
the widget item to a particular variable declared in the Objects
Manager property view. This is accomplished through the
Moniker, which is another name for a variable.
Button Description
Edit Opens the selected property view and the Widget Palette.
Test Allows you to test the property view.
Add Adds a new property view to the object.
Copy Creates a copy of the selected property view.
Remove Removes the selected property view from the object.4-28
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
Extension View Editor 4-29
ww
ThFor most widgets the Target Moniker option is used to assign a
specific variable to the widget.
Common widget properties are discussed in the next section,
followed by widget specific properties. In the section describing
the specific widget properties, an example of each widget (as
well as its respective Properties property view) is shown.
Moniker Specification
Moniker (or variable) specification is usually done via the
Ellipsis icon that is usually associated with the moniker field.
There are usually three types of monikers specified:
Variable Type Description
Number
Variables
Numerical variables are selected via the Select Number
Variable property view which appears when the
Ellipsis icon is clicked. These variables:
• Represent numerical quantities and have a
Variable Type that allows HYSYS to manage Unit
Conversions for the user.
• Can have zero, one, or two dimensions.
• Can trigger the steady state solver when they are
changed. If this is the case, the variable operates
like other HYSYS variables in that the solver
performs consistency checking when values are
changed.
Text Variables Text variables are selected via the Select Text Variable
property view which appears when the Ellipsis icon
is clicked. These variables:
• Represent string quantities.
• Can be zero- or one-dimensional.
Message
Variables
Text variables are selected via the Edit Messages
property view which appears when the Ellipsis icon
is clicked. These variables do not represent any
particular quantification, but can be associated with
buttons in a property view. Messages are sent through
the VariableChanged method of an extension.4-29
w.cadfamily.com EMail:cadserv21@hotmail.com
e document is for study only,if tort to your rights,please inform us,we will delete
4-30 Widget Properties
ww
ThThe Select Number Variable and Select Text Variable property
view are very similar in their appearance and operation. Both
consist of a list that displays the available variables in the
variables set (or sub-set) selected in the Base Object drop-down
list.
The Base Object drop-down list contains variable sets and sub-
sets. The drop-down list acts as a path to object and object sub-
sets. The default option is the