Jump to content

easy question about arrays


Recommended Posts

Hi people,

It's been a while :)
I have been scripting in vbscript for some time but now i'm back using AutoIt for a project:

Scripting Adobe Illustrator with AutoIt .
This vb code needs to be converted:

Set appRef = CreateObject("Illustrator.Application")
'Create a new document and assign it to a variable
Set documentRef = appRef.Documents.Add
'Create a new text frame item and assign it to a variable
Set sampleText = documentRef.TextFrames.Add
'Set the contents and position of the TextFrame
sampleText.Position = Array(200, 200)
sampleText.Contents = "Hello World!"

The ... = Array(200,200) part is done in one line in vb, is this possible in AutoIt without declaring an array first?
I know I sound like a newbie but I never had to use arrays this way before..

what i have:

$appRef = ObjCreate("Illustrator.Application")
;Create a new document and assign it to a variable
$documentRef = $appRef.Documents.Add
;Create a new text frame item and assign it to a variable
$sampleText = $documentRef.TextFrames.Add
;Set the contents and position of the TextFrame
ReDim $sampleText.Position[2] = [200, 200] <<<--- doesn't work...
$sampleText.Contents = "Hello World!"

 

Edited by TheAutomator
Link to comment
Share on other sites

maybe you could "simulate" the VB behaviuor for "Array()" by using a simple function to return a 2 elements array....

$appRef = ObjCreate("Illustrator.Application")
;Create a new document and assign it to a variable
$documentRef = $appRef.Documents.Add
;Create a new text frame item and assign it to a variable
$sampleText = $documentRef.TextFrames.Add
;Set the contents and position of the TextFrame
$sampleText.Position = Array(200, 200)
$sampleText.Contents = "Hello World!"

Func Array($iX, $iY) ; returns a 2 element 1d array
    Local $aArray[2] = [$iX, $iY]
    Return $aArray
EndFunc   ;==>Array

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

7 minutes ago, Chimp said:

maybe you could "simulate" the VB behaviuor for "Array()" by using a simple function to return a 2 elements array....

$appRef = ObjCreate("Illustrator.Application")
;Create a new document and assign it to a variable
$documentRef = $appRef.Documents.Add
;Create a new text frame item and assign it to a variable
$sampleText = $documentRef.TextFrames.Add
;Set the contents and position of the TextFrame
$sampleText.Position = Array(200, 200)
$sampleText.Contents = "Hello World!"

Func Array($iX, $iY) ; returns a 2 element 1d array
    Local $aArray[2] = [$iX, $iY]
    Return $aArray
EndFunc   ;==>Array

 

Yes, I thought about that to.. but I first wanted to know if there wasn't a more direct way.
I suppose that's a no for direct array declaring in AutoIt then? :)

Thanks for the reply btw :)

Link to comment
Share on other sites

11 minutes ago, TheAutomator said:

I suppose that's a no for direct array declaring in AutoIt then?

Correct in relation to your syntax, although using StringSplit() should also work here - however this is still calling a function.

Edited by czardas
Link to comment
Share on other sites

good point,

so you could use for example something like this;

$sampleText.Position = StringSplit('200,200', ',', 3)

p.s. ( little hijacking) )

@czardas,

Since also the StringRegExp function can return an array, what pattern can be used to have an array from a comma delimited list? .....thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hello. knowing that we're going to use number also we could use

_ArrayDisplay(StringRegExp("200,200", '\d+', 3))

Of course for this Chimp's  suggestion is the correct/clean way to use.

Saludos

Link to comment
Share on other sites

5 minutes ago, czardas said:

I think I know this. :)

never doubted ...... lol :D

@Danyfirex .... thanks :)

 

p.s.

:think: is there any 'regexp' guru that could came out with an an esotheric pattern to get a multidimensional array as well..... :blink:

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
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
 Share

×
×
  • Create New...