HYSYS有偿服务? 共享一些代码,希望对大家有用。 [1]添加hysys 3.0 type library引用。 在excel的脚本编辑器中添加hysys 3.0 type library引用。 工具,引用。 [2]查看hysys库的方法。 在excel的脚本编辑器中,视图,对象浏览器,选中hysys库。 如:createobject("hysys.application")或createobject("hysys.simulationcase") [3]获得物流3910的温度流量。 dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\plant.hsc") simcase.flowsheet.materialstreams.item("3910").temperaturevalue simcase.flowsheet.materialstreams.item("3910").pressurevalue 或 simcase.flowsheet.streams.item("3910").temperaturevalue 改变单位 simcase.flowsheet.materialstreams.item("3910").molarflow.getvalue("m3/h_(gas)") simcase.flowsheet.streams.item("3910").temperature.getvalue("c") simcase.flowsheet.streams.item("3910").temperature.getvalue("f") simcase.flowsheet.streams.item("3910").pressure.getvalue("mpa") [4]给物流3910赋值 simcase.flowsheet.streams.item("3910").pressure.setvalue 200, "kpa" simcase.flowsheet.streams.item("3910").temperature.setvalue 30, "c" simcase.flowsheet.streams.item("3910").molarflow.setvalue 30, "m3/h_(gas)" [5]操作名称为e-100的冷却器。 dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\plant.hsc") set coolers = simcase.flowsheet.operations("coolerop") msgbox coolers.item("e-100").name 或 for each cooler in coolers msgbox cooler.name next 具体方法查看:coolerop参考。 注意:带op的都可以这样操作,如: acmop adjustop aircoolerop columnop compressop delumperop expandop fractop heaterop mixerop setop spreadsheetop teeop templateop userunitop valveop [6]查看所有对象的operator属性。 dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\plant.hsc") set c = simcase.flowsheet.operations for i = 0 to c.count - 1 msgbox c.item(i).name & " is unit type " & c.item(i).typename next i 注:有时不知道某个控件的属性时,可以上述代码看一下。 [7]直接操作某一个控件,如阀v1的开度。 dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\plant.hsc") set v = simcase.flowsheet.operations.item("v1") msgbox v.percentopenvalue v.percentopen.setvalue 40 [8]获得物流的组分 注:物流的方法在processstream类中。 dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\program files\aspentech\aspen hysys 2004\samples\dyntut1.hsc") set hystream = simcase.flowsheet.materialstreams("feed 1") hycompfrac = ponentmolarfractionvalue for i = 0 to ubound(hycompfrac) msgbox " molar fraction = " & hycompfrac(i) next i [9]获得未知变量的类型 注:有时操作某一个方法时,怎么都提示类型不对。 先获得变量类型typename(hycompfrac),再到对象浏览器的类中去找相应的名称,查看相应的方法。 double()表示数据,用ubound查看数据大小,注:数组从0开始。 dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\program files\aspentech\aspen hysys 2004\samples\dyntut1.hsc") set hystream = simcase.flowsheet.materialstreams("feed 1") msgbox typename(hystream) [10]获得hysys界面的物体 sub readtypeoperation() dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\program files\aspentech\aspen hysys 2004\samples\dyntut1.hsc") set c = simcase.flowsheet.operations for i = 0 to c.count - 1 msgbox c.item(i).name & " is unit type " & c.item(i).typename next i end sub [11]获得hysys塔界面的物体 sub readtypecolumnoperation() dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\program files\aspentech\aspen hysys 2004\samples\dyntut1.hsc") set colop = simcase.flowsheet.operations.item("depropanizer").columnflowsheet.operations set colf = simcase.flowsheet.operations.item("depropanizer").columnflowsheet for i = 0 to colop.count - 1 'msgbox colop.item(i).name next i end sub [12]获得hysys界面的物流 sub readtypematerialstream() dim app, simcase as object set app = createobject("hysys.application") set simcase = getobject("c:\program files\aspentech\aspen hysys 2004\samples\dyntut1.hsc") set f = simcase.flowsheet.materialstreams for i = 0 to f.count - 1 msgbox f.item(i).name next i end sub [13]显示纯度ppm查看更多