dots in variable name?

Get help with using AutoHotkey and its commands and hotkeys
scriptor2016
Posts: 356
Joined: 21 Dec 2015, 02:34

dots in variable name?

21 Feb 2018, 01:02

evening all

Using COM to interact with Photoshop.
The following code successfully changes the foreground color in Photoshop to the hex value of 64c820

Code: [Select all] [Download] GeSHi © Codebox Plus

appRef := ComObjActive("Photoshop.Application")
SolidColor := ComObjCreate("Photoshop.SolidColor")
hex := SolidColor
hex.rgb.hexValue := "64c820"
appRef.foregroundColor := hex


..but this one throws an error (the error is coming from Photoshop I believe, which utilizes .jsx coding)

Code: [Select all] [Download] GeSHi © Codebox Plus

color=64c820

appRef := ComObjActive("Photoshop.Application")
SolidColor := ComObjCreate("Photoshop.SolidColor")
hex := SolidColor
hex.rgb.hexValue := "%color%"
appRef.foregroundColor := hex


this is a screenshot of the error:

[img]
https://ibb.co/ipYmHc
[/img]

My guess is that in order for Photoshop to accept the code, this line: hex.rgb.hexValue := "64c820" must contain a 6 character HEX code inside the quotes instead of a variable reference.

In other words, this one works:

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := "64c820"


..but this doesn't:

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := "%color%"



..how can I insert a 6-character variable inside those quotation marks? I've tried many variations, such as:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



..and this successfuly inserts the color variable in between the quotes, but how do I "run" the script now? I now have the code written out the way I need it, but how can I execute it? Running the script does nothing obviously, because all it becomes is essentially 2 variables.
User avatar
gregster
Posts: 1178
Joined: 30 Sep 2013, 06:48

Re: dots in variable name?

21 Feb 2018, 01:34

Use expression style to set the contents of a variable/property: hex.rgb.hexValue := color
scriptor2016
Posts: 356
Joined: 21 Dec 2015, 02:34

Re: dots in variable name?

21 Feb 2018, 01:45

hi gregster from what I gather so far is that the line of code must look exactly like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := "64c820"


so, the quotes need to be there, etc.

But if it's written like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := "color"


then the error message pops up (see screenshot link above).

I also tried:

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := `"%color%`"


and

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := "%color%"


and

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := color


as well as many other variations, but none work except the top example (where the actual HEX code is enclosed in quotes)

Are there any tricks to get a vartiale inserted in there?



..again, this will work:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




..but now it just becomes a variable in itself - how can I execute it by running the script without a hotkey? Kind of like run, %variable% if that makes sense? the messagebox that pops up contains the exact code I need (as you can see the HEX value is inserted from the color variable on the first line) .. but what do I do with it to make it run?
User avatar
gregster
Posts: 1178
Joined: 30 Sep 2013, 06:48

Re: dots in variable name?

21 Feb 2018, 02:24

With your msgbox you are on the wrong track. That's just text in a variable, not executable code.

Use expression style to set the contents of a variable/property: hex.rgb.hexValue := color
will work, if color contains the right contents.
If

Code: [Select all] [Download] GeSHi © Codebox Plus

hex.rgb.hexValue := "64c820"
works (the property hexValue gets the string 64c820 allocated, without "s), this will work, too:

Code: [Select all] [Download] GeSHi © Codebox Plus

color := "64c820"   ; <-- expression syntax;  "legacy syntax"    color = 64c820   will also work, but is not recommended.
hex.rgb.hexValue := color
The "s are not part of the string, but only indicate a string in expression syntax. Read again here, if you are not sure how variables (and properties) work: https://autohotkey.com/docs/Variables.htm
Last edited by gregster on 21 Feb 2018, 02:29, edited 1 time in total.
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: dots in variable name?

21 Feb 2018, 02:29

hex.rgb.hexValue := "64c820" ; expression style. Defining the variable hex.rgb.hexValue containing the string 64c820. Correct.

hex.rgb.hexValue := color ; expression style. Defining the variable hex.rgb.hexValue containing the content of the variable color. Correct.

As already said, check out the difference between AHK's legacy/traditional way to set :arrow: variables and how they are used within :arrow: expressions.
You've simply mixed up both types.
scriptor2016
Posts: 356
Joined: 21 Dec 2015, 02:34

Re: dots in variable name?

21 Feb 2018, 10:38

many thanks to you both - your solutions do indeed work! I was playing around for quite a while trying to understand where to place the the quotes and percentage signs - this is where I often get confused. I have this topic bookmarked so I can return to it later when I need it. I'm going to read up further on it :)

Return to “Ask For Help”

Who is online

Users browsing this forum: bxdobs, DyaTactic, evilC, rscott and 38 guests