sort points

sort points

dg3duy
Collaborator Collaborator
620 Views
2 Replies
Message 1 of 3

sort points

dg3duy
Collaborator
Collaborator

I have a script that adds constraint orientation between bones and nulls, but it happens that this time I don't plan to use it between bones and nulls, the bones I am going to substitute them by points, what is the way to make it work correctly if all the objects of the scene are points objects, I am not going to use bones. script cont.gif

(
	points = #()
	bones  = #()
	
	for j in selection do
	(
		if iskindof j point then append points j.name else append bones j.name
	)
	
	sort points
	sort bones
	
	for j = 1 to points.count do
	(
		controller = orientation_constraint()
		
		pt = getnodebyname bones[j]
		pt.rotation.controller = controller
		
		if j < 1 and j < points.count do
		(
			bn = getnodebyname points[j-1]
			controller.appendTarget bn 50.0
		)
		
		bn = getnodebyname points[j]
		controller.appendTarget bn 50.0
	)
)

 

0 Likes
Accepted solutions (1)
621 Views
2 Replies
Replies (2)
Message 2 of 3

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

it sounds like you need extra prefix or suffix name for your point objects:

 

 

delete objects


sources = for k=1 to 5 collect (point name:(uniquename #source) cross:on axistripod:on box:off wirecolor:orange pos:[0,0, (1-k)*30]) 
targets = for k=1 to 8 collect (point name:(uniquename #target) cross:off axistripod:off box:on wirecolor:green pos:[40,0, (1-k)*40])

/* find nodes: #1:

sources = $helpers/source* as array
targets = $helpers/target* as array

*/

/* find nodes: #2:

sources = for node in helpers where iskindof node Point and matchpattern node.name pattern:"source*" collect node
targets = for node in helpers where iskindof node Point and matchpattern node.name pattern:"target*" collect node

*/

fn sortbyname n1 n2 = stricmp n1.name n2.name

qsort sources sortbyname
qsort targets sortbyname

count = amin sources.count targets.count
for k=1 to count do
(
	c = sources[k].rotation.controller = lookat_constraint()
	c.appendTarget targets[k] 100
	c
)

 

 

Message 3 of 3

dg3duy
Collaborator
Collaborator

Exactly needs an extra prefix or suffix name 🤗

0 Likes