Notifications
Clear all

[Closed] gw.PrintInViewport

Hi is any smart way how i can stop print my fn when i don’t need it anymore . Because now when i don’t want run my script i must restart whole max stop run my script and i think it must be some other way

Thanks

fn PrintInViewport =
for i in $** where i.isHidden == false do
(
gw.setTransform(Matrix3 1)
textpos = gw.wTransPoint i.center
gw.wtext textpos i.name color:[255,255,255]
gw.enlargeUpdateRect #whole
gw.updateScreen()
)
unregisterRedrawViewsCallback PrintInViewport
registerRedrawViewsCallback PrintInViewport

5 Replies

Hi Peter and welcome,
to manage the viewport callback you need some interface to trigger it on and off. The following code creates a simple rollout with a checkbutton for your function.


rollout rolShowName "Show Names"
(
-- Rollout Interface

    checkButton cbtActive "Activate!" width:80 align:#center

-- Drawing Function

    function printInViewport =
    (
        gw.setTransform(Matrix3 1)
        
        for item in objects where (item.isHidden == false) do
        (
            gw.text item.center item.name color:white
        )

        gw.enlargeUpdateRect #whole
        gw.updateScreen()
    )

-- Interface Events

    on cbtActive changed bState do
    (
        unregisterRedrawViewsCallback printInViewport

        if (bState == true) then
        (
            registerRedrawViewsCallback printInViewport
        )

        forceCompleteRedraw()
    ) 

-- Rollout Events, just to be safe

    on rolShowName close do
    (
        unregisterRedrawViewsCallback printInViewport
        forceCompleteRedraw()
    )
)
createDialog rolShowName 90 30 style:#(#style_toolwindow, #style_border, #style_sysmenu)

  • Enrico

p.s. Your code looks better if enclosed into CODE tags.

Hi

Thanks for help SyncViewS and i promise next time i try use code tags for my script problem:) So if i understand this code right switch off in code is present with ” unregisterRedrawViewsCallback ” command but important is call this code in right time and in right way

So here is what i proposed. But i would like still to know if will be possible make this script initialize by keybord shortcut . On and Off by press keybord during work . I think that will be more faster and flexible how pressing button One more thanks for Enrico help i hope you found this script useful for your work in Max or inspiration.

 
macroScript Activate_Name category:"Kepo4Max" tooltip:"Activate Name" buttontext:"Activate Name"
(
rollout rolShowName "Show Names"
(
-- Rollout Interface
	checkButton cbtActive "Activate Names" width:110
	label lab1 "Kepo4Max@gmail.com"
-- Drawing Function
	function printInViewport =
	( 
		for i in $** where i.isHidden == false do
		(
gw.setTransform(Matrix3 1)
textpos = gw.wTransPoint i.center
			gw.wtext textpos i.name color:black
gw.wtext (textpos+[1,1,0]) i.name color:yellow
		)
		gw.enlargeUpdateRect #whole
		gw.updateScreen()
	)
-- Interface Events
	on cbtActive changed bState do
(
		unregisterRedrawViewsCallback printInViewport
		if (bState == true) then
		(
			registerRedrawViewsCallback printInViewport
		)
		forceCompleteRedraw()
	) 
-- Rollout Events, just to be safe
	on rolShowName close do
	(
		unregisterRedrawViewsCallback printInViewport
		forceCompleteRedraw()
	)
)
createDialog rolShowName 120 50 style:#(#style_toolwindow, #style_border, #style_sysmenu)
)

Hi Peter,
this new version doesn’t have an interface, unless you create a button through standard Max Customize User Interface panel. You can associate a shortcut to it and it will toggle object names in your scene. In this case the action is handled by the macroscript event “on execute”, and the rollout is only a placeholder for variables and functions.


macroScript ActivateName category:"Kepo4Max" tooltip:"Activate Name" buttontext:"Activate Name"
(
    -- the rollout is declared as a global function to be accessible without
    -- any interface
    global rolActivateName

    -- the rollout in this case is only a placeholder for variables and functions
    -- and will not be displayed
    rollout rolActivateName ""
    (
        -- the variable inside the rollout that traces the drawing callback status
        local bState = false
    
-- Drawing Function

        -- the drawing function
        function printInViewport =
        (
            -- gw.setTransform can be called once only (out of loop) 
            gw.setTransform(Matrix3 1)
            
            for item in objects where (item.isHidden == false) do
            (
                local p3TextPos = gw.wTransPoint item.center
                gw.wText p3TextPos item.name color:black
                gw.wText (p3TextPos + [1, 1, 0]) item.name color:yellow
            )
            -- gw.enlargeUpdateRect and gw.updateScreen can be called once only
            -- (out of loop)
            gw.enlargeUpdateRect #whole
            gw.updateScreen()
        )
    )

-- MacroScript Event

    -- when the macroscript is executed, the drawing callback is toggled;
    -- a toolbar button or a keyboard shortcut can be associated to the
    -- macroscript in the standard customization panel
    
    on execute do
    (
        -- to access functions and variables inside the rollout the full path
        -- must to be specified: rollout.variable or rollout.function

        if (rolActivateName.bState == false) then
        (
            registerRedrawViewsCallback rolActivateName.printInViewport
            rolActivateName.bState = true
        )
        else
        (
            unregisterRedrawViewsCallback rolActivateName.printInViewport
            rolActivateName.bState = false
        )

        forceCompleteRedraw()
    )
)

  • Enrico

p.s. If you want to try this script, be sure to remove any previous version from Max scripts folder. In WinXp you can find it in: .\Documents and Settings<user>\Local Settings\Application Data\Autodesk\3dsmax<max version>\enu\UI\usermacros

Thanks Enrico. That is exactly what i wanted. Absolutely perfect.