[Closed] New script: cross section slider
– UPDATE
After taking some time to work on other things, I have finally updated this script. I have removed some redundant variables, added some user interface options, and the script is now able to create cross sections from multiple directions.
I am currently trying to figure out how to make it dynamically update when the original object is moved or rotated (it will need to run the createCSec function from the rollout).
-- Cross Section
-- crossSection.ms
-- Version 0.4 (10/10/08)
-- by Kevin Mackey (kmackey2001@hotmail.com)
-- This script creates a cross section of a selected object using a simple boolean.
-- Suggestions are welcome.
rollout cSecSlider "Cross Section"
(
local target, dimBox, refTgt
local csAmt = 0
fn deleteOld =
(
-- delete the previous dimension box, cross section box, and reference
if (isValidNode dimBox) and (dimBox != undefined) do delete dimBox
if (isValidNode crsBox) and (crsBox != undefined) do delete crsBox
if (isValidNode refTgt) and (refTgt != undefined) do delete refTgt
)
fn createCSec =
(
deleteOld()
-- get the x, y, and z dimensions of the target object
xDim = (target.max.X - target.min.X)
yDim = (target.max.Y - target.min.Y)
zDim = (target.max.Z - target.min.Z)
minPos = target.center
maxPos = target.center
--set the box and cross section dimensions and transforms based on the direction of the cross section
case cSecSlider.rad_Direction.state of
(
1: (
minPos.z = target.min.z; maxPos.z = target.max.z
dimBox = box length:yDim width:xDim height:(zDim - (zDim * csAmt)) transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] minPos)
crsSec = box length:yDim width:xDim height:(zDim * csAmt) transform:(matrix3 [1,0,0] [0,-1,0] [0,0,-1] maxPos)
)
2: (
minPos.z = target.min.z; maxPos.z = target.max.z
dimBox = box length:yDim width:xDim height:(zDim - (zDim * csAmt)) transform:(matrix3 [1,0,0] [0,-1,0] [0,0,-1] maxPos)
crsSec = box length:yDim width:xDim height:(zDim * csAmt) transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] minPos)
)
3: (
minPos.x = target.min.x; maxPos.x = target.max.x
dimBox = box length:zDim width:yDim height:(xDim - (xDim * csAmt)) transform:(matrix3 [0,1,0] [0,0,1] [1,0,0] minPos)
crsSec = box length:zDim width:yDim height:(xDim * csAmt) transform:(matrix3 [0,1,0] [0,0,-1] [-1,0,0] maxPos)
)
4: (
minPos.x = target.min.x; maxPos.x = target.max.x
dimBox = box length:zDim width:yDim height:(xDim - (xDim * csAmt)) transform:(matrix3 [0,1,0] [0,0,-1] [-1,0,0] maxPos)
crsSec = box length:zDim width:yDim height:(xDim * csAmt) transform:(matrix3 [0,1,0] [0,0,1] [1,0,0] minPos)
)
5: (
minPos.y = target.min.y; maxPos.y = target.max.y
dimBox = box length:zDim width:xDim height:(yDim - (yDim * csAmt)) transform:(matrix3 [1,0,0] [0,0,-1] [0,-1,0] maxPos)
crsSec = box length:zDim width:xDim height:(yDim * csAmt) transform:(matrix3 [1,0,0] [0,0,1] [0,1,0] minPos)
)
6: (
minPos.y = target.min.y; maxPos.y = target.max.y
dimBox = box length:zDim width:xDim height:(yDim - (yDim * csAmt)) transform:(matrix3 [1,0,0] [0,0,1] [0,1,0] minPos)
crsSec = box length:zDim width:xDim height:(yDim * csAmt) transform:(matrix3 [1,0,0] [0,0,-1] [0,-1,0] maxPos)
)
)
-- display the dimension box in green wire
dimBox.wirecolor = color 0 255 0
dimBox.material = standard()
dimBox.material.diffuse = color 0 255 0
dimBox.material.wire = on
-- create target reference, hide original
refTgt = reference target
refTgt.wirecolor = target.wirecolor
refTgt.name = target.name + "_reference"
-- run a boolean operation using the target reference and the cross section box
boolObj.createBooleanObject refTgt
boolObj.SetOperandB refTgt crsSec 4 2
case cSecSlider.rad_Original.state of
(
1: (target.xray = true; target.isHidden = false)
2: (target.xray = false; target.isHidden = true)
)
case cSecSlider.rad_dimBox.state of
(
1: dimBox.isHidden = false
2: dimBox.isHidden = true
)
)
pickbutton pck_Select "(Select an object)"
label lbl_Direction "Direction:"
radioButtons rad_Direction labels:#("top", "bottom", "left", "right", "front", "back")
slider cSecSlider "Amount"
button btn_Clear "Clear"
label lbl_Original "Original:"
radioButtons rad_Original labels:#("xray","hidden") default:2
label lbl_DimBox "Dimension Box:"
radioButtons rad_DimBox labels:#("wire","hidden")
on pck_Select picked obj do
(
deleteOld()
pck_Select.text = obj.name
target = obj
createCSec()
)
on rad_Direction changed val do
(
if (isValidNode target and target != undefined) do createCSec()
)
on cSecSlider changed val do
(
csAmt = cSecSlider.value / 100
if (isValidNode target and target != undefined) do createCSec()
)
on btn_Clear pressed do
(
deleteOld()
pck_Select.text = "(Select an object)"
if (isValidNode target and target != undefined) do (target.xray = false; target.isHidden = false)
target = undefined
)
on rad_Original changed val do
(
if (isValidNode target and target != undefined) do
(
case rad_Original.state of
(
1: (target.xray = true; target.isHidden = false)
2: (target.xray = false; target.isHidden = true)
) -- end case
) -- end if
) -- end on
on Rad_DimBox changed val do
(
if (isValidNode target and target != undefined) do
(
case rad_dimBox.state of
(
1: dimBox.isHidden = false
2: dimBox.isHidden = true
) -- end case expression
) -- end if
) -- end on
) -- end rollout
createDialog cSecSlider
– OLD
This is one of several scripts I am currently working on for my own productivity. I’m by no means an expert, so any and all advice would be very much appreciated.
-- Cross Section
-- crossSection.ms
-- Version 0.2 (08/29/08)
-- by Kevin Mackey (kmackey2001@hotmail.com)
-- This script creates a cross section of a selected object
-- using a simple boolean.
-- It is still in a very early stage of development.
-- Suggestions are welcome.
-- Right now this script can only be applied to one object at a time
-- due to "target" being a global variable. I plan to fix this soon.
-- create and apply a material for the cross section display box
meditMaterials[1] = Standardmaterial ()
meditMaterials[1].Diffuse = color 0 255 0
meditMaterials[1].wire = on
-- define variables
fn setCSecValues =
(
if (isValidNode target and target != undefined) do
(
minPos = target.min
maxPos = target.max
-- set to work from top for now
-- length: Z (define as zDim?)
-- width: X (define as xDim?)
-- height: Y (define as yDim?)
-- define target dimensions (from above)
tLength = (maxPos.Z - minPos.Z)
tWidth = (maxPos.X - minPos.X)
tHeight = (maxPos.Y - minPos.Y)
-- define cross section object position
cPos = target.center
cPos.y = minPos.y
dPos = target.center
dPos.y = maxPos.y
)
)
-- create cross section
fn createCSec =
(
-- make its own function
if isValidNode cDisp do delete cDisp
if isValidNode cSec do delete cSec
if isValidNode tRef do delete tRef
cDisp = Box length:tLength width:tWidth height:(tHeight - (tHeight * cAmt)) transform:(matrix3 [1,0,0] [0,0,-1] [0,-1,0] dPos)
cDisp.material = meditMaterials[1]
cSec = Box length:tLength width:tWidth height:(tHeight * cAmt) transform:(matrix3 [1,0,0] [0,0,1] [0,1,0] cPos)
-- create target reference, hide original
tRef = reference target
target.isHidden = true -- set to xray for testing
boolObj.createBooleanObject tRef
boolObj.SetOperandB tRef cSec 4 2
)
dialogName = "Cross Section"
rollout crossSlider dialogName
(
pickbutton pbt_select "(Select an object)" --autoDisplay: true
slider cSecSlider "Amount"
button btn_clear "Clear"
-- pickbutton controls
on pbt_select picked obj do
(
pbt_select.text = obj.name
if isValidNode cDisp do delete cDisp
if isValidNode cSec do delete cSec
if isValidNode tRef do delete tRef
--unhide original object and delete reference/display box
if (isValidNode target and target != undefined) do target.isHidden = false
if obj != undefined do target = obj
setCSecValues()
createCSec()
)
-- slider controls
on cSecSlider changed val do
(
cAmt = cSecSlider.value / 100
format "%
" cAmt
setCSecValues()
if (isValidNode target and target != undefined) do createCSec()
)
on btn_clear pressed do
(
pbt_select.text = "(Select an object)"
-- make its own function
if isValidNode cDisp do delete cDisp
if isValidNode cSec do delete cSec
if isValidNode tRef do delete tRef
if (isValidNode target and target != undefined) do target.isHidden = false
target = undefined
)
)
createDialog crossSlider
Hi Malkalypse,
That’s what I got:
Standardmaterial:Standard
(color 0 255 0)
true
setCSecValues()
createCSec()
"Cross Section"
Rollout:crossSlider
true
OK
-- Error occurred in createCSec()
-- Frame:
-- tRef: undefined
-- cSec: undefined
-- dPos: undefined
-- tWidth: undefined
-- cPos: undefined
-- tHeight: undefined
-- cDisp: undefined
-- tLength: undefined
-- cAmt: undefined
-- called in pbt_select.picked()
-- Frame:
-- tRef: undefined
-- cSec: undefined
-- Obj: $Box01
-- cDisp: undefined
-- target: $Box01
>> MAXScript Rollout Handler Exception: -- No ""*"" function for undefined <<
MAX Version?
It’s Max R9, but I just realized I left out anything defining the target. That’s probably the problem there. I’ll fix that shortly…
I have updated the code to make the script more versatile and user friendly.