COM access to Engineering application
#1
Posted 17 May 2012 - 09:03 PM
I am trying out AutoIt to access a program called Pipesim. According to the authors:
"PIPESIM has been designed with "Openness" in mind. Therefore key modules can be "driven" from 3rd party applications, for example, Microsoft Excel, VB, C++, and so on."
one of the calls/commands i make is .GetNameList ()
From the documentation of Pipesim:
GetNameList (ObjectType As Long, pNameArray, Count As Long)
OLE/COM Object viewer gives this information about this method:
void GetNameList(
[in] long ObjectType,
[out] VARIANT* pNameArray,
[out] long* Count);
My AutoIt script uses this as : $p.GetNameList(7, $list, $count)
$list returns are an array with index 0 to 26 (matches the $count with returns 27). Elements $list[1] to [26] do contains the proper string values (e.g. 'RB-136H') but element [0] contains a left pointing arrow (seems to be line feed since when I copied it from the output of ConsoleWrite and pasted it here it takes me to a new line with no visible character).
Another Get method ( for which OLE/COM Object viewer says ):
VARIANT_BOOL GetPropertyStringAtObjectIndex(
[in] BSTR ObjectName,
[in] BSTR ParentName,
[in] BSTR PropName,
[out] BSTR* pValue,
[in] long Index);
It returns pValue with a value of '??\'
Are these limitations of AutoIt w.r.t. COM or am I doing something wrong?
Thanks for any insight into this. This will really decide if we adopt AutoIt as our chosen scripting solution of choice. It has given us an extremely good impression otherwise. The functions work fine with Excel/VBA but have problems with VBScript.
Regards,
Faiz
#2
Posted 20 May 2012 - 09:15 AM
You could try to determine the datatype of element $list[0] by using the following functions:
ConsoleWrite("IsArray: " & IsArray($list[0]) & @CRLF) ConsoleWrite("IsObj: " & IsObj($list[0]) & @CRLF) ConsoleWrite("IsPtr: " & IsPtr($list[0]) & @CRLF)
Edited by water, 20 May 2012 - 09:15 AM.
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#3
Posted 21 June 2012 - 08:23 AM
I "ConsoleWrite" the count, the value of each element and then the code you suggested and get this:
count = 27
list(0)
list(1) RB-136H
list(2) RB-104V
list(3) RB-138H
list(4) RB-154H
list(5) RB-266H
list(6) RB-265V
list(7) RB-267H
list(8) RB-268H
list(9) RB-208H
list(10) RB-93H
list(11) RB-17V
list(12) RB-209H
list(13) RB-210H
list(14) RB-225H
list(15) RB-233V
list(16) RB-226HST
list(17) RB-307H
list(18) RB-308H
list(19) RB-207H
list(20) RB-202H
list(21) RB-92V
list(22) RB-311HST
list(23) RB-115
list(24) RB-84V
list(25) RB-309H
list(26) RB-203H
IsArray: 0
IsObj: 0
IsPtr: 0
I the data from elements $list[1] to [26] is correct but I am missing the first data (which I expected to be in [0]). Thanks for any pointers/help. Really appreciate it.
#4
Posted 21 June 2012 - 08:28 AM
I then also tried:
ConsoleWrite("VarType: " & VarGetType($list[0]) & @CRLF)
and got:
VarType: String
Edited by faiz, 21 June 2012 - 08:33 AM.
#5
Posted 21 June 2012 - 08:40 AM
What do you get if you access elements 27 and 28 of your array?
ConsoleWrite($list[27]) & @CRLF) ; Should give you a correct output ConsoleWrite($list[28]) & @CRLF) ; Should return an error
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#6
Posted 21 June 2012 - 01:27 PM
After your suggestion I get :
ConsoleWrite("27" & $list[27] & @CRLF)
ConsoleWrite("27" & ^ ERROR
Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.
#7
Posted 21 June 2012 - 01:38 PM
Element[0] contains the number of returned records = 27. They would be stored in Element[1] to Element[27]. But you can only access up to Element[26].
Could you query another object type (now you query type 7) so we can see what changes?
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#8
Posted 21 June 2012 - 01:54 PM
How do you create $p?My AutoIt script uses this as : $p.GetNameList(7, $list, $count)
Like this?
; Declare Network Model Object $NetModel = CreateObject("NET32COM.INETMODEL") ; Load model into Object $NetModel.OpenModel($ModelInput)
Edited by water, 21 June 2012 - 02:21 PM.
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#9
Posted 21 June 2012 - 03:30 PM
Dim $m, $list, $count $m = "e:....trunk.bpn" $p = ObjCreate("Net32COM.INetModel") $p.OpenModel($m) $p.GetNameList(7, $list, $count) ConsoleWrite("count = " & $count & @LF) for $i = 0 to $count - 1 ConsoleWrite("list(" & $i & ") " & $list[$i] & @LF) next ConsoleWrite("IsArray: " & IsArray($list[0]) & @CRLF) ConsoleWrite("IsObj: " & IsObj($list[0]) & @CRLF) ConsoleWrite("IsPtr: " & IsPtr($list[0]) & @CRLF) ConsoleWrite("VarType: " & VarGetType($list[0]) & @CRLF) ConsoleWrite("27" & $list[27] & @CRLF) ; Should give you a correct output ConsoleWrite("28" & $list[28] & @CRLF) ; Should return an error
Edited by faiz, 21 June 2012 - 03:31 PM.
#10
Posted 21 June 2012 - 05:37 PM
Global $m, $list[100], $count $m = "e:....trunk.bpn" $p = ObjCreate("Net32COM.INetModel") ConsoleWrite(@error & @CRLF) $p.OpenModel($m) ConsoleWrite(@error & @CRLF) $p.GetNameList(7, $list, $count) ConsoleWrite(@error & @CRLF) ConsoleWrite("count = " & $count & @LF) for $i = 0 to $count - 1 ConsoleWrite("list(" & $i & ") " & $list[$i] & @LF) next
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#11
Posted 21 June 2012 - 09:34 PM
#12
Posted 22 June 2012 - 05:42 AM
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#13
Posted 22 June 2012 - 06:16 AM
In this PDF you can find another (larger) example.
Edited by water, 22 June 2012 - 06:18 AM.
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#14
Posted 22 June 2012 - 11:39 AM
The VB Script & PDF are part of my history with this. The PDF contains Excel/VBA example, and it works for me too. In fact that is the solution we used and I left this forum for over a month!
The VB Script is from a colleague and it does not work. This triggered an interest in an alternative and I googled and found AutoIt! AutoIt was better than VBScript since gave a Type Mismatch on the call which AutoIt does execute it and return everything, except the first element of the list.
I suspect it is the way arguments are handled in AutoIt specially when using with calls to COM objects. I can get some insight from an expert like you.
#15
Posted 22 June 2012 - 11:45 AM
Edited by water, 22 June 2012 - 11:46 AM.
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#16
Posted 22 June 2012 - 11:50 AM
Actually just mow i was going to see if there is a new version...
#17
Posted 22 June 2012 - 11:56 AM
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#18
Posted 22 June 2012 - 01:47 PM
#19
Posted 22 June 2012 - 01:52 PM
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") Global $m, $list[100], $count $m = "e:....trunk.bpn" $p = ObjCreate("Net32COM.INetModel") $p.OpenModel($m) $p.GetNameList(7, $list, $count) ConsoleWrite("count = " & $count & @LF) For $i = 0 to $count - 1 ConsoleWrite("list(" & $i & ") " & $list[$i] & @LF) Next ConsoleWrite("27" & $list[27] & @CRLF) ; Should give you a correct output Exit Func _ErrFunc($oError) ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _ "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ "err.description is: " & @TAB & $oError.description & @CRLF & _ "err.source is: " & @TAB & $oError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ErrFunc
Edited by water, 22 June 2012 - 01:54 PM.
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#20
Posted 22 June 2012 - 02:34 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users




