Any example of how to select and copy using the API? #1101
Answered
by
Variable-ind
devmark404
asked this question in
Q&A
-
I would like to select and copy the first 9 pixels that are within the white border of the current layer I am using the following code, but the first 9 pixels are not selected and copied
Español: Estoy usando el siguiente código, pero no se seleccionan y no se copian los primeros
|
Beta Was this translation helpful? Give feedback.
Answered by
Variable-ind
Sep 10, 2024
Replies: 1 comment 6 replies
-
Hy, what happens when you use the paste shortcut (Ctrl + V). test-.9.mp4extends Node
var extension_api: Node
var selection_node: Node ## Used to interact with the selection directly, instead of through api
# This script acts as a setup for the extension
func _enter_tree() -> void:
## NOTE: use get_node_or_null("/root/ExtensionsApi") to access api.
extension_api = get_node_or_null("/root/ExtensionsApi")
extension_api.menu.add_menu_item(extension_api.menu.SELECT, "Copy 9 Pixels", self)
## NOTE: You may want to get some other properties of the selection e.g size.
## for the moment those aren't exposed to API,
## so you have to interact with selection directly.
selection_node = extension_api.general.get_global().canvas.selection
## NOTE Now you can use functions given in pixelorama's res://src/UI/Canvas/Selection.gd file.
func menu_item_clicked():
extension_api.selection.select_rect(Rect2(0, 0, 1, 9), 0) ## Copies 9 pixels (From Top to Bottom)
## NOTE: (Other helpful examples)
#extension_api.selection.select_rect(Rect2(0, 0, 1, 9), 0) ## Copies 9 pixels (From Left to Right)
#extension_api.selection.select_rect(Rect2(0, 0, 3, 3), 0) ## Copies 9 pixels (In a Square area)
## NOTE: There is another option called cut (which is just copy + delete original)
## in the api, the "cut" feature is split into two parts (copy + delete_content).
extension_api.selection.copy()
#extension_api.selection.delete_content() ## Uncomment this line to cut instead of copy.
## PRINT the selection size
var selection_size: Rect2i = selection_node.big_bounding_rectangle
extension_api.dialog.show_error(str(selection_size))
func _input(event: InputEvent) -> void:
if event is InputEventKey:
if event.physical_keycode == KEY_A:
selection_node.transform_content_confirm() |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
devmark404
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hy, what happens when you use the paste shortcut (Ctrl + V).
I tried this but it seems to work for me.
test-.9.mp4