How do you keep a multiple object selection, selected?

Technical questions, etc..
Post Reply
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

How do you keep a multiple object selection, selected?

Post by trueBlue »

How do you keep a multiple object selection, selected?
After this code below runs, it unselects all but one object.
So you can not continue to run the script on the previous multiple object selection.
I will have a Watch Dog hooked up to the script.

Code: Select all

function Execute(params)
{
	var Shear_X = params.ConValue('Shear_X');
	var Shear_Y = params.ConValue('Shear_Y');
	var Shear_Z = params.ConValue('Shear_Z');

	sel = Node.Selection();
	for (i = 0; i < Node.SelectionLength(sel); i++)
		{Node.Select(Node.SelectionGetAt(sel, i)); ApplyShear(Node.SelectionGetAt(sel, i))};
}

function ApplyShear(sel)
{
	var Shear_X  = Node.NearValue('', 'Shear_X')
	var Shear_Y  = Node.NearValue('', 'Shear_Y')
	var Shear_Z  = Node.NearValue('', 'Shear_Z')
	if(Node.IsLight(sel)) { return; }
	if(Node.IsCamera(sel)) { return; }
	if(!sel) { return; }
	if(!Node.ConExists(sel,"WldMatrix")) { return;	}
	Space.NodeMatrixElement(sel,'shx') = Shear_X;
	Space.NodeMatrixElement(sel,'shy') = Shear_Y;
	Space.NodeMatrixElement(sel,'shz') = Shear_Z;
}
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: How do you keep a multiple object selection, selected?

Post by clintonman »

From Docs for Node.Select, "The object will be the only one selected after this operation"

You can try Node.NearValue(sel, 'Shear_X') and get rid of the Node.Select
That way it's not dependent on the selected item to "automatically fill in" the empty quotes.
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: How do you keep a multiple object selection, selected?

Post by trueBlue »

Thank YOU!
Simply taking out the Node.Select() did the trick.
Not sure what you meant by using the Node.NearValue('', 'value')
As I understood it's use is, it is the short version of
Node.Value(System.ThisOwner(), 'value')

if you do not declare the attribute in the ApplyShear function, it will generate an undefined error.

Code: Select all

function Execute(params)
{
	sel = Node.Selection();
	for (i = 0; i < Node.SelectionLength(sel); i++)	
	{Node.SelectionGetAt(sel, i); ApplyShear(Node.SelectionGetAt(sel, i))};
}

function ApplyShear(sel)
{
	var Shear_X  = Node.NearValue('', 'Shear_X')
	var Shear_Y  = Node.NearValue('', 'Shear_Y')
	var Shear_Z  = Node.NearValue('', 'Shear_Z')
	if(Node.IsLight(sel)) { return; }
	if(Node.IsCamera(sel)) { return; }
	if(!sel) { return; }
	if(!Node.ConExists(sel,"WldMatrix")) { return;	}
	Space.NodeMatrixElement(sel,'shx') = Shear_X;
	Space.NodeMatrixElement(sel,'shy') = Shear_Y;
	Space.NodeMatrixElement(sel,'shz') = Shear_Z;
}
Any ideas how to do Shear X, Y, & Z with one Shear_XYZ attribute?
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: How do you keep a multiple object selection, selected?

Post by clintonman »

trueBlue wrote: 14 Feb 2020, 14:39 Thank YOU!
Simply taking out the Node.Select() did the trick.
Not sure what you meant by using the Node.NearValue('', 'value')
As I understood it's use is, it is the short version of
Node.Value(System.ThisOwner(), 'value')

if you do not declare the attribute in the ApplyShear function, it will generate an undefined error.

Code: Select all

function Execute(params)
{
	sel = Node.Selection();
	for (i = 0; i < Node.SelectionLength(sel); i++)	
	{Node.SelectionGetAt(sel, i); ApplyShear(Node.SelectionGetAt(sel, i))};
}

function ApplyShear(sel)
{
	var Shear_X  = Node.NearValue('', 'Shear_X')
	var Shear_Y  = Node.NearValue('', 'Shear_Y')
	var Shear_Z  = Node.NearValue('', 'Shear_Z')
	if(Node.IsLight(sel)) { return; }
	if(Node.IsCamera(sel)) { return; }
	if(!sel) { return; }
	if(!Node.ConExists(sel,"WldMatrix")) { return;	}
	Space.NodeMatrixElement(sel,'shx') = Shear_X;
	Space.NodeMatrixElement(sel,'shy') = Shear_Y;
	Space.NodeMatrixElement(sel,'shz') = Shear_Z;
}
Any ideas how to do Shear X, Y, & Z with one Shear_XYZ attribute?
Nope, and I see what you mean "Node.Value(System.ThisOwner(), 'value')" - last 2 sample lines of docs,
"get value of the 'ObjMatrix' connector from caller (this) object. Useful e.g. for panel button actions
val = Node.NearValue('', 'ObjMatrix')"
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: How do you keep a multiple object selection, selected?

Post by trueBlue »

So I saved this project in Widgets.
Discovered that the Watch Dog Event was not working when you load it. Ugh! :x
I created a script and hooked it up to the Watch Dog Event. :mrgreen:
WatchDog.PNG
WatchDog.PNG (10.7 KiB) Viewed 2274 times

Code: Select all

function Execute(params)
{
}
function OnPostLoad(params)
{
System.SendCommandLine('Activity.Run("/Widgets/Tools/Shear/Start")');
}
Now it works! :D
Post Reply