how can i get the currently selected card in the canvas?
I’ve tried using
this.registerEvent(this.app.workspace.on('file-open', (file: TFile ) => {
//file given doesn't contain the id of CanvasTextData within the CanvasNodeData of the canvas
//all i can get is the name
file.name
//the file name will either be the canvas ur currently open in,
//or if it's a CanvasFileData type you will get back the name of the file
}));
I wanted to be able to get the id of the current selected node in the canvas
i feel like im looking for a needle in a haystack, surely there must be a method on either he workspace or workspaceleaf that will give me the id of the currently selected node in the canvas??
Just saw your post and it got me thinking. I think that to get the currently selected card ID in the canvas, you can access the active view and then get the selection. This will give you a list of all the selected nodes and their IDs.
If you need to verify documents or IDs for your projects, try www.idanalyzer.com. They have an API that helps verify the authenticity of documents and IDs, which can be really useful for many tasks.
@Tekashi’s code snippet looks very useful to me.
But, unfortunately, I don’t know where to run it from.
const canvasView = this.app.workspace.getActiveViewOfType(ItemView);
if (canvasView?.getViewType() !== 'canvas') return;
const canvas = (canvasView as any).canvas;
const selection: any = Array.from(canvas.selection);
Could anyone, please, tell me where to store this script and how to launch it from within Obsidian.
Sorry, I’m very new to Obsidian and just trying to dive into the world of plugins, commands and scripting.
Do I need to create a plugin to be able to run this code or is there a “lighter” way to run this code?
Info:
My final goal is to write a script that gets the images that are selected within a canvas (multiple files) and to select them in the navigation view (in order to be able yo bulk move them from there).
I created a feature request for this as well here:
But, maybe this could be done faster via scripting.