Page 1 of 1

Need help in making script to hop between two layers

Posted: 18 Apr 2020, 12:07
by TheQuestionMark
I was wonder can anyone make a command or script where you can hop between two layers? I would like hop between the current layer and line layer. I was wondering if it can hop to any selection of within 3 of color layers if I select it but it always land back to "Line" Layer, and it goes back and forth. I have alot between layers that's in the middle of the color and line layer, it's a real hassle to tap keyboard several times. Is there such thing as script for it?

Re: Need help in making script to hop between two layers

Posted: 18 Apr 2020, 15:28
by slowtiger
I'm just guessing: if you put all these layers in the same group, maybe the script can jump easily between these?

Re: Need help in making script to hop between two layers

Posted: 19 Apr 2020, 00:24
by Svengali
This script "ToggleLineLayer.grg" can be embedded and should do what you want.

Follow these steps and pay attention to step 5. where you must SUBSTITUTE the line name you want to toggle to...
1. create a new Action button
2. in the code box below click on SELECTALL
3. Edit the Action button to create an Ebedded George Script
4. In the "Type Script's Command" box, paste the script

5. IMPORTANT: locate and Edit the following line in the SCRIPT:
LineLayer = "name of line layer you want to toggle to"

6. Select OK to close the "Type Script's Command" box
7. Select OK to save the Action button
8. Test the button: it should toggle between your line layer and whatever other, current layer you are working on

Code: Select all

// ToggleLineLayer.grg
// Svengali © 2020
// ( april ) 2020 - ver .0
//     toggles between any current layer and linelayer

Param none
ScriptName = "ToggleLineLayer"

LineLayer = "name of line layer you want to toggle to"			// put the name of the line layer here INSIDE QUOTATION MARKS

tv_LayerCurrentID
OrigLayerID = result
tv_LayerInfo OrigLayerID
parse result d d d LayerName d
IF CMP(LayerName,LineLayer) == 0
	tv_WriteUserString "ToggleLineLayer" "OrigLayerID" OrigLayerID
	FindLineLayer()
ELSE
	tv_ReadUserString "ToggleLineLayer" "OrigLayerID" 
	OrigLayerID = result
	tv_LayerSet OrigLayerID
END


FUNCTION FindLineLayer()
	
	Counter = 0
	LineLayerID = 0
	LayerFlag = 1
	While LayerFlag == 1
		tv_LayerGetID Counter
		LineLayerID = result
		tv_LayerInfo LineLayerID
		parse result d d d LayerName d
		IF CMP(LayerName,LineLayer)
			tv_LayerSet LineLayerID
			LayerFlag = 0
		END
		IF CMP(LineLayerID,"none")
			tv_warn LineLayer "not found... aborting"
			LayerFlag = 0
		END
		Counter = Counter + 1
	END
END
Sven

Re: Need help in making script to hop between two layers

Posted: 20 Apr 2020, 03:09
by TheQuestionMark
slowtiger wrote: 18 Apr 2020, 15:28 I'm just guessing: if you put all these layers in the same group, maybe the script can jump easily between these?
I'm not sure I really need a group? I just need to hop to line layer and with the current layer, the color layer. I have 3 color layers, but I just want the color layer I'm on and want to hop back to line layer, back and forward.

Re: Need help in making script to hop between two layers

Posted: 20 Apr 2020, 03:18
by TheQuestionMark
Svengali wrote: 19 Apr 2020, 00:24 This script "ToggleLineLayer.grg" can be embedded and should do what you want.

Follow these steps and pay attention to step 5. where you must SUBSTITUTE the line name you want to toggle to...
1. create a new Action button
2. in the code box below click on SELECTALL
3. Edit the Action button to create an Ebedded George Script
4. In the "Type Script's Command" box, paste the script

5. IMPORTANT: locate and Edit the following line in the SCRIPT:
LineLayer = "name of line layer you want to toggle to"

6. Select OK to close the "Type Script's Command" box
7. Select OK to save the Action button
8. Test the button: it should toggle between your line layer and whatever other, current layer you are working on

Code: Select all

// ToggleLineLayer.grg
// Svengali © 2020
// ( april ) 2020 - ver .0
//     toggles between any current layer and linelayer

Param none
ScriptName = "ToggleLineLayer"

LineLayer = "name of line layer you want to toggle to"			// put the name of the line layer here INSIDE QUOTATION MARKS

tv_LayerCurrentID
OrigLayerID = result
tv_LayerInfo OrigLayerID
parse result d d d LayerName d
IF CMP(LayerName,LineLayer) == 0
	tv_WriteUserString "ToggleLineLayer" "OrigLayerID" OrigLayerID
	FindLineLayer()
ELSE
	tv_ReadUserString "ToggleLineLayer" "OrigLayerID" 
	OrigLayerID = result
	tv_LayerSet OrigLayerID
END


FUNCTION FindLineLayer()
	
	Counter = 0
	LineLayerID = 0
	LayerFlag = 1
	While LayerFlag == 1
		tv_LayerGetID Counter
		LineLayerID = result
		tv_LayerInfo LineLayerID
		parse result d d d LayerName d
		IF CMP(LayerName,LineLayer)
			tv_LayerSet LineLayerID
			LayerFlag = 0
		END
		IF CMP(LineLayerID,"none")
			tv_warn LineLayer "not found... aborting"
			LayerFlag = 0
		END
		Counter = Counter + 1
	END
END
]
Sven
Thank you this is exactly what I wanted! I guess writing the code is complicated then what I imagine in my mind. Thanks!

Re: Need help in making script to hop between two layers

Posted: 20 Apr 2020, 13:14
by Svengali
Happy to help.
Actually, the script is pretty simple and uses a standard method to loop through all layers to find one (or more) specific layer(s) with some characteristic like name, or status.

It also uses the config.ini file to store and retrieve data so dynamic information that changes can be passed between scripts.

Sven