slice script

Hello

I try to make a script to slice selected polys at equal distances in between two picked points.

Here is the in progress (in not progressing state) script.

Don't work.... If somebody can help. :-)

#universe

pta = pickpoint snap:#3d
ptb = pickpoint snap:#3d rubberBand:pta

try destroyDialog rlslice catch()
global rlslice = rollout rlslice "Slice"
(
button butconnect "GO" pos:[2,2]
spinner spX "X " width:60 range:[2,100,3] type:#integer pos:[55,5]
on butconnect pressed do
(
ptd = ( pta - ptb )
for i=0 to (spX.value) do
(
inc = (ptd/(spX.value+2))
ppp = (inc * i) + pta

Point pos: ppp
$.EditablePoly.slice [1,0,0] ppp flaggedFacesOnly:on
)
)
)
createDialog rlslice 160 50

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Haider of Sweden's picture

.

Ah, now it makes totall sense. Thanks Miauu :)

Question: What do you need to change in the code so that it affects the current slice modifier instead of adding a new one?

Kind regards
Haider
www.haider.se

miauu's picture

.

(
	-- Add slice modifier from two points
	-- p1 is point 1
	-- p2 is point 2
	fn AddSliceFrom2Pts myobj p1 p2 affectCurrentMod: =
	(
		local mySlide = undefined
		if affectCurrentMod == true then
		(
			if myobj.modifiers.count != 0 and classOf myobj.modifiers[1] == SliceModifier do
				mySlide = myobj.modifiers[1]
		)
		else
		(
			mySlide = sliceModifier()
			AddModifier myobj mySlide
		)
 
		vn = [0,0,1] -- vertical vector (normal)
		objTM = myobj.objecttransform
		Vec1 = normalize ( p2 - p1)
		V3= normalize ( cross Vn Vec1) -- get Vy
		--create Matrix. Swap X by Z to get vertical plane. p1 is the position of gizmo
		newModTM = matrix3 Vn Vec1 V3 p1
		mytransform = (inverse objTM ) * newModTM
		mySlide.slice_plane.transform = mytransform
	)
	if selection.count == 1 do
	(
		myobj = selection[1]
		p1 = pickPoint snap:#3D 
		if classOf p1 == point3 do
		(
			p2 = pickPoint snap:#3D 
			if classOf p2 == point3 do
			(
				p1 *= inverse myobj.transform
				p2 *= inverse myobj.transform
				AddSliceFrom2Pts myobj p1 p2 affectCurrentMod:true
			)
		)
	)
)
Haider of Sweden's picture

.

Wonderful!
Works perfect :)

I saved both of them and will at some point look how it works to create a scripted plugin so that I use the first one (that adds a new modifier) as an option to the regular Slice.

Kind regards
Haider
www.haider.se

Haider of Sweden's picture

.

How is this last script supposed to work?
Made a quick try, but achieved nothing.

Kind regards
Haider
www.haider.se

miauu's picture

.

(
	-- Add slice modifier from two points
	-- p1 is point 1
	-- p2 is point 2
	fn AddSliceFrom2Pts myobj p1 p2 =
	(
		mySlide = sliceModifier()
		AddModifier myobj mySlide
 
		vn = [0,0,1] -- vertical vector (normal)
		objTM = myobj.objecttransform
		Vec1 = normalize ( p2 - p1)
		V3= normalize ( cross Vn Vec1) -- get Vy
		--create Matrix. Swap X by Z to get vertical plane. p1 is the position of gizmo
		newModTM = matrix3 Vn Vec1 V3 p1
		mytransform = (inverse objTM ) * newModTM
		mySlide.slice_plane.transform = mytransform
	)
	if selection.count == 1 do
	(
		myobj = selection[1]
		p1 = pickPoint snap:#3D 
		if classOf p1 == point3 do
		(
			p2 = pickPoint snap:#3D 
			if classOf p2 == point3 do
			(
				p1 *= inverse myobj.transform
				p2 *= inverse myobj.transform
				AddSliceFrom2Pts myobj p1 p2
			)
		)
	)
)
mmorais's picture

Add slice modifier from two points

-- Add slice modifier from two points
-- p1 is point 1
-- p2 is point 2
fn AddSliceFrom2Pts myobj p1 p2 =
(
mySlide = sliceModifier()
AddModifier myobj mySlide

vn = [0,0,1] -- vertical vector (normal)
objTM = myobj.objecttransform
Vec1 = normalize ( p2 - p1)
V3= normalize ( cross Vn Vec1) -- get Vy
--create Matrix. Swap X by Z to get vertical plane. p1 is the position of gizmo
newModTM = matrix3 Vn Vec1 V3 p1
mytransform = (inverse objTM ) * newModTM
mySlide.slice_plane.transform = mytransform
)

Anubis's picture

Hi Titane, is this that you

Hi Titane,
is this that you looking for?
in coordsys local $.EditablePoly.slice [na,nb,nc] ppp flaggedFacesOnly:on

my recent MAXScripts RSS (archive here)

titane357's picture

hello anubis, nice to see

hello anubis, nice to see you.
I test with "local" but don't work....
I have another version where I substract object position, it was ok but slices planes wasn't rotated within the object...

(
local savesnap=snapMode.active
snapMode.active=true

in coordsys local pta = pickpoint snap:#3d
in coordsys local ptb = pickpoint snap:#3d rubberBand:pta
ptd = ( ptb - pta )
nptd = normalize ptd
na = nptd[1]
nb = nptd[2]
nc = nptd[3]
try destroyDialog rlslice catch()
global rlslice = rollout rlslice "Slice"
(
button butconnect "GO" pos:[2,2]
spinner spX "X " width:60 range:[2,100,3] type:#integer pos:[55,5]
on butconnect pressed do
(
for i=1 to (spX.value-1) do
(
inc = (ptd/(spX.value))
ppp = (inc * i) + pta
in coordsys local Point pos: ppp
in coordsys local $.EditablePoly.slice [na,nb,nc] ppp flaggedFacesOnly:on
)
)
)
createDialog rlslice 160 50
snapMode.active=savesnap
)

titane357's picture

hello again, Here is my

hello again,

Here is my script, but I don't know how to convert in local syst (because slice is in local sys )
anybody help ?

pta = pickpoint snap:#3d
ptb = pickpoint snap:#3d rubberBand:pta
ptd = ( ptb - pta )
nptd = normalize ptd
na = nptd[1]
nb = nptd[2]
nc = nptd[3]
try destroyDialog rlslice catch()
global rlslice = rollout rlslice "Slice"
(
button butconnect "GO" pos:[2,2]
spinner spX "X " width:60 range:[2,100,3] type:#integer pos:[55,5]
on butconnect pressed do
(
for i=1 to (spX.value-1) do
(
inc = (ptd/(spX.value))
ppp = (inc * i) + pta
--Point pos: ppp
$.EditablePoly.slice [na,nb,nc] ppp flaggedFacesOnly:on
)
)
)
createDialog rlslice 160 50

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.