[Script] Bookmark Node Positon

User avatar
pingking
Fusionista
Posts: 705
Joined: Thu Aug 14, 2014 9:10 am
Been thanked: 6 times

[Script] Bookmark Node Positon

#1

Post by pingking » Wed Sep 14, 2016 2:03 pm

(splitting this into a seperate thread)
in the discussion about the feature wish for a "bookmark system" which can store specific locations in the composition and you can jump quickly to them i came up with these 2 scripts:

- both are comp scripts
- positions are stored in the comp meta data, so you dont lose them after closing the comp
- currently i store the name of the selected node and jump to this node even if you moved it


script to store the "Bookmarks":
Code: [Select all] [Expand/Collapse] [Download] (storeBookmarkPosition.lua)
  1. --------------------------------------
  2. -- example to recal position and names of tools in the composition metadata
  3. -- and jump the flowView to the selected tool
  4. --
  5. --
  6. -- Michael Vorberg
  7. --
  8. -- CC BY-NC 4.0
  9. -- https://creativecommons.org/licenses/by-nc/4.0/
  10. -----------------------------------------------------------------
  11.  
  12.  
  13. fusion = Fusion()
  14.  
  15. composition = fusion:GetCurrentComp()
  16.  
  17. flow = composition.CurrentFrame.FlowView
  18.  
  19. CurXPos, CurYPos  = flow:GetPos(composition.ActiveTool)
  20. tool = composition:GetAttrs().COMPH_ActiveTool
  21.  
  22. ret = comp:AskUser("Save Position to ...", {
  23.     {"storeName", Name="store as", "Text", Lines = 1, Default = tool:GetAttrs().TOOLS_Name},
  24.     })
  25.  
  26.    
  27. if ret == nil then
  28.     print("cancelled") return
  29. else
  30.     storePositionName = "Position_"..ret.storeName..".name"
  31.     storePositionX = "Position_"..ret.storeName..".x"
  32.     storePositionY = "Position_"..ret.storeName..".y"
  33.     composition:SetData(storePositionName,tool:GetAttrs().TOOLS_Name)
  34.     composition:SetData(storePositionX,CurXPos)
  35.     composition:SetData(storePositionY,CurYPos)
  36.  
  37. end
ideas, feedback and improvements welcome!
Last edited by pingking on Sat Sep 17, 2016 12:09 pm, edited 1 time in total.

User avatar
pingking
Fusionista
Posts: 705
Joined: Thu Aug 14, 2014 9:10 am
Been thanked: 6 times

Re: [Script] Hotspot Nodes

#2

Post by pingking » Wed Sep 14, 2016 2:07 pm

and here the code to jump to the stored positions
Code: [Select all] [Expand/Collapse] [Download] (jumpToBookmarkPosition.lua)
  1. --------------------------------------
  2. -- example to store position and names of tools in the composition metadata
  3. -- to recall them later and jump the flowView to the selected tool
  4. --
  5. -- you can store the positions under any name, but by default it will be the active tools name
  6. --
  7. -- tool/node has to be active to be stored
  8. --
  9. -- Michael Vorberg
  10. --
  11. -- CC BY-NC 4.0
  12. -- https://creativecommons.org/licenses/by-nc/4.0/
  13. -----------------------------------------------------------------
  14. fusion = Fusion()
  15.  
  16. composition = fusion:GetCurrentComp()
  17.  
  18. flow = composition.CurrentFrame.FlowView
  19.  
  20. storedPositionTable = {}
  21.  
  22. for i,v in ipairs(composition:GetData()) do
  23.     a, b = string.find(v, "Position")
  24.     if b ~= nil then
  25.         table.insert( storedPositionTable, string.sub(v, b+2))
  26.        
  27.     end
  28. end
  29.  
  30. ret = comp:AskUser("jump ...", {
  31.     {"PosSlot", Name="to ", "Dropdown", Options = storedPositionTable},
  32.     })
  33.  
  34.    
  35. if ret == nil then print("cancelled") return
  36.  
  37. else
  38.     storePositionName = "Position_"..storedPositionTable[ret.PosSlot+1]..".name"
  39.     storePositionX = "Position_"..storedPositionTable[ret.PosSlot+1]..".x"
  40.     storePositionY = "Position_"..storedPositionTable[ret.PosSlot+1]..".y"
  41.     newX = composition:GetData(storePositionX)
  42.     newY = composition:GetData(storePositionY)
  43.     newName = composition:GetData(storePositionName)
  44.     source = composition:FindTool(newName)
  45.     composition:SetActiveTool(source)
  46.     composition.CurrentFrame.FlowView.SetScale(2)
  47. end
Last edited by pingking on Sat Sep 17, 2016 12:10 pm, edited 1 time in total.

User avatar
ShadowMaker SdR
Fusionista
Posts: 558
Joined: Sun Sep 21, 2014 6:17 am
Been thanked: 3 times

Re: [Script] Hotspot Nodes

#3

Post by ShadowMaker SdR » Wed Sep 14, 2016 3:37 pm

Maybe a different name for it might be a good idea, since we already have an actual tool that's called Hot Spot in Fusion, just to prevent con-Fusion. (Sorry 'bout that)

What about 'X-marks'?

User avatar
Kristof
Fusionista
Posts: 477
Joined: Thu Aug 07, 2014 1:30 pm
Been thanked: 7 times

Re: [Script] Hotspot Nodes

#4

Post by Kristof » Wed Sep 14, 2016 11:41 pm

ShadowMaker SdR wrote:Maybe a different name for it might be a good idea, since we already have an actual tool that's called Hot Spot in Fusion, just to prevent con-Fusion. (Sorry 'bout that)

What about 'X-marks'?
As in X marks the spot? :) Cool. Waypoints, jump-to points, anchors, bookmarks, hooks...

Thanks Pingking, going to give it a whirl!

User avatar
pingking
Fusionista
Posts: 705
Joined: Thu Aug 14, 2014 9:10 am
Been thanked: 6 times

Re: [Script] Bookmark Node Positon

#5

Post by pingking » Sat Sep 17, 2016 12:10 pm

just changed the title of the thread and the names of the scripts

User avatar
Kristof
Fusionista
Posts: 477
Joined: Thu Aug 07, 2014 1:30 pm
Been thanked: 7 times

Re: [Script] Bookmark Node Positon

#6

Post by Kristof » Tue Sep 20, 2016 3:19 am

Hi pingking, a few ideas:

have the list sorted alphabetically (easier to look through)
store the zoom level and average position of selected nodes (in case of multiple selected nodes) as part of the bookmark's settings. A single node is not always the ideal jump-to point and you might need a certain zoom level to be able to really focus on that part of the comp. Like a "fit selection" workflow

Thanks for the script, it is already a great starting point and allows a user to get a taste of what's possible. :)

User avatar
pingking
Fusionista
Posts: 705
Joined: Thu Aug 14, 2014 9:10 am
Been thanked: 6 times

Re: [Script] Bookmark Node Positon

#7

Post by pingking » Tue Sep 20, 2016 12:49 pm

Kristof wrote:Hi pingking, a few ideas:

have the list sorted alphabetically (easier to look through)
store the zoom level and average position of selected nodes (in case of multiple selected nodes) as part of the bookmark's settings. A single node is not always the ideal jump-to point and you might need a certain zoom level to be able to really focus on that part of the comp. Like a "fit selection" workflow

Thanks for the script, it is already a great starting point and allows a user to get a taste of what's possible. :)
sorting the list seams easy, i'll put it on my list for improvements

i wanted to have a system where you can jump to specific XY coordinates in the flow with a certain zoom level. so you can jump to the "Bookmarks" even if the node doesnt exist anymore. but i didnt find a way to do it (okay, i found one, but that was a very silly one). it seems that you can only jump in the flow to specific nodes and not XY positions

User avatar
ColoristNow
Posts: 6
Joined: Mon Oct 30, 2017 3:53 am
Been thanked: 1 time

Re: [Script] Bookmark Node Positon

#8

Post by ColoristNow » Fri Feb 01, 2019 10:48 am

This is awesome! just what I needed.
As a side-note would it be possible to also add an option to delete the bookmarks?

Movalex
Posts: 30
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 5 times

Re: [Script] Bookmark Node Positon

#9

Post by Movalex » Mon Feb 11, 2019 12:34 pm

Here's my little bookmarking script.
Add bookmarks for selected tool, set custom name or use default name. Then invoke jump script and instantly switch to the desired node of your huge comp.
I used Michael's approach and added some features:
* bookmarks sorted alphabetically
* delete single bookmark or reset all
* instant switch between bookmarks without prompt
* submit bookmark addition on press Enter
* close window on press ESC
* do not switch to first bookmark on script launch
* the bookmarked tool can be either active or just selected, whatever

Script requires 64-bit Python v2.7 or v3.6.
Shortcuts are mapped in config file to SHIFT+A and SHIFT+J (Add and Jump respectively)

TODO:
* I'd like to center bookmarked node in a flow. I thought it can be easy done, since we already have Find Tools built-in functionality that centers the tool found in the flow. I even created a topic (viewtopic.php?f=6&t=2812), but nobody answered. So it is either me failed to clearly explain my intent or there's no solution.
* Use shortcut to open bookmarks dropdown of the Jump script on MacOs. It already works on Windows: after script is launched you can use DOWN (or ALT+DOWN) to (visually) switch between bookmarks. It currently does not apply for Mac. There's ShowPopup() method in UIComboBox class, so we could probably assign a key to force show dropdown, but I am not sure how to do that.
* Submit to Reactor (almost done).
Image
Image
You do not have the required permissions to view the files attached to this post.

User avatar
intelligent machine
Fusionista
Posts: 267
Joined: Fri May 13, 2016 10:01 pm
Location: Austin, Texas, USA
Been thanked: 11 times
Contact:

Re: [Script] Bookmark Node Positon

#10

Post by intelligent machine » Mon Feb 11, 2019 8:09 pm

Hey @Movalex
I searched every alternate keyword I could think of in every text and binary document in every fusion folder and came up with nothing....so I worked out a hackaround that gets the centering of the bookmarks 'almost' there.
With some more work and querying of actual window and view dims this could get a lot closer.

So the hack is:
We start by getting the position of the bookmarked tool on the flow.
We then get the flow scale amount that will be used and add two new nodes that are offset in X and Y from the source node's position.
We activate each of those new nodes and then delete them and activate the source.

I added a variable for the scaleFactor so that hopefully each bookmark can have a stored scale. The scaleFactor variable is used for the actual flow scale and to calculate the offsets of the temp nodes.

It doesn't center 100% because as I mentioned, we need to query actual window/view dimensions and use half of that result to create the offsets.

Added in 16 minutes 34 seconds:
Here's the edited file:
(edits marked with '#**')
bookmark_jump-edit.py
You do not have the required permissions to view the files attached to this post.

Movalex
Posts: 30
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 5 times

Re: [Script] Bookmark Node Positon

#11

Post by Movalex » Tue Feb 12, 2019 4:53 am

This is a really nice workaround, thanks! I'm currently onto add scaling preserve for bookmarks.

User avatar
intelligent machine
Fusionista
Posts: 267
Joined: Fri May 13, 2016 10:01 pm
Location: Austin, Texas, USA
Been thanked: 11 times
Contact:

Re: [Script] Bookmark Node Positon

#12

Post by intelligent machine » Tue Feb 12, 2019 10:19 am

I fiddled with it a little more after the last post and found that just offsetting the PipeRouters to a fixed distance and activating from a max zoom (400%) works better considering varying screen widths and tool/modifier panels:

Code: Select all

toolName = "Background1"
print('jump to', toolName)
source = comp.FindTool(toolName)
sx, sy = flow.GetPosTable(source).values()
scaleFactor = 1.75
pr1 = comp.AddTool("PipeRouter", sx - 2, sy - 2)
pr2 = comp.AddTool("PipeRouter", sx + 2, sy + 4)
flow.SetScale(4)
comp.SetActiveTool(pr1)
comp.SetActiveTool(pr2)
flow.Select()
pr1.Delete()
pr2.Delete()
flow.SetScale(scaleFactor)
comp.SetActiveTool(source)

Movalex
Posts: 30
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 5 times

Re: [Script] Bookmark Node Positon

#13

Post by Movalex » Thu Feb 14, 2019 5:50 am

Hey, @intelligent machine!
Here's a bit refactored version of the script, featuring preserve scaling and your slightly modified hackaround for centering bookmark.

Current issues:
1. With hackaround enabled the surrounding tools temporarily disappear until the flow is moved.
2. Centering feature produces unnecessary clutter in comp, so while useful, still a bit annoying. We need a native solution!
3. If the tool is renamed after bookmark add, it will not be found, since the script is looking for tool's name. Dunno how to handle this or even whether it worth handling.

TODO:
Current revision allows to create as many bookmarks for one tool as you like.
Probably it is not optimal, so for current tool we need only one bookmark.
We could check 'TOOLI_ID' of the tool, and if it exists, bookmark will be replaced with the new name.

P.S. You are welcome to make some PR's here: https://github.com/movalex/fusion_scrip ... Bookmarker
You do not have the required permissions to view the files attached to this post.

User avatar
intelligent machine
Fusionista
Posts: 267
Joined: Fri May 13, 2016 10:01 pm
Location: Austin, Texas, USA
Been thanked: 11 times
Contact:

Re: [Script] Bookmark Node Positon

#14

Post by intelligent machine » Thu Feb 14, 2019 9:04 am

@Movalex Working pretty well so far.
A few suggestions:
1. Creating bookmarks that begin with numbers will produce errors.
I'd suggest either testing for that and automatically preceding with an underscore if true or throwing up a "not allowed" warning message.

2. If possible, combine the "add" and "jump to" functions into a single UI (the "jump to" UI with an additional button to bring up the add dialog - refresh list after add)

3. make the window dockable if possible.

4. maybe make the dropdown and buttons inline and change buttons to just icons (trash can, reset (mail reply), and plus sign) - more relevant to #3 above if this could be docked and kept minimal.

Movalex
Posts: 30
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 5 times

Re: [Script] Bookmark Node Positon

#15

Post by Movalex » Thu Feb 14, 2019 9:32 am

Thank you for reviewing this!

Here's a quick-fix for first digit symbol bug.

I thought about combining this tool into single UI, but actually I like simplicity in design. Add tool is meant to appear at the time we add something, otherwise it is useless distraction. It is a great point about refreshing list, so we don't need to relaunch Jump script if something added. Probably it would be nice to create tiny '+' button in Jump UI that will invoke Add script.
Not sure if the windows can be dockable...
You do not have the required permissions to view the files attached to this post.