Notifications
Clear all
[Closed] Spline boolean ops
Jan 23, 2018 7:33 am
I can go splineOps.startUnion, but how do I actually perform these union operations in script?
3 Replies
Jan 23, 2018 7:33 am
There’s no easy way afaik.
(
fn get2DPoint pos yTop:true = (
local sX = gw.getWinSizeX() as float
local sY = gw.getWinSizeY() as float
local rPA = renderPixelAspect
local rX = RenderWidth as float
local rY = RenderHeight as float
rY = rY * ( 1 / rPA )
local rratio = ( sX / rX ) / (sY / rY)
if rratio >= 1. then (
local ratio = sY / rY
) else (
local ratio = sX / rX
)
local xMin = ( sX - ( rX * ratio ) ) / 2
local yMin = ( sY - ( rY * ratio ) ) / 2
gw.setTransform (matrix3 1)
local p = gw.TransPoint ( pos )
local x = ( p.x - xMin ) / ( sX - ( xMin * 2) )
local y = ( p.y - yMin ) / ( sY - ( yMin * 2 ) )
if not yTop then y = 1 - y
[x,y]
)
fn makeparam w l = (
bit.or (bit.and w 0xFFFF) (bit.shift l 16)
)
hwnd = windows.getParentHWND (windows.getChildHWND #max "Ribbon")[1]
activeViewportHWND = (dotNetClass "Autodesk.Max.GlobalInterface").Instance.COREInterface7.ActiveViewExp.HWnd
delete objects
shp = circle()
convertToSplineShape shp
shp2 = copy shp pos:(shp.pos + [(shp.max.x-shp.min.x)/2.0,0,0])
addAndWeld shp shp2 -1
select shp
max modify mode
subobjectlevel = 3
setSplineSelection shp #(1)
p2 = getKnotPoint shp 2 1
splineOps.startUnion shp
p2xy = get2DPoint p2
p2xy = [ int (p2xy[1] * gw.getWinSizeX()), int (p2xy[2] * gw.getWinSizeY()) ]
-- mouseParam = makeparam mouse.pos.x mouse.pos.y
mouseParam = makeparam p2XY[1] p2XY[2]
windows.sendMessage hwnd 0x21 0x302DE 0x2070001
windows.postMessage activeViewportHWND 0x0200 0x1 mouseParam -- WM_MouseMove
windows.postMessage activeViewportHWND 0x0020 activeViewportHWND 0x2000001 -- WM_SetCursor
windows.postMessage activeViewportHWND 0x201 0x1 mouseParam
windows.postMessage activeViewportHWND 0x202 0 mouseParam
)
Jan 23, 2018 7:33 am
this one works too, but never on the first run.
at first function call it always fails for some unknown reason system exception
but second time it does boolean as expected
fn splineIntersect shp index1 index2 = if index1 > 0 and index2 > 0 and isKindOf shp SplineShape do (
local ns = numSplines shp
if index1 <= ns or index2 <= ns and ns > 1 then (
if isClosed shp index1 and isClosed shp index2 then (
local g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
local inode = g.COREInterface.GetINodeByHandle shp.inode.handle asdotnetobject:true
local iobj = (inode.EvalWorldState g.COREInterface.Time true asdotnetobject:true).Obj
if getCommandPanelTaskMode() != #modify do max modify mode
if subObjectLevel != 3 do subObjectLevel = 3
setSplineSelection shp #(index1)
iobj.BoolOperation = 2
splineOps.startIntersect shp
iobj.doBoolean (index2-1)
updateShape shp
if theHold.Holding() do theHold.Accept "Boolean Intersect"
true
) else false
) else false
)
splineIntersect $ 1 2