Jump to content
marcoauto

Convert from C++ to Autoit for ATEM Mixer

Recommended Posts

marcoauto

Ciao

I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.

The instructions say to follow this sequence:

Quote
Switcher Configuration and Transitions
An application for controlling a switcher may perform the following steps:
‚ Use IBMDSwitcherDiscovery::ConnectTo to connect to a switcher device and obtain
an IBMDSwitcher object interface
‚ Use IBMDSwitcher::CreateIterator to get an IBMDSwitcherInputIterator
object interface
‚ For each IBMDSwitcherInput returned by IBMDSwitcherInputIterator::Next retrieve
the input’s unique Id using IBMDSwitcherInput::GetInputId and retrieve other properties
of the input, such as the input’s name, using IBMDSwitcherInput::GetString or
IBMDSwitcherInput::GetInt
‚ Use IBMDSwitcher::CreateIterator to get an IBMDSwitcherMixEffectBlockIterator
object interface
‚ Obtain an IBMDSwitcherMixEffectBlock object interface using
IBMDSwitcherMixEffectBlockIterator::Next
‚ Use IBMDSwitcherMixEffectBlock::SetInt to configure the Program and
Preview inputs to the mix effect block by assigning the input Ids returned by
IBMDSwitcherInput::GetInputId
‚ Perform a transition between Program and Preview inputs by calling
IBMDSwitcherMixEffectBlock::PerformTransition
‚ Install a callback using IBMDSwitcherMixEffectBlock::AddCallback and receive
IBMDSwitcherMixEffectBlockCallback::PropertyChanged callbacks to determine
progress through the transition and when the transition is complete

and to connectTo with C++ is:

string address = "192.168.1.240";
_BMDSwitcherConnectToFailure failureReason = 0;
IBMDSwitcher switcher = null;
var discovery = new CBMDSwitcherDiscovery();
discovery.ConnectTo(address, out switcher, out failureReason);

From Blackmagic SDK:

IBMDSwitcherDiscovery::ConnectTo method
The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.

Syntax
HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason);
Parameters:
deviceAddress in Network hostname or IP address of switcher to connect to.
switcherDevice out IBMDSwitcher object interface for the connected switcher.
failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value.

So, I have I tried these solutions but with non success:

$DllName =@ScriptDir&"\BMDSwitcherAPI.dll"
$result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF)
ConsoleWrite("DLLCall Result: " & $result & @CRLF)

and I have tried also create an Object (That I think is the best way solution):

#include <MsgBoxConstants.au3>

$oSwitcher=ObjCreate("IBMDSwitcher")
If IsObj($oSwitcher) Then
    MsgBox(64, "", "Object $oSwitcher created successfully")
EndIf
$oAtem=ObjCreate("IBMDSwitcherDiscovery")
If IsObj($oAtem) Then
    MsgBox(64, "", "Object $oAtem created successfully")
EndIf
$failureReason =ObjCreate("_BMDSwitcherConnectToFailure")
If IsObj($failureReason) Then
    MsgBox(64, "", "Object $failureReason created successfully")
EndIf
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler
Global $errore,$oSwitcher1
$oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason);
; This is the custom error handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription & @CRLF & _
            "Source is: " & $oMyError.source & @CRLF & _
            "Description is: " & $oMyError.description & @CRLF & _
            "Helpfile is: " & $oMyError.helpfile & @CRLF & _
            "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _
            "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _
            "Scriptline is: " & $oMyError.scriptline)
EndFunc   ;==>MyErrFunc

But the result is:

We intercepted a COM Error !
Number is: 000000A9
Windescription is: Variable must be of type 'Object'.
Source is: 
Description is: 
Helpfile is: 
Helpcontext is: 
Lastdllerror is: 0
Scriptline is: 17

The BMDSwitcherAPI.dll is registered in system. Can someone help me?

Grazie

Marco

Share this post


Link to post
Share on other sites
Danyfirex

Hello. Could you provide doc file?

 

Saludos

Share this post


Link to post
Share on other sites
marcoauto

Hi, I Have pdf Backmagic SDK. You can find it in attachment here

Thankyou

Marco

Blackmagic Switchers SDK.pdf

Share this post


Link to post
Share on other sites
Danyfirex

Hello. You need to get the basic about AutoIt DllCall Function. You're walking blind. You also need to get the basic about C++ Implement this. I really have not to much free time to look deeply in the doc file. You need to make sure this SDK registers a COM Visible Object otherwise You can't use ObjCreate. If You can't you probably need to use ObjCreateInterface to handle this. let's try this script. I don't know the ProgID (if It shows one) So I'm using the CLSID to create the object. (not sure if it will work). If It does not. Good look with ObjCreateInterface or probably direct dll calls of which I'm not sure if it exposes the functions.

 

Script: (sorry I'm unable to load sintaxis highlighting)

Global Const $sCLSID_CBMDSwitcherDiscovery='{F2DC5149-9599-47E4-84B9-054C78A1A46D}'
Local $oObject=ObjCreate($sCLSID_CBMDSwitcherDiscovery)
ConsoleWrite('IsObj($oObject): ' & IsObj($oObject) & @CRLF)

 

Saludos

 

 

Share this post


Link to post
Share on other sites
marcoauto
4 hours ago, Danyfirex said:

Hello. You need to get the basic about AutoIt DllCall Function. You're walking blind. You also need to get the basic about C++ Implement this. I really have not to much free time to look deeply in the doc file. You need to make sure this SDK registers a COM Visible Object otherwise You can't use ObjCreate.

Yes, the problem is I don't know how to understand if is a COM Visible method.

the result of

Global Const $sCLSID_CBMDSwitcherDiscovery='{F2DC5149-9599-47E4-84B9-054C78A1A46D}'
Local $oObject=ObjCreate($sCLSID_CBMDSwitcherDiscovery)
ConsoleWrite('IsObj($oObject): ' & IsObj($oObject) & @CRLF)

in console is:

IsObj($oObject): 0

I'll try with ObjCreateInterface. I'll study the sintax.

My problem is that I do not have the knowledge of c ++ to understand how it works. I'll try

Thankyou for your time!

Marco

Share this post


Link to post
Share on other sites
Danyfirex

Could you provide me the BMDSwitcherAPI.dll to do some tests.

 

Saludos

Share this post


Link to post
Share on other sites
marcoauto

yes, of course!!

I zipped dll file because the maximum forum upload file size 

Grazie

marco

BMDSwitcherAPI.zip

Share this post


Link to post
Share on other sites
Danyfirex

Here a simple example for create a CBMDSwitcherDiscovery Interface.

Global Const $sCLSID_CBMDSwitcherDiscovery = "{F2DC5149-9599-47E4-84B9-054C78A1A46D}"
Global Const $sIID_IBMDSwitcherDiscovery = "{A676047A-D3A4-44B1-B8B5-31D7289D266A}"
Global Const $sTag_IBMDSwitcherDiscovery = "ConnectTo hresult(bstr;ptr*;int*);"


Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $oCBMDSwitcherDiscovery = ObjCreateInterface($sCLSID_CBMDSwitcherDiscovery, $sIID_IBMDSwitcherDiscovery, $sTag_IBMDSwitcherDiscovery)
ConsoleWrite("IsObj($oCBMDSwitcherDiscovery): " & IsObj($oCBMDSwitcherDiscovery) & @CRLF)

Local $sDeviceAddress = "192.168.1.240"
Local $pIBMDSwitcher = 0
Local $iConnectToFailure = 0
$oCBMDSwitcherDiscovery.ConnectTo($sDeviceAddress, $pIBMDSwitcher, $iConnectToFailure)
ConsoleWrite("$pIBMDSwitcher: " & $pIBMDSwitcher & @CRLF)
ConsoleWrite("$iConnectToFailure: " & $iConnectToFailure & @CRLF)


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

on success you'll need to casting $pIBMDSwitcher pointer to an Interface IBMDSwitcher using ObjectCreateInterface

 

Saludos

Share this post


Link to post
Share on other sites
marcoauto

ciao,

Hi, I tried to do what you told me, but I can not understand the syntax I have to use. I'm trying to study how c ++ works but it's very different from autoit and so I have a lot of difficulties
For the moment I did only this with success: $oIBMDSwitcher.GetProductName($nome) 

 

Global Const $sCLSID_CBMDSwitcherDiscovery = "{F2DC5149-9599-47E4-84B9-054C78A1A46D}"
Global Const $sIID_IBMDSwitcherDiscovery = "{A676047A-D3A4-44B1-B8B5-31D7289D266A}"
Global Const $sTag_IBMDSwitcherDiscovery = "ConnectTo hresult(bstr;ptr*;int*);"
Global Const $sIID_IBMDSwitcher = "{3D480E2F-3CF4-474B-92E7-B7907EE83B41}"
Global Const $sTag_IBMDSwitcher = "ConnectTo hresult(bstr;ptr*;int*);"
Global Const $sTag_IBMDSwitcher_CreateIterator = "CreateIterator hresult(ptr*;int*);"

Global Const $sIID_IBMDSwitcherMixEffectBlockIterator = "{930BDE3B-4A78-43D0-8FD3-6E82ABA0E117}"
Global Const $sTag_IBMDSwitcherMixEffectBlockIterator = "Next hresult(int*);"

Global Const $sIID_IBMDSwitcherMixEffectBlock = "{11974D55-45E0-49D8-AE06-EEF4D5F81DF6}"
Global Const $sTag_IBMDSwitcherMixEffectBlock = "CreateIterator hresult(REFIID, LPVOID*);"

Global Const $sIID_IBMDSwitcherInputIterator = "{275E9888-2F65-4B2E-9434-1937A72B9EC4}"
Global Const $sTag_IBMDSwitcherInputIterator = " GetById hresult (int,int*);"


Global Const $sTag_IBMDSwitcher_GetProductName  = "GetProductName  hresult(bstr*);"

Global Const $sTag_IBMDSwitcher_Creator = "CreateIterator hresult(lpvoid*);"

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $oCBMDSwitcherDiscovery = ObjCreateInterface($sCLSID_CBMDSwitcherDiscovery, $sIID_IBMDSwitcherDiscovery, $sTag_IBMDSwitcherDiscovery)
ConsoleWrite("IsObj($oCBMDSwitcherDiscovery): " & IsObj($oCBMDSwitcherDiscovery) & @CRLF)
$sFileWithDefinition = ObjName($oCBMDSwitcherDiscovery)
ConsoleWrite($sFileWithDefinition & @CRLF)

Local $sDeviceAddress = "192.168.1.37"
Local $pIBMDSwitcher = 0
Local $iConnectToFailure = 0
$oCBMDSwitcherDiscovery.ConnectTo($sDeviceAddress, $pIBMDSwitcher, $iConnectToFailure)
ConsoleWrite("$pIBMDSwitcher: " & $pIBMDSwitcher & @CRLF)
ConsoleWrite("$iConnectToFailure: " & $iConnectToFailure & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ IsObj($oCBMDSwitcherDiscovery): 1
;~ InterfaceDispatch
;~ $pIBMDSwitcher: 72569844
;~ $iConnectToFailure: 0
;~ -------

local $iterator,$nome
Local $oIBMDSwitcher = ObjCreateInterface($pIBMDSwitcher,$sIID_IBMDSwitcher,$sTag_IBMDSwitcher_GetProductName);$sTag_IBMDSwitcher_Creator)
ConsoleWrite("IsObj($oIBMDSwitcher): " & IsObj($oIBMDSwitcher) & @CRLF)
$sFileWithDefinition = ObjName($oIBMDSwitcher)
ConsoleWrite($sFileWithDefinition & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ IsObj($oIBMDSwitcher): 1
;~ InterfaceDispatch
;~ -------

$oIBMDSwitcher.GetProductName($nome)
ConsoleWrite("$oIBMDSwitcher.GetProductName: " & $nome & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ $oIBMDSwitcher.GetProductName: ATEM 1 M/E Production Switcher
;~ -------

Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

I'd like to set a preview input and after do a cut transition

From a c++ script:

result = mSwitcher->CreateIterator((IID_IBMDSwitcherInputIterator, (void**)&inputIterator);

but I can't understand how to obtain  (void**)&iterator and how to declare it

from SDK is

IBMDSwitcher::CreateIterator method
HRESULT CreateIterator (REFIID iid, LPVOID* ppv);
iid [in] = Iterator Interface ID to create an iterator for
ppv [in] = Pointer to return interface object.
result = mSwitcher->CreateIterator(IID_IBMDSwitcherInputIterator, (void**)&inputIterator);

I tried with

$return  = $oIBMDSwitcher.CreateIterator($sIID_IBMDSwitcherInputIterator,$pIBMDSwitcher)
ConsoleWrite("$oIBMDSwitcher.CreateIterator: " & $return & @CRLF)
ConsoleWrite("-------" & @CRLF)
;~ Output console:
;~ atem.au3 (109) : ==> COM Error intercepted !
;~  err.number is:      0x80020006
;~  err.windescription: Nome sconosciuto.

;~  err.description is:
;~  err.source is:
;~  err.helpfile is:
;~  err.helpcontext is:
;~  err.lastdllerror is:    0
;~  err.scriptline is:  109
;~  err.retcode is:     0x00000000

but is wrong, of course!

from SDK I need to:

IBMDSwitcher::CreateIterator to get an IBMDSwitcherInputIterator object interface

For each IBMDSwitcherInput returned by IBMDSwitcherInputIterator::Next retrieve the input’s unique Id using IBMDSwitcherInput::GetInputId and retrieve other properties of the input, such as the input’s name, using IBMDSwitcherInput::GetString or IBMDSwitcherInput::GetInt

Use IBMDSwitcher::CreateIterator to get an IBMDSwitcherMixEffectBlockIterator object interface

Obtain an IBMDSwitcherMixEffectBlock object interface using IBMDSwitcherMixEffectBlockIterator::Next

Use IBMDSwitcherMixEffectBlock::SetInt to configure the Program and Preview inputs to the mix effect block by assigning the input Ids returned by IBMDSwitcherInput::GetInputId

Perform a transition between Program and Preview inputs by calling IBMDSwitcherMixEffectBlock::PerformTransition

Install a callback using IBMDSwitcherMixEffectBlock::AddCallback and receive IBMDSwitcherMixEffectBlockCallback::PropertyChanged callbacks to determine progress through the transition and when the transition is complete

 

Thanks

marco

 

Share this post


Link to post
Share on other sites
Danyfirex

Hello. I think the best and easy alternative for you is use .NET I think SDK has some C# examples, because convert this to AutoIt is a little hard if you dont have at least basic knowledge of C++ / AutoIt. 

 

 

Saludos

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • cdeb
      By cdeb
      I'm trying to verify which is the default scanner and if it is different from what I need to propose a choice among those available.
      All this is possible with eztw32.dll however I can not make certain functions work
      Are these:
      int TWAIN_GetDefaultSourceName(LPSTR pzName)
      string TWAIN_DefaultSourceName()
      int TWAIN_GetSourceList(void)
      source: http://www.eztwain.com/pub/eztp/EZTwain_User_Guide.pdf
      I tried this way but they do not work:
      Local $pzName
      $pzName = DllCall($pathDLL,"int","TWAIN_DefaultSourceName") ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName", "str*", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName","str", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList")
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList", "NONE", "") ;
       
      Can anyone help me?
      Everything else works, here is the code:
       
      Local $pathDLL = @ScriptDir&"\_res\eztw32.dll" Local $rc = DllCall($pathDLL,'int','TWAIN_EasyVersion') if @error <> 0 then MsgBox(16+262144, "DllCall Error", "Error load eztw32.dll") else ConsoleWrite('--> eztw32.dll version: ' & $rc[0]/100 & @CRLF) $rc = DllCall($pathDLL,"int","TWAIN_IsAvailable") If @error > 0 Then MsgBox(16+262144, "DllCall Error", "Error call DLL - TWAIN_IsAvailable") if $rc[0] <> 0 then ConsoleWrite('--> TWAIN available: RC = ' & $rc[0]&@CRLF) ;;;;;;;;;;;;;;;;;;;;;; I NEED HERE ;manual select scanner Local $hwnd $rc = DllCall($pathDLL,"long","TWAIN_SelectImageSource",'hwnd',$hwnd) ConsoleWrite('--> TWAIN_SelectImageSource = ' & $rc[0]&@CRLF) if $rc[0] <> 0 then ConsoleWrite("--> TWAIN device selected"&@CRLF) else ConsoleWrite("--> no TWAIN device selected"&@CRLF) endif Else ConsoleWrite('--> TWAIN NOT available: RC = ' & $rc[0]&@CRLF) ; es: 0 endif endif thank you
    • Mannyfresh31
      By Mannyfresh31
      Hi Everybody I want know if there is someone kind enough to help me translate this code in to Autoit please don't blame me cause I'm a newbe 
      here is the code I need to translate also I want know if it's possible to look through a DLL  functions
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Function CASH_OPENCOM Lib "CASH.DLL" (ByVal CASH_COMPORT As Long) As Long 
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Sub CASH_CLOSECOM Lib "CASH.DLL" ()
       
       
      and here is the code I have written so far
      down below is the DLL attached also a screen shot of the  exit code of SciTE
      #include<Array.au3> $CashDLL = DllOpen("C:\Users\manue\Downloads\Casll DLL\cash.dll") if $CashDLL Then MsgBox (0,"","CashDLL Open",0) $HOPPER_OPENCOM = DllCall($CashDLL,"LONG","HOPPER_OPENCOM") if isarray ($HOPPER_OPENCOM) Then _Arraydisplay ($HOPPER_OPENCOM) Else MsgBox (0,"",@error,0) EndIf $HOPPER_CLOSECOM = DllCall($CashDLL,"NONE","HOPPER_CLOSECOM") if isarray ($HOPPER_CLOSECOM) Then _Arraydisplay ($HOPPER_CLOSECOM) Else MsgBox (0,"",@error,0) EndIf DllClose ($CashDLL)  
       

      cash.dll
    • genius257
      By genius257
      I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.
      Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.
      If I've forgotten to add credit, please let me know
      Example:
      #include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoItObject-Internal/tree/master/Examples
      Version: 2.0.0
      AutoItObject_Internal.au3
      Documentation
      Edit2 (19th March 2017):
      First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.
      So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • tuffgong
      By tuffgong
      Good morning. I have a system I am trying to automate that works like this: user fills a column in an Excel spreadsheet with values they would like printed and saves it to a folder on their desktop, they start the script and it formats their data into a text file (adding a prefix) and sends the text file as a .bch file where it needs to go. This is working:
      #include <Array.au3> #include <Excel.au3> #include <File.au3> #include <MsgBoxConstants.au3> Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) barcodePrint() Func barcodePrint() $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) FileOpen($sFilename, $FO_OVERWRITE) ;Global $oWorkbook = _Excel_BookAttach($oExcel) Global $sSTCArray = _Excel_RangeRead($Read) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, "!StaticShelving1x3_ZPL," & $sSTCArray[$i]) Next _Excel_Close($oExcel) FileMove($sFilename, "***file path***\print.bch") EndFunc However, it only works if the user first formats the spreadsheet to text. I want to automate that. From what I have read it appears AutoIt does not like formatting cells that already have values. True? Can I pull the values from an un-formatted (default GENERAL format) spreadsheet and go straight to my text file? I have also considered opening a second spreadsheet, formatting it, and copying the values over. Like this:
        
      Global $sPrefix Global $oPath Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) Global $aArray Global $bExcel _Excel_BookNew($bExcel) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $aArray = IniReadSection("***File path***\barcode.ini", "stc/rvt/mgm") $sPrefix = $aArray[1][1] $oPath = $aArray[2][1] barcodePrint() EndSwitch WEnd Func barcodePrint() $oWorkbook = _Excel_BookOpen($bExcel, @DesktopDir & "\Labels\print.xlsx") $oWorkbook.ActiveSheet.Columns("A").NumberFormat = "@" Local $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) $oCopy = _Excel_RangeRead($sWorkbook) _Excel_RangeWrite($oWorkbook, Default, $oCopy) FileOpen($sFilename, $FO_OVERWRITE) $sSTCArray = _Excel_RangeRead($Read,"Default","Default",3) ;_ArrayDisplay($sSTCArray) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, $sPrefix & $sSTCArray[$i]) Next _Excel_Close($oExcel) ;FileMove($sFilename, $oPath) Exit EndFunc This does not like the formatting of $oWorkbook: "Variable must be of type 'Object'".  Do I need this second sheet? If so, how can I format it? Is there a better way to get the Excel values into a .txt file? Any ideas would be appreciated. Thanks!
×