Notifications
Clear all

[Closed] Selecting multiple objects with try() and *

I’m trying to select multiple objects with try() and catch():

‘Bip Acolyte1A Spine1’,
‘Bip Acolyte1A Spine2’,
‘Bip Acolyte1A Spine’

it works perfectly with:

SpineSel = "Bip * Spine*"
theObjectSp = Execute ("$'"+SpineSel+"'")

select theObjectSp

but it gets me Undefined when I’m trying this code:

try(select #(
				$'Bip * Spine*'
)) catch()

I would appreciate for any suggestions.

14 Replies

You are putting a PathName inside an array and so it throws an error:

try(select #($'Bip*Spine*'))catch(getCurrentException())
    "-- Runtime error: operation requires a collection of nodes, got: $$objects/.../Bip*Spine*"
    

Try removing the array:

try(select $Bip*Spine*)catch(getCurrentException())

Thank for your answer, PolyTools.
The reason why I’d like to select object with try() it’s because I like to see/control the list of objects like below:

try(select #(
	$'Bip Acolyte1A Pelvis',
	$'Bip Acolyte1A Spine',
	$'Bip Acolyte1A Spine1',
	$'Bip Acolyte1A Spine2',
	$'Bip Acolyte1A Neck',
	$'Bip Acolyte1A Head',
	
	$'Bip Acolyte1A L UpperArm',
	$'Bip Acolyte1A L Forearm',
	$'Bip Acolyte1A L Hand',
	$'Bip Acolyte1A R UpperArm',
	$'Bip Acolyte1A R Forearm',
	$'Bip Acolyte1A R Hand',

	$'Bip Acolyte1A L Foot', --Legs
	$'Bip Acolyte1A L Toe0',
	$'Bip Acolyte1A L Calf',
	$'Bip Acolyte1A R Foot',
	$'Bip Acolyte1A R Toe0',
	$'Bip Acolyte1A R Calf',

	$BoB_Acolyte1A_Falda_06, --Skirt Front
	$BoB_Acolyte1A_Falda_01,
	$BoB_Acolyte1A_Falda_04,
	$BoB_Acolyte1A_Falda_13,
	$BoB_Acolyte1A_Falda_11,
	$BoB_Acolyte1A_Falda_14,
	$BoB_Acolyte1A_Falda_07,
	
	$BoB_Acolyte1A_Falda_03, --Skirt Back
	$BoB_Acolyte1A_Falda_16,
	$BoB_Acolyte1A_Falda_09,
	
	$BoB_Acolyte1A_Falda_02, --Skirt Left side
	$BoB_Acolyte1A_Falda_15,
	$BoB_Acolyte1A_Falda_08,
	
	$BoB_Acolyte1A_Falda_05, --Skirt Right side
	$BoB_Acolyte1A_Falda_12,
	$BoB_Acolyte1A_Falda_10,
)) catch()

But if I use your code I want be able to do that:

try(select $'Bip*Spine*', $'Bip*Pelvis*')
catch(getCurrentException())

this gives me an error:

-- Error occurred in anonymous codeblock; filename: C:\Users\AntonSh\Dropbox\Public\00-archive\03-distr\01-3d-tools\3dsmax\_scripts\01-my-scripts\01-tswfull\_mklink	swbase\; position: 148
-- Syntax error: at ),, expected <factor>
--  In line: try(select $'Bip*Spine*', $

One way could be:

nodes = #()
 join nodes $Bip*Spine*
 join nodes $Bip*Pelvis*
 select nodes
nodes = #()
 nodes += $Bip*Spine*
 nodes += $Bip*Pelvis*
 select nodes
select (#() + $Bip*Spine* + $Bip*Pelvis*)
3 Replies
(@tosyk)
Joined: 11 months ago

Posts: 0

this work great, but is there any way do not duplicate these “join nodes” lines?

(@polytools3d)
Joined: 11 months ago

Posts: 0

The last example is just one line.

(@tosyk)
Joined: 11 months ago

Posts: 0

oh, when I was quoting there was just first example thank you. Can I use last example like a top-down list?

I am not sure what a “top-down” list would be.

If you mean if the array would be unsorted or if that it would keep the order of the items as you add them, then yes, the items keeps the order as you add them. 
(#() + #("Z") + #("A") + #("B") + #("X") + #("M"))
  -- #("Z", "A", "B", "X", "M")
 
   (#() + #("8") + #("2") + #("10") + #("1") + #("3"))
 --#("8", "2", "10", "1", "3")

no, I meant how it represented in code:

I want something like this:

	$'Bip Acolyte1A Pelvis',
	$'Bip Acolyte1A Spine',
	$'Bip Acolyte1A Spine1',
	$'Bip Acolyte1A Spine2',
	$'Bip Acolyte1A Neck',
	$'Bip Acolyte1A Head',

In your case, if you want to select by nodes names, I don’t see how that could be easily solved using just PathNames:

$'Bip Acolyte1A Pelvis'	-- Select
$'Bip Acolyte1A Spine'	-- Select
$'Bip Acolyte1A Spine1'	-- Select
$'Bip Acolyte1A Spine2'	-- Select
$'Bip Acolyte1A Neck'	-- Select
$'Bip Acolyte1A Head'	-- Select

$'Bip Acolyte1A L UpperArm'	-- Avoid
$'Bip Acolyte1A L Forearm'	-- Avoid
$'Bip Acolyte1A L Hand'		-- Avoid
$'Bip Acolyte1A R UpperArm'	-- Avoid
$'Bip Acolyte1A R Forearm'	-- Avoid
$'Bip Acolyte1A R Hand'		-- Avoid
 Instead you could use RegEx: 
(
    	pattern = "Bip Acolyte1A [HNPS]"
    	regex = dotnetObject "System.Text.RegularExpressions.Regex" pattern
    	
    	clearselection()
    	select (for j in objects where regex.isMatch j.name collect j)
    )

It could also be helpful to use the nodes hierarchy, but I don’t know if this is the case.

1 Reply
(@tosyk)
Joined: 11 months ago

Posts: 0

I appreciate for this approach, PolyTools. But this is going to be really heavy for the case.
Can you explain why try() is not working along with the *?
I just wanna keep this simple and fast

I am sorry but I think I am not following you. Wildcards and Try()Catch() statements are to different things.

In your very first example what was failing was not the wildcard but the array you were building #2.

If you would like to use Try/Catch with the Select function you could just add it as follow:

try (select (#() + $Bip*Spine* + $Bip*Pelvis*)) catch()

But I don’t see any reason to use it as if no nodes with the given path are found, then it would just select an empty array, which does not throws any error.

2 Replies
(@tosyk)
Joined: 11 months ago

Posts: 0

I feel noob myself. Ok, I will try to explain. I’d like to use Try/Catch with the Select function because it let me keep code exactly as following:

try(select #(
	$'Bip Acolyte1A Pelvis',
	$'Bip Acolyte1A Spine',
	$'Bip Acolyte1A Spine1',
	$'Bip Acolyte1A Spine2',
	$'Bip Acolyte1A Neck',
	$'Bip Acolyte1A Head'
)) catch()
try(select #(

at the top,

)) catch()

at the bottom and a list of objects between them. As you can see the list of objects contains nothing except just object names with $ and commas which is fine by me (I can copy object names from Listener). I don’t need objects to be in line.

So in my case this code is working:

try(select #(
	$'Bip Acolyte1A Pelvis',
	$'Bip Acolyte1A Spine',
	$'Bip Acolyte1A Spine1',
	$'Bip Acolyte1A Spine2',
	$'Bip Acolyte1A Neck',
	$'Bip Acolyte1A Head'
)) catch()

And this code is not working:

try(select #(
	$'Bip*Pelvis',
	$'Bip*Spine*',
	$'Bip*Neck',
	$'Bip*Head'
)) catch()
(@polytools3d)
Joined: 11 months ago

Posts: 0

It’s not working for the same reason I explained earlier, the way you are building the array. So you do want each entry to be in a different line instead of one line?

try(select (#() +
 	$'Bip*Pelvis' +
 	$'Bip*Spine*'  +
 	$'Bip*Neck' +
 	$'Bip*Head'
  )) catch()

Which is the same as this:

try(select (#() + $'Bip*Pelvis' + $'Bip*Spine*' + $'Bip*Neck' + $'Bip*Head'))catch()

Thank you so much! This is exactly what I looked for.