Jump to content



Featured Articles

Check out the latest featured articles.

File Library

Check out the latest downloads available in the File Library.

New Article

Product Viscosity vs. Shear

Featured File

Vertical Tank Selection

New Blog Entry

Low Flow in Pipes- posted in Ankur's blog

1

Adding Components Through Vba To Hysys

hysys vba components adding components

1 reply to this topic
Share this topic:
| More

#1 Matylda

Matylda

    Brand New Member

  • Members
  • 7 posts

Posted 26 July 2024 - 08:08 AM

Hi everyone!

 

I've been struggling to add components to Hysys (or UniSim) though VBA's code. I've tried a couple of different methods but none of them works.

 

Sub AddCompressorInHYSYS()
 
Dim hyApp As HYSYS.Application
Dim hyCase As HYSYS.SimulationCase
Set hyApp = CreateObject("HYSYS.Application")
 
Dim hyPath As String
hyPath = "C:\Users\ ....."
Set hyCase = GetObject(hyPath)
 
Dim Compressor As HYSYS.Operations
Set Compressor = hyCase.Flowsheet.ExtnPropertyPackage.AddComponent(Compressor)

 

or 

Set Compressor = hyCase.Flowsheet.Operations.Item.Add("compressor")
 
and a variation of those. 
I've read about ExtnPropertyPackage and AddComponent in Hysys Customization Guide but I still am not sure how to use it properly.
 
Thank you in advance!
 
 


#2 Matylda

Matylda

    Brand New Member

  • Members
  • 7 posts

Posted 30 July 2024 - 02:08 AM

Hi everyone, 

 

Update, I've already know how to do so, 

 

I'm sharing the answer in case anyone would have the same issue as I had. 

 

Sub AddCompressorInHYSYS()
 
Dim hyApp As HYSYS.Application
Dim hyCase As HYSYS.SimulationCase
Set hyApp = CreateObject("HYSYS.Application")
 
Dim hyPath As String
hyPath = "C:\Users\ ....."
Set hyCase = GetObject(hyPath)
 
Dim Compressor As HYSYS.Operations  ' or As Object or As HYSYS.CompressOp I think it works either way
Set Compressor = hyCase.Flowsheet.Operations.Add("compressor_name", "compressor")
 
"compressor_name" - it is just a name you want you operation to have
 
"compressor" - what object you want: compressor, pipeseg etc. They sometimes have weird names just like pipeseg instead of pipe segment, and I think some of them can have "Op" at the end so "TeeOp" so try and error ig.
 
 
And with streams this is much easier:
Dim NewStream As HYSYS.ProcessStream
Set NewStream = hyCase.Flowsheet.MaterialStreams.Add("Stream_Name")
 
 
Hope it helps someone :))
 

Edited by Matylda, 30 July 2024 - 02:10 AM.





Similar Topics