I'm trying to create a maxscript which offsets selected keyframes in the curve editor by specified amount to aid in some animation however I have zero experience in scripting in max. I tried searching on scriptspot for relevant tools but none seems to fit my need and script listener is not helping.
Currently, I only have the UI done
rollout MoveKeyTool "Move Key"
(
group "Settings"
(
spinner OffsetBySpn "Offset by" type:#integer
button OffsetFramesBt "Offset Keyframes"
on OffsetFramesBt pressed do
(
)
)
)
createdialog MoveKeyTool
Any help or advice is greatly appreciated, thank you.
try destroyDialog ::MoveKeyTool catch()
rollout MoveKeyTool "Move Key"
(
group "Settings"
(
spinner OffsetBySpn "Offset by" type:#integer range:[-1e3,1e3,10]
button OffsetFramesBt "Offset Keyframes"
on OffsetFramesBt pressed do
(
local currentTV = trackViews.current
if currentTV == undefined do return messageBox "Trackview window has to be open."
local selCount = currentTV.numSelTracks()
for i = 1 to selCount
where (local ctrl = currentTV.getSelected i).keyable do
moveKeys ctrl OffsetBySpn.value #selection
)
)
)
createdialog MoveKeyTool
Related
I work with 2 monitors on macOS. Under System Preferences >> Displays >> Appearances, I can change the display setup so that monitors are either side by side, one on top of the other, etc.
I often need to change the setup from side by side to one below the other, and it's painful to have to go into System Preferences and change it manually every time.
How do I go about setting it up so it does it automatically when I press some "hotkey" or keyboard shortcut?
I have access to Alfred for Mac so can code in custom workflows which should help achieve this.
Any ideas would be much appreciated!
Here's a script that calls a python script to switch between display sets. It's only set up to change the relative position of the second display, but it can easily be expanded to work with three or more displays.
Note that you don't have to be precise about the new position. Quartz will automatically adjust things to give the nearest configuration in which the display spaces touch seamlessly.
set displaySet to first item of ¬
(choose from list {"On left", "On right", "On top", "On bottom"} ¬
with prompt "Choose position for second display.")
(* assuming 1280 x 800 pixel displays *)
if displaySet is "On top" then
changeSecondDisplayOrigin(0, -800)
else if displaySet is "On bottom" then
changeSecondDisplayOrigin(0, 800)
else if displaySet is "On left" then
changeSecondDisplayOrigin(-1280, 0)
else
changeSecondDisplayOrigin(1280, 0)
end if
on changeSecondDisplayOrigin(x, y)
do shell script "
/usr/bin/python <<END
import objc
import Quartz
from Quartz.CoreGraphics import CGGetActiveDisplayList
from Quartz.CoreGraphics import CGBeginDisplayConfiguration
from Quartz.CoreGraphics import CGConfigureDisplayOrigin
from Quartz.CoreGraphics import CGCompleteDisplayConfiguration
(activeErr, activeDisplays, displayCount) = Quartz.CGGetActiveDisplayList(2, None, None);
secondDisplay = activeDisplays[1];
(configErr, displayConfigRef) = CGBeginDisplayConfiguration(None);
moveErr = CGConfigureDisplayOrigin(displayConfigRef, secondDisplay, " & x & ", " & y & ");
completeErr = CGCompleteDisplayConfiguration(displayConfigRef, 2);
END"
end changeSecondDisplayOrigin
I am having problems making a reactive app to show the map of a given state. I want the app to react ONLY WHEN I click "Show map", but for some reason with the following code, after the first click on "Show map", the output changes whenever I change the input (state), whether or not I click the button again.
library(shiny)
ui <- fluidPage(
titlePanel("Show map of a given state"),
sidebarLayout(
sidebarPanel(
textInput("state", label = "State", value = "CA", placeholder = "California or CA"),
actionButton("showU","Show map")
),
mainPanel(
conditionalPanel(
condition = "input.showU > 0",
h3(textOutput("state")),
uiOutput("url")
)
)
)
)
server <- function(input, output){
observeEvent(input$showU,{
output$state <- renderText(paste("Map of", input$state, ":"))
output$url <-renderUI({a(href=paste("https://www.google.com/maps/place/", input$state, sep=""),"Show in Google Map",target="_blank")})
})
#output$state <- eventReactive(input$showU, renderText(paste("Map of", input$state, ":")))
#output$url <- eventReactive(input$showU, renderUI({a(href=paste("https://www.google.com/maps/place/", input$state, sep=""),"Show in Google Map",target="_blank")}))
}
shinyApp(ui,server)
I thought observeEvent or eventReactive (the code that's commented out; doesn't work either) is supposed to delay reaction until I click the action button but it's not doing that. Can anybody help me figure out what is wrong here? Thank you!
It's because you call input$xxx within renderYYY. You can use isolate():
observeEvent(input$showU,{
output$state <- renderText(paste("Map of", isolate(input$state), ":"))
output$url <-renderUI({a(href=paste("https://www.google.com/maps/place/", isolate(input$state), sep=""),"Show in Google Map",target="_blank")})
})
Can anyone show a way to make dynamic UI elements in maxscript?
For example. I can insert a image button in the ui, but i'd like to control the scale of the image based on the value of a slider element.
I did find a way to make a dynamic user interface,
that was the first part of the problem.
But i did not get it to make image button sizes dynamic yet.(mainly because if i use group elements in the way i want to, then the position of every element is hard coded.
try(destroydialog dRolH) catch()
rollout dRolH "Dialog" height:200 width:200
(
dropdownlist rolList "Rollouts: " items:#("Rollout A", "Rollout B", "Rollout C") width:175 offset:[0,0]
checkbox lbA "A" pos:[14,50] visible:off
checkbox lbB "B" pos:[14,50] visible:off
checkbox lbC "C" pos:[14,50] visible:off
local rolls = #(#(lbA), #(lbB), #(lbC))
on rolList selected sel do
(
for k=1 to rolls.count do for c in rolls[k] do c.visible = (k == sel)
)
)
createDialog dRolH pos:[740, 200]
See, this is a bit more complicated.
Changing the width and height values of the bitmap element is pretty easy:
bitmap bm "Bitmap:" filename:#"some/file/path.jpg" -- create the bitmap UI element
bm.width = 100
bm.height = 100
But this will only change the size of the bitmap framing. You will also need to rerender the bitmap in a new resolution and switch out the old one. I have implemented this in your code here:
try(destroydialog dRolH) catch()
rollout dRolH "Dialog" height:200 width:200
(
dropdownlist rolList "Rollouts: " items:#("Rollout A", "Rollout B", "Rollout C") width:175 offset:[0,0]
checkbox lbA "A" pos:[14,50] visible:off
checkbox lbB "B" pos:[14,50] visible:off
checkbox lbC "C" pos:[14,50] visible:off
spinner s "Size (%)" range:[0,1000,100]
local bm_height = 128
local bm_width = 128
bitmap bm "Bitmap" height:bm_height width:bm_width fileName:#"C:\ProgramData\Microsoft\User Account Pictures\Default Pictures\usertile12.bmp"
fn scaleAndReloadImage factor =
(
-- New sizes
bm.height = bm_height * factor
bm.width = bm_width * factor
-- Loadimage and
local image = Bitmaptexture filename:#"C:\ProgramData\Microsoft\User Account Pictures\Default Pictures\usertile12.bmp"
-- Rerender into new bitmap
local new_bm = bitmap bm.width bm.height
rendermap image into:new_bm size:([image.bitmap.width,image.bitmap.height]) filter:on display:off gamma:2.2
-- Assign new bitmap
bm.bitmap = new_bm
)
-- EVENTS
local rolls = #(#(lbA), #(lbB), #(lbC))
on rolList selected sel do
(
for k=1 to rolls.count do for c in rolls[k] do c.visible = (k == sel)
)
on s changed val do
(
if val == 0 then s.value = val = 100 -- Resets to 100 on rightclick
local factor = val / 100 -- Scaling factor
scaleAndReloadImage factor
)
on dRolH open do
(
scaleAndReloadImage 1 -- Render image from start, to secure uniform gamma
)
)
createDialog dRolH pos:[740, 200] height:400
I have put in a few comments for you as well.
Happy hacking :D :)
/goehler
NB: The address I use for the bitmap will probably only work in Windows 7 - but I imagine you have the sense to use another address if need be :)
I currently have an AHK script which switches the scrolling direction of my mouse.
WheelUp::
Send {WheelDown}
Return
WheelDown::
Send {WheelUp}
Return
My colleagues don't like this and use my computer sometimes.
How can I assign a shortkey to switch the scrolling direction?
What I want:
When I press win+z the scrolling direction is changed, when I pres win+z again, the scrolling direction is changed back.
So basically the scrolling direction can be changed when pressing win+z
Is that possible with AHK?
Yes you can modify your hotkeys to have more code.
You will have to use if statements and variables.
Example:
global direction := 1
^s:: ; ctrl + s will launch this code you can modify this to win + z
direction := Mod( direction + 1 , 2 ) ; alternates values of direction between 1 and 0
return
WheelUp::
if(direction)
Send {WheelDown}
else
Send {WheelUp}
Return
; and reverse for wheeldown
In Windows 7, you can give focus to a window just by hovering over it with the mouse. This feature is not enabled by default, but you can enable it in the Control Panel. (Here is the path to take:
[Ease of Access Center-->Make the mouse easier to use-->check "Activate a window by hovering over it with the mouse"]).
I like this feature a lot, but sometimes it annoys me when I try to open a C# class in Visual Studio using Resharper. I'll hit CTRL+N and type the name of the class I want to see (for example, "MyWpfClass"). Resharper will then show a dropdown of suggestions with "MyWpfClass" on top. I hit return, and now Resharper opens a dropdown which lets me choose between "MyWpfClass.xaml" and "MyWpfClass.xaml.cs". However, if the mouse cursor is in the wrong place, the dropdown closes within a second and I'm back to square one. Is there a way to fix this without turning the focus-follows-mouse feature off?
I was having the same problem with MS Outlook: the auto-suggestions list for contacts would close automatically because Windows treated it as a window rather than part of the New Message window.
You could use NiftyWindows, which has the same option "Focus Follows Mouse", accessible through its context menu.
Alternatively, as it is written in Autohotkey, you could use extract and run its subroutine "XWN_FocusHandler" into a standalone script:
#Persistent
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn All, OutputDebug ; Recommended for catching common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTimer, XWN_FocusHandler, 100
return
XWN_FocusHandler:
CoordMode, Mouse, Screen
MouseGetPos, XWN_MouseX, XWN_MouseY, XWN_WinID
If ( !XWN_WinID )
Return
If ( (XWN_MouseX != XWN_MouseOldX) or (XWN_MouseY != XWN_MouseOldY) )
{
IfWinNotActive, ahk_id %XWN_WinID%
XWN_FocusRequest = 1
Else
XWN_FocusRequest = 0
XWN_MouseOldX := XWN_MouseX
XWN_MouseOldY := XWN_MouseY
XWN_MouseMovedTickCount := A_TickCount
}
Else
If ( XWN_FocusRequest and (A_TickCount - XWN_MouseMovedTickCount > 500) )
{
WinGetClass, XWN_WinClass, ahk_id %XWN_WinID%
If ( XWN_WinClass = "Progman" )
Return
; checks wheter the selected window is a popup menu
; (WS_POPUP) and !(WS_DLGFRAME | WS_SYSMENU | WS_THICKFRAME)
WinGet, XWN_WinStyle, Style, ahk_id %XWN_WinID%
If ( (XWN_WinStyle & 0x80000000) and !(XWN_WinStyle & 0x4C0000) )
Return
IfWinNotActive, ahk_id %XWN_WinID%
WinActivate, ahk_id %XWN_WinID%
XWN_FocusRequest = 0
}
Return