Scripted plugin - creating a shape plugin with a spline linked to two nodes

Hi there,

I am in the process of writing a scripted plugin which can do the following;

create a splineshape between two different nodes. When creating the plugin object, I need to initialize a node picking tool, which I cannot seem to get done. Second, when the spline is generated, it needs to be updated when the linked nodes are moved. I suppose this is done using shape instances? I just cannot find any reference to start from.

There is so little information about this in the help files, I figured I would post it in here.

I currently have this as a base for my plugin;

plugin shape Path_segment
name:"Path Segment"
classID:#(0x48238272, 0x48206285)
extends:line replaceUI:true version:1
category:"Carmatools"
(
	local last_n1pos,last_n2pos,thesegment
 
	parameters main rollout:params 
	(
		node1_param type:#node ui:node1 
		node2_param type:#node ui:node2
	)
 
	rollout params "Params"
	(
		label node1_label "Node1:" across:2 offset:[0,3] align:#right 
		pickbutton node1 autodisplay:true
		label node2_label "Node2:" across:2 offset:[0,3] align:#right 
		pickbutton node2 autodisplay:true
		on node1 picked obj do
		(
			node1_param = obj
			node1.text = obj.name
			last_n1pos = obj.pos
		)
		on node2 picked obj do
		(
			node2_param = obj
			node2.text = obj.name
			last_n2pos = obj.pos
		)
	)
 
	tool create
	(
		thesegment = splineshape pos:node1_param.pos
		addKnot thesegment 1 #corner #line node1_param.pos 
		addKnot thesegment 1 #corner #line node2_param.pos
		updateShape thesegment
		thesegment
 
	)
)

obviously the tool section is a dummy and needs the proper code for my goals.

Has anybody done anything similar or can anybody help me out? Perhaps some of you have seen a similar script before and can point me in that direction?

Comments

Comment viewing options

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

why you need to make this as

why you need to make this as plugin? that's mission impossible. you can made it as mouse tool or macro script.

my recent MAXScripts RSS (archive here)

Harmalarm's picture

I have been able to invoke

I have been able to invoke the node picking tool, and can generate a spline between two nodes. The spline vertices however are not properly linked with the nodes, so the splineshape doesn't update when I move the nodes. Somehow I feel I should work with link contraints rather then updating the splineshape... This is what I currently have. Help still appreciated! :)

plugin shape Path_segment
name:"Path Segment"
classID:#(0x48238272, 0x48206285)
extends:line replaceUI:true version:1
category:"Carmatools"
(
	local last_n1pos, last_n2pos,thesegment
 
	fn createsegment pointA pointB =
	(
		ss = SplineShape pos:pointA
		addNewSpline ss
		addKnot ss 1 #corner #line PointA
		addKnot ss 1 #corner #line PointB
		updateShape ss
		ss
	)
 
	parameters main rollout:params 
	(
		node1_param type:#node ui:node1 
		node2_param type:#node ui:node2
	)
 
	rollout params "Params"
	(
		label node1_label "Node1:" across:2 offset:[0,3] align:#right 
		pickbutton node1 autodisplay:true
		label node2_label "Node2:" across:2 offset:[0,3] align:#right 
		pickbutton node2 autodisplay:true
		on params load do
		(
			if node1_param != undefined do
			(
				node1.text = node1_param.name
			)
		)
		on node1 picked obj do
		(
			node1_param = obj
			node1.text = obj.name
			last_n1pos = obj.pos
		)
		on node2 picked obj do
		(
			node2_param = obj
			node2.text = obj.name
			last_n2pos = obj.pos
		)
	)
 
	tool create
	(
		on start do
		(
			fn shapeFilt o = classof o == Path_node
 
			local thesegment, obj1pos, obj2pos
 
			obj1 = pickobject filter:shapeFilt
 
			if isValidNode obj1 do
			(
				obj2 = pickObject rubberBand:obj1.pos rubberBandColor:yellow
				if obj2 != undefined and obj2 != obj1 do
				(
					ss = SplineShape pos:obj1.pos
					addNewSpline ss
					addKnot ss 1 #corner #line obj1.pos
					addKnot ss 1 #corner #line obj2.pos
					updateShape ss
					thesegment = instance ss
					delete ss
					thesegment
				)
				gw.updateScreen()
			)
		)
	)
)

Comment viewing options

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