Notifications
Clear all

[Closed] How to remove position_script()?

All objects are rotated at arbitrary angle.
With when cosntruct the objects are moved correctly – they follow the selected object using its local X axis.
With position_xyz/float_Script() the objects are moved in the world space(Xaxis).
As you can see when I select the object, that I want to move the objects in the center are aligned on the world X axis.
Whan I need the objects to be movd with position_xyz/float_Script() but to use the selected object local X axis(as with the when cosntruct).

it’s clear now. let me think how it can be scripted…

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

 delete objects
 p1 = point name:"p1" pos:[-20,0,0]
 p2 = point name:"p2" pos:[20,0,0]
 p0 = dummy name:"p0" pos:[0,0,0]
 
 -- XY constraint, Z freet:
 p = p0.pos.controller = position_list()
 s = p.available.controller = position_script()
 p.active = 1
 lockedtracksman.setlocks on #(p[1][1],p[1][2]) #(p[1],p[1]) #(1,2) off
 
 s.addobject "p0" p0.rotation.controller
 s.addobject "p1" (NodeTransformMonitor node:p1)
 s.addobject "p2" (NodeTransformMonitor node:p2)
 s.setexpression "(p1.pos + p2.pos)*[0.5,0.5,0]*p0.value"
 

Thank you for this solution. I learned a lot from you in this thread.
My script still not work as I want.

The script:

(
 	global rol_test
 	try(destroyDialog rol_test)catch()
 	rollout rol_test ""
 	(		
 		local pXplus = undefined
 		local pXminus = undefined
 		local pYplus = undefined
 		local pYminus = undefined
 		local pZplus = undefined
 		local pZminus = undefined
 		
 		button btn_start "Start"
 		
 		function AddPositionScript p0 p1 p2 =
 		(	
 			-- XY constraint, Z freet:
 			p = p0.pos.controller = position_list()
 			s = p.available.controller = position_script()
 			p.active = 1
 			lockedtracksman.setlocks on #(p[1][1],p[1][2]) #(p[1],p[1]) #(1,2) off
 			
 			s.addobject "p0" p0.rotation.controller
 			s.addobject "p1" (NodeTransformMonitor node:p1)
 			s.addobject "p2" (NodeTransformMonitor node:p2)
 			s.setexpression "(p1.pos + p2.pos)*[0.5,0.5,0]*p0.value"			
 		)
 		
 		function ObjPosChanged =
 		(
 			deleteAllChangeHandlers id:#ObjPosChangedID
 			if selection.count == 1 do
 			(
 				case selection[1] of
 				(
 					(pXplus): 
 					(
 						for m in #(pYplus,pYminus,pZplus,pZminus) do
 							AddPositionScript m pXplus pXminus
 					)
 				)
 			)			
 		)
 		
 		on btn_start pressed do
 		(
 			if selection.count == 1 then
 			(
 				--	get the selected object
 				local curObj = selection[1]
 				local objLocalBBox = nodeLocalBoundingBox curObj 
 				local tm = curObj.objectTransform
 				local bmin = objLocalBBox[1]*(inverse tm) 
 				local bmax = objLocalBBox[2]*(inverse tm)
 				local center = ((bmin + bmax)/2)				
 				
 				pXplus = point name:"pXplus"
 				pXminus = point name:"pXminus"
 				pYplus = point name:"pYplus"
 				pYminus = point name:"pYminus"
 				pZplus = point name:"pZplus"
 				pZminus = point name:"pZminus"
 				
 				mArr = #(pXplus,pXminus,pYplus,pYminus,pZplus,pZminus)
 				for m in mArr do
 				(
 					m.transform = curObj.transform
 					m.scale = [1,1,1]
 				)
 				pXplus.pos = ([bmax.x,center.y,center.z]*(tm))
 				pXminus.pos = ([bmin.x,center.y,center.z]*(tm))
 				pYplus.pos = ([center.x,bmax.y,center.z]*(tm))
 				pYminus.pos = ([center.x,bmin.y,center.z]*(tm))
 				pZplus.pos = ([center.x,center.y,bmax.z]*(tm))
 				pZminus.pos = ([center.x,center.y,bmin.z]*(tm))				
 				
 				setTransformLockFlags  pXplus #{2..9}
 				setTransformLockFlags  pXminus #{2..9}
 				setTransformLockFlags  pYplus #{1,3..9}
 				setTransformLockFlags  pYminus #{1,3..9}
 				setTransformLockFlags  pZplus #{1,2,4..9}
 				setTransformLockFlags  pZminus #{1,2,4..9}
 				--
 				deleteAllChangeHandlers id:#ObjPosChangedID
 				callbacks.removescripts id:#ObjPosChangedID			
 				callbacks.addscript #selectionSetChanged "rol_test.ObjPosChanged()" id:#ObjPosChangedID					
 			)	
 		)
 		
 		on rol_test close do
 		(
 			deleteAllChangeHandlers id:#ObjPosChangedID
 			callbacks.removescripts id:#ObjPosChangedID
 			delete helpers
 		)
 	)
 	createdialog rol_test 
 )

the thing that you have shown last time is a position constraint by 50/50


 delete objects
 p1 = point name:"p1" pos:[-20,0,0]
 p2 = point name:"p2" pos:[20,0,0]
 p0 = dummy name:"p0" pos:[0,0,10]
 
about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)

 p = p0.position.controller = position_constraint relative:on
 p.appendTarget p1 50
 p.appendTarget p2 50
 

Thank you, Denis.
This makes the code shorter and works as I want.

I have some more questions

    • can I use position constraint achive the result from the code below?
      (the two points follow only the X or Y)
(
 	delete objects
 	p1 = point name:"p1" pos:[-20,0,0]
 	p2 = point name:"p2" pos:[20,20,0]
 	p0 = dummy name:"p0" pos:[20,0,0]
 	
 -- 	about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)
 	
 	--	can this be achieved with position_constraint
 	p1.parent = p2.parent = p0
 	setInheritanceFlags p1 #{2} keepPos:true
 	setInheritanceFlags p2 #{1} keepPos:true
 )
  1. setInheritanceFlags works only with world coordinates or I miss something? If you uncoment the
about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)

the p1 and p2 will follow the world X and Y coordinates of p0.

  1. here is how to do it:

set redraw off

delete objects
p1 = point name:"p1" pos:[-20,0,0]
p2 = point name:"p2" pos:[20,0,0]
p0 = dummy name:"p0" pos:[0,0,10]

about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)

a = p0.pos.controller
p = p0.pos.controller = createinstance position_list
c = p.available.controller = position_constraint()
f = p.available.controller = a
p.active = 2

lockedtracksman.setlocks on #(f[1],f[2]) #(f,f) #(1,2) off

c.appendTarget p1 50
c.appendTarget p2 50

set redraw on

  1. do you mean TransformLockFlags? for InheritanceFlags the coordinate system doesn’t make sense.

BTW… what you are making looks like a manipulator for me. why is it not a manipulator?

I meaned TransformLockFlags.
It is a kind of manipulator. I started with scriptedManipulators, but with no success.

I saw somethihg here http://forums.cgsociety.org/showthread.php?f=98&t=819257&highlight=simpleManipulator

TransformLockFlags lock only possibility to change transformation in world space using Transform Gizmo. They don’t really lock controllers. You still be able to change the transform any other way than using gizmo.

Page 2 / 2