I have no knowledge in coding and making scripts. can anybody help to make such a script? I have not to render an animation, so the region has not to follow anything.
thanks for helping. but auto region is better for this I have tried the vrayspherefade.
I have made “mask” objects for the regions, so the only thing is missing is the script to select the object before rendering.
if someone could help I am willing to pay for the work. pm me, please
After doing a bit of reading it appears that some features in Max are buggy and others are badly implemented - difficult to believe I know
Unfortunately for us two of these features are pre-render scripts and auto region. There are other ways to do this I think…
Ok, I’ve got something working if anyone would like to test it.
Run the script then select an object and press the ‘set region’ button. At the moment it only works for single objects and doesn’t work if pixel aspect is set to something other than 1 in render settings. Both of these can limitations can be lifted with a bit more work if required.
(
try (destroyDialog BBautoRegion) catch ()
rollout BBautoRegion "AutoRegion 1.0"
(
fn bb2rect =
(
renderSceneDialog.close()
vpSize = getViewSize()
BBmask = $
gw.setTransform(Matrix3 1)
gwMin = gw.wTransPoint BBmask.center
gwMax = gw.wTransPoint BBmask.center
objBB = nodeGetBoundingBox BBmask (Matrix3 1) --get selection BB in worldspace co-ordsys
for zi = 1 to 2 do
(
for yi = 1 to 2 do
(
for xi = 1 to 2 do
(
gw.setTransform(Matrix3 1)
wsPt = point3 obJBB[xi][1] objBB[yi][2] objBB[zi][3]
gwPnt = gw.wTransPoint wsPt
if (gwPnt.x < gwMin.x) then
(
if (gwPnt.x > 0) then (gwMin.x = gwPnt.x) else (gwMin.x = 0) --set gwMin.x
)
if (gwPnt.y < gwMin.y) then
(
if (gwPnt.y > 0) then (gwMin.y = gwPnt.y) else (gwMin.y = 0) --set gwMin.y
)
if (gwPnt.x > gwMax.x) then
(
if (gwPnt.x < vpSize.x) then (gwMax.x = gwPnt.x) else (gwMax.x = vpSize.x) --set gwMax.x
)
if (gwPnt.y > gwMax.y) then
(
if (gwPnt.y < vpSize.y) then (gwMax.y = gwPnt.y) else (gwMax.y = vpSize.y) --set gwMax.x
)
) --end x loop
) --end y loop
) --end z loop
if getRendImageAspect() < (vpSize.x/vpSize.y) then
(
roScale = (renderHeight/vpSize.y)
roPad = ((vpSize.x*roScale)-(renderWidth))/2
roRegion = box2 (point2 ((gwMin.x*roScale)-roPad) (gwMin.y*roScale)) (point2 ((gwMax.x*roScale)-roPad) (gwMax.y*roScale))
)
else
(
roScale = (renderWidth/vpSize.x)
roPad = ((vpSize.y*roScale)-(renderHeight))/2
roRegion = box2 (point2 (gwMin.x*roScale) ((gwMin.y*roScale)-roPad)) (point2 (gwMax.x*roScale) ((gwMax.y*roScale)-roPad))
)
EditRenderRegion.IsEditable = true
if viewport.activeViewport != 0 then viewport.setRegionRect viewport.activeViewport roRegion
EditRenderRegion.UpdateRegion()
setRenderType #region
renderSceneDialog.open()
)--end fn bb2rect
button setRegion "Set Region"
on setRegion pressed do
(
if selection.count == 1 then
(
unregisterRedrawViewsCallback bb2rect
registerRedrawViewsCallback bb2rect
redrawViews()
unregisterRedrawViewsCallback bb2rect
redrawViews()
)
)
)--end rollout
createDialog BBautoRegion
)
Here’s a later version that works with multiple object selections:
try (destroyDialog BBautoRegion) catch ()
rollout BBautoRegion "AutoRegion"
(
local sfState
local selChanged
on BBautoRegion open do
(
sfState = displaySafeFrames
displaySafeFrames = true
unregisterRedrawViewsCallback bb2rect
)
on BBautoRegion close do
(
displaySafeFrames = BBautoRegion.sfState
unregisterRedrawViewsCallback bb2rect
BBautoRegion.selChanged = undefined
gc light:true
)
fn bb2rect =
(
if $ != undefined then
(
renderSceneDialog.close()
vpSize = getViewSize()
gw.setTransform(Matrix3 1)
sel = getCurrentselection() as array
BBmask = sel[1]
gwMin = gw.wTransPoint BBmask.center
gwMax = gw.wTransPoint BBmask.center
for BBmask in sel do
(
objBB = nodeGetBoundingBox BBmask (Matrix3 1) --get selection BB in worldspace co-ordsys
for zi = 1 to 2 do
(
for yi = 1 to 2 do
(
for xi = 1 to 2 do
(
gw.setTransform(Matrix3 1)
wsPt = point3 obJBB[xi][1] objBB[yi][2] objBB[zi][3]
gwPnt = gw.wTransPoint wsPt
if (gwPnt.x < gwMin.x) then
(
if (gwPnt.x > 0) then (gwMin.x = gwPnt.x) else (gwMin.x = 0) --set gwMin.x
)
if (gwPnt.y < gwMin.y) then
(
if (gwPnt.y > 0) then (gwMin.y = gwPnt.y) else (gwMin.y = 0) --set gwMin.y
)
if (gwPnt.x > gwMax.x) then
(
if (gwPnt.x < vpSize.x) then (gwMax.x = gwPnt.x) else (gwMax.x = vpSize.x) --set gwMax.x
)
if (gwPnt.y > gwMax.y) then
(
if (gwPnt.y < vpSize.y) then (gwMax.y = gwPnt.y) else (gwMax.y = vpSize.y) --set gwMax.x
)
) --end x loop
) --end y loop
)--end z loop
)--end o loop
if getRendImageAspect() < (vpSize.x/vpSize.y) then
(
roScale = (renderHeight/vpSize.y)
roPad = ((vpSize.x*roScale)-(renderWidth))/2
roRegion = box2 (point2 ((gwMin.x*roScale)-roPad) (gwMin.y*roScale)) (point2 ((gwMax.x*roScale)-roPad) (gwMax.y*roScale))
)
else
(
roScale = (renderWidth/vpSize.x)
roPad = ((vpSize.y*roScale)-(renderHeight))/2
roRegion = box2 (point2 (gwMin.x*roScale) ((gwMin.y*roScale)-roPad)) (point2 (gwMax.x*roScale) ((gwMax.y*roScale)-roPad))
)
EditRenderRegion.IsEditable = true
if viewport.activeViewport != 0 then viewport.setRegionRect viewport.activeViewport roRegion
EditRenderRegion.UpdateRegion()
setRenderType #region
renderSceneDialog.open() --need test for previous state
displaySafeFrames = true --need test for previous state
)
)--end fn bb2rect
fn autobb2rect ev nd =
(
registerRedrawViewsCallback bb2rect
redrawViews()
unregisterRedrawViewsCallback bb2rect
redrawViews()
)
button setRegion "Set Region" pos:[5,10]
checkButton autoRegion "Auto Region" pos:[80,10]
on setRegion pressed do
(
if selection.count == 1 then
(
autobb2rect 1 1
)
)
on autoRegion changed state do
(
if state == true then
(
autobb2rect 1 1
BBautoRegion.selChanged = NodeEventCallback mouseUp:true selectionChanged:autobb2rect --all:autobb2rect
)
else
(
selChanged = undefined
gc light:true
)
)
)--end rollout
createDialog BBautoRegion
I’m not any of my scripts are worth selling. I started a page on Scriptspot about 2 years ago but I have posted anything on there yet. Hopefully I’ll have time to upload something soon.
They both do the same thing (set the renderer to region and set the region to the current selection) apart from while ‘auto region’ is pressed the region is automatically redrawn if the selection changes or is moved.