ScriptSpot

Forum topic · General Scripting

How do i create a line with pre specified number of verts and then do something?

By mjbg · 2011-10-05

Description

so i belive what i am trying to do is very siple.
lets say i want to create a line with 3 points and after i click the right mouse button to stop the creation it will messagebox = "aaa"

but.. if i try to do something like this:


StartObjectCreation Line
messagebox "aaa"

the "aaa" will show on the first click not after i right click

if i try some mouse tool it will kind of abort the mousetool

i tryed lots of callbacks without any luck

so.. theres any way to do it?

Comments (4)

oops...

Anubis · 2011-10-05

Sorry, my bad, I write this by memory, here is correct one:

tool makeLine numPoints:5 -- limit clicks to 4
(
	local sp = splineShape()
	fn fn_addKnot = (addKnot sp 1 #corner #line worldPoint)
	
	on mousePoint clickNo do (
		case clickNo of (
			1: (addnewSpline sp; fn_addKnot())
			default: (fn_addKnot(); updateShape sp)
		)
	)
)
startTool makeLine prompt:"Click 4 times to create line"

Also dunno why if numPoints is 4 it end of 3 clicks,
but if click and drag i end with 4 knots.
So i set numPoints to 5 to can click w/o dragging.

Anubis · 2011-10-05

maybe mouse tool is not so bad too

tool makeLine numPoints:4 -- limit clicks to 4
(
	local sp = splineShape()
	addnewSpline sp
	
	on mousePoint clickNo do (
		if clickNo <= 4 do
			addKnot sp 1 #corner #line worldPoint
		if clickNo == 4 do updateShape sp
	)
)
startTool makeLine prompt:"Click 4 times to create line"

mjbg · 2011-10-05

Thank you Anubis
but for some reason i cannot run your code
it says:


-- Error occurred in anonymous codeblock; filename: C:\_Neo3d\_ Scripts Neo3d\Scripts temp\; position: 92; line: 4
-- Syntax error: at name, expected tool clause: 
--  In line: 	addnewSpline s

mjbg · 2011-10-05

i found some way using RegisterRedrawViewsCallback
just in case


fn teste = 
(
	try
	(
	aa = numknots $
	if aa == 4 do 
		(
		messagebox "aaa"
		stopCreating()
		unRegisterRedrawViewsCallback teste
		)
	)
	catch()
)
clearSelection()
RegisterRedrawViewsCallback teste
StartObjectCreation Line