MousePoint Help

Hello , Im new to maxscript and iv'e been doing some practice scripting basics to better understand it.

Ok, here it is.I'm trying to add a mousepoint handler to my script. The problem I'm having, is that im not sure where the placement for the event to go in and how to structure it. Any suggestion or guidance would be appreciated, Thanks.

global myFloater
(			
		try
		closeRolloutFloater myFloater
		catch()
 
		myfloater = newRolloutFloater "My Rock" 200 300 
		rollout myRollout "Rock Pro"
 
	(
		global myBox
 
			group "Rocksize"
			(
				spinner spnLen "Length: " range:[1.0, 10.0, 1.0] type:#worldunits 
				spinner spnWid "Width: " range:[1.0, 10.0, 1.0] type:#worldunits 
				spinner spnHei "Height: " range:[1.0, 10.0, 1.0] type:#worldunits 
			)
 
 
			button createRock "MakeRock"
 
				on createRock pressed do
 
					(
						sL = spnLen.value
						sW = spnWid.value
						sH = spnHei.value
 
						myBox = box length:sL width:sW height:sH pos:worldPoint lengthsegs:5 widthsegs:5 heightsegs:5
						myBox.name = uniqueName "Rock_"
						select myBox
						for i in selection do i.pivot = i.center
						addModifier myBox (spherify())
						addModifier myBox (turbosmooth())
						myBox.spherify.percent = 100
 
					)
 
 
				tool create 
			(
 
				local myBox
 
				on mousePoint clickno do
 
				if clickno == 1 then myBox = myBox pos:worldPoint else #stop
 
				on mouseMove clickno do myBox.pos = worldPoint
 
			)
 
		)
)
       addrollout myRollout myfloater
 

Comments

Comment viewing options

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

Thanks Anubis for your help.

Thanks Anubis for your help. I appreciate you giving me the two options for the script to work. And pickpoint v1 would work for me for my pos and adding an undefined for in case the user aborts. Thanks again this was really helpful.
cheers.

Anubis's picture

Just take this as quick

Just take this as quick reply... if you need a mouse tool only for the start pos point you can use pickPoint(). The mouse tool named "create" likely is preserved for plugins, so I rename it to "createRock", and add the tool as local to the rollout (but it can be outside of the rollout as well).

(
	global myFloater
	try(closeRolloutFloater myFloater)catch()
 
	rollout myRollout "Rock Pro"
	(
		local thePos
 
		tool createRock
		(
			on mousePoint click do
			(
				thePos = worldPoint
				#stop
			)
		)
 
		group "Rock Size"
		(
			spinner spnLen "Length: " range:[1.0, 10.0, 1.0] type:#worldunits 
			spinner spnWid "Width: " range:[1.0, 10.0, 1.0] type:#worldunits 
			spinner spnHei "Height: " range:[1.0, 10.0, 1.0] type:#worldunits 
		)
		button btn_createRock1 "MakeRock v.1"
		button btn_createRock2 "MakeRock v.2"
 
		on btn_createRock1 pressed do -- // Version 1
		(
			sL = spnLen.value
			sW = spnWid.value
			sH = spnHei.value
 
			thePos = pickPoint() -------------------------------
			-- supply default value in case the user abort mouse tool:
			if classOf thePos != Point3 do thePos = [0,0,0]
 
			myBox = Box length:sL width:sW height:sH \
			pos:thePos lengthsegs:5 widthsegs:5 heightsegs:5 \
			name:(uniqueName "Rock_") isSelected:true
 
			CenterPivot myBox
			addModifier myBox (spherify())
			addModifier myBox (turbosmooth())
			myBox.spherify.percent = 100
		)
 
		on btn_createRock2 pressed do -- // Version 2
		(
			sL = spnLen.value
			sW = spnWid.value
			sH = spnHei.value
 
			startTool createRock -------------------------------
			if classOf thePos != Point3 do thePos = [0,0,0]
 
			myBox = Box length:sL width:sW height:sH \
			pos:thePos lengthsegs:5 widthsegs:5 heightsegs:5 \
			name:(uniqueName "Rock_") isSelected:true
 
			CenterPivot myBox
			addModifier myBox (spherify())
			addModifier myBox (turbosmooth())
			myBox.spherify.percent = 100
		)
	)
	myFloater = newRolloutFloater "My Rock" 200 300
	addRollout myRollout myFloater
)

my recent MAXScripts RSS (archive here)

Comment viewing options

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