measure floater


#1

Hello scripting gurus,
Was looking for a script to invoke the “measure floater” by bypassing the utilities panel and found this one from Bobo, which is a few versions old and doesnt seem to be working on 2016. Since I dont know squat about maxscript, would anyone be kind enough to take a look a it and tell me how to fix it?

[I]macroScript OpenMeasureFloater
category:“Forum Help”
buttontext:“Measure!”
tooltip:“Open the Measure Floater with one click!”
(
fn openMeasureFloater =
(
WM_SETREDRAW=0xB
commandHWND = windows.getChildHWND #max “Command Panel”
windows.sendmessage commandHWND[1] WM_SETREDRAW 0 0
local result = false --flag for success/failure
local oldPannel = getCommandPanelTaskMode() --remember the old command panel tab
UtilityPanel.OpenUtility measure --open Utility tab and enable Measure Utility
local theMeasureUtil = windows.getChildHWND #max “Measure” --grab the Measure’s rollout handle
if theMeasureUtil.count > 0 do --if it was found,
(
local theButton = windows.getChildHWND theMeasureUtil[7] “New Floater” --get the New Floater button’s handle
print theButton
if theButton.count > 0 do --if this succeeded too, then send messages to click it
(
Windows.sendMessage theButton[1] 0x201 0 0 --Left Mouse Button Down
Windows.sendMessage theButton[1] 0x202 0 0 --Left Mouse Button Up
result = true --raise the flag for success
)
)
setCommandPanelTaskMode oldPannel --switch back to the previous command panel tab
windows.sendmessage commandHWND[1] WM_SETREDRAW 1 0
result --return result
)

openMeasureFloater()
)
[/I]
Huge thanks!


#2

It works fine here.
Do you use a localized Max version?


#3

Thanks for responding!

Localized Max version? What do you mean by that?


#4

I mean a different language than English for the UI.

The script relies on the Labels of the controls. So it looks first for a control with label “Measure” and then for a button labeled “New Floater”.

This is for English version, but for other languages the labels might be different and so the script can’t find them.


#5

All english here.

I get a : -No “get” function for undefined- comment when running the script


#6

Ok, hard to tell what it might be. See if this works:

macroScript OpenMeasureFloater
 category:"Forum Help"
 buttontext:"Measure!"
 tooltip:"Open the Measure Floater with one click!"
 (
 	fn openMeasureFloater =
 	(
 		--WM_SETREDRAW=0xB
 		--commandHWND = windows.getChildHWND #max "Command Panel"
 		--windows.sendmessage commandHWND[1] WM_SETREDRAW 0 0
 		--local result = false --flag for success/failure
 		local oldPannel = getCommandPanelTaskMode() --remember the old command panel tab
 		UtilityPanel.OpenUtility measure --open Utility tab and enable Measure Utility
 		local theMeasureUtil = windows.getChildHWND #max "Measure" --grab the Measure's rollout handle
 		if theMeasureUtil.count > 0 do --if it was found,
 		(
 			local theButton = windows.getChildHWND theMeasureUtil[7] "New Floater" --get the New Floater button's handle
 			if theButton.count > 0 do --if this succeeded too, then send messages to click it
 			(
 				Windows.sendMessage theButton[1] 0x201 0 0 --Left Mouse Button Down
 				Windows.sendMessage theButton[1] 0x202 0 0 --Left Mouse Button Up
 				result = true --raise the flag for success
 			)
 		)
 		setCommandPanelTaskMode oldPannel --switch back to the previous command panel tab
 		--windows.sendmessage commandHWND[1] WM_SETREDRAW 1 0
 		--result --return result
 	)
 
 	openMeasureFloater()
 )

#7

Still no go.
Now getting : unknown property “count” in undefined
Would the fact that my command panel is on another monitor have anything to do?

Thanks again for taking the time, Jorge. Much appreciated!


#8

I see. You have the Command Panel undocked.
This should work with both docked and undocked Command Panel (I hope) :slight_smile:

macroScript OpenMeasureFloater
       category:"Forum Help"
       buttontext:"Measure!"
       tooltip:"Open the Measure Floater with one click!"
       (
       	
       	fn openMeasureFloater =
       	(
       		WM_SETREDRAW = 0xB
       		WM_LBUTTONUP = 0x202
       		WM_LBUTTONDOWN = 0x201
       
       		local result = false
       		local oldPannel = getCommandPanelTaskMode()
       		
       		commandHWND = windows.getChildHWND #max "Command Panel"
       		if commandHWND == undefined do commandHWND = windows.getChildHWND 0P "Command Panel"
       		
       		windows.sendmessage commandHWND[1] WM_SETREDRAW 0 0
       		
       		UtilityPanel.OpenUtility measure
       		
       		local theMeasureUtil = windows.getChildHWND #max "Measure"
       		if theMeasureUtil == undefined do theMeasureUtil = windows.getChildHWND (windows.getDesktopHWND()) "Measure"
       
       		if theMeasureUtil != undefined do
       		(
       			local theButton = windows.getChildHWND theMeasureUtil[7] "New Floater"
       			
       			if theButton != undefined and theButton.count > 0 do
       			(
       				Windows.sendMessage theButton[1] WM_LBUTTONDOWN 0 0
       				Windows.sendMessage theButton[1] WM_LBUTTONUP 0 0
       				result = true
       			)
       		)
       		setCommandPanelTaskMode oldPannel
       		windows.sendmessage commandHWND[1] WM_SETREDRAW 1 0
       		return result
       	)
       	
       	openMeasureFloater()
       	
       )

[b]The above code is a modified version of a Script created by Borislav Petrov (Bobo).

[/b]


#9

Working!
Cant thank you enough, Jorge. This is gonna save me a lot of clicking around.
And it’s about time I started delving into maxscripting…

Thanks again :thumbsup:


#10

Hi, This is great thanks. I use it.
I am a novice at maxscript .
But I would like to position the Measure Floater in a corner or on the next screen. I think this should be possible with the offset :[1000, 400] or using the “pos:” command . I keep getting undefined errors.


#11

This should work. The command panel will “flash”, but that is not an issue.
Getting the Command Panel HWND is different in some Max versions. There is code in this forum to get it if you need.

macroScript OpenMeasureFloater
	category:"Forum Help"
	buttontext:"Measure!"
	tooltip:"Open the Measure Floater with one click!"
(
	fn OpenMeasureFloater =
	(
		local posx   = 1000
		local posy   = 400
		local width  = 180
		local height = 0		-- Can't set
		
		local WM_LBUTTONDOWN = 0x201
		local WM_LBUTTONUP   = 0x202
		
		local oldPannel = getCommandPanelTaskMode()
		
		UtilityPanel.OpenUtility measure
		
		local floater
		
		local theMeasureUtil = windows.getChildHWND #max "Measure"
		if theMeasureUtil == undefined do theMeasureUtil = windows.getChildHWND (windows.getDesktopHWND()) "Measure"
		
		if theMeasureUtil != undefined do
		(
			local theButton = windows.getChildHWND theMeasureUtil[7] "New Floater"
			
			if theButton != undefined and theButton.count > 0 do
			(
				Windows.sendMessage theButton[1] WM_LBUTTONDOWN 0 0
				Windows.sendMessage theButton[1] WM_LBUTTONUP 0 0
				
				floater = windows.getChildHWND 0 "Measure" parent:#max
				if floater != undefined do windows.setWindowPos floater[1] posx posy width height true
			)
		)
		
		setCommandPanelTaskMode oldPannel
		
		return floater
	)
	openMeasureFloater()
)

#12

Why are you so turned on? :wink:

you know every woman should have a mini black dress … it does … every technical artist should write its own measuring tool :slight_smile:


#13

Thanks for this. It works.
I am still trying to move the Measure dialog to another part of the screen. I thought perhaps this could be done using theMeasureUtil.pos with leftPosition and downPosition. or just [1000, 800].

I am very new to maxscript. What is the syntax for parsing “left” and “down” to theMeasureUtil.pos?

Any help appreciated.