Notifications
Clear all

[Closed] execute string in loop

Hello. The code below is meant to place custom attribute parameters on a spline but all it does is place the first one (morphs_used [1] = up ) on it. I’ve tried every variation of “execute str” and placement of the string but nothing seems to get the desired result. Any suggestions?
Thank you for your time.

 
ctrl = getnodebyname "FaceControl001"
 
morphs_used = #("up", "down", "turnaround")
 
addmodifier ctrl (EmptyModifier ())
 
str = "for i = 1 to 3 do (
	 (attdef = attributes facialctrl
		 ( parameters face
 
			 ( 
" + morphs_used[i]+" type:#float;
 
 
			 )
 
		 ) 
	 )
 
						 ) 
" 
 
execute str 
 
custAttributes.add ctrl.modifiers[1] attdef
 
 
 
 
--This doesn't seem to work either:
 
ctrl = getnodebyname "FaceControl001"
morphs_used = #("up", "down", "turnaround")
addmodifier ctrl (EmptyModifier ())
 
for i = 1 to 3 do (
str = " (attdef = attributes facialctrl
			 ( parameters face
 
				 ( 
" + morphs_used[i]+" type:#float;
 
 
				 )
 
			 ) 
			)
 
" 
					  )
execute str 
 
custAttributes.add ctrl.modifiers[1] attdef

11 Replies
 JHN

Please wrap the code bits in a code block in the editor press the “#” button!
It’s unreadable.

Thanks,
-Johan

yes. I have done so. Don’t know if it makes matters clearer, however.

 JHN

Maybe some more effort in proper formatting with yield some faster feedback, but…
your first idea is not sound at all, the for loop in wrapped in a string that makes 3 attributes, and the result of the for loop, what I assume will be undefined or void is what you assign to the custAttributes. This makes no sense.
The second idea is better, but doesn’t work because of bad code(!?).
So rewriting what you want to do gives me code that looks like this:


ctrl = $
-- ctrl = getnodebyname "FaceControl001"
 
morphs_used = #("up", "down", "turnaround")
 
addmodifier ctrl (EmptyModifier ())

for i = 1 to morphs_used.count do 
(
	local attStr = ""
	attStr += "attdef = attributes facialctrl
"
	attStr += "(
"
	attStr += "	parameters face
"
	attStr += "	(
"
	attStr += "		" + morphs_used[i] + " type:#float
"
	attStr += "	)
"
	attStr += ")"

	execute attStr
	custAttributes.add ctrl.modifiers[1] attdef
)

That leaves me with one question, why would you want to have a custom attribute per morph channel used, wouldn’t it make more sense to make 1 custom attribute with an array parameter and write to the array param the channels you used. Image having 20 channels, resulting in 20 CA’s on this modifier alone… Something to think about.

-Johan

 eek

One reason for me anyway is to store the order they were created for combination (corrective), and to store the space world value, pre turned into a corrective. Wish CA’s could store nested arrays…

For this instance thought – you could just iterated though the channels something like so:

for c = 1 to 100 where WM3_MC_HasData morpher c do
(
    append myAttrib.myStringArray morpher[c].name
)

Thank you both, but running your code, I get three CAs, when what I need are three parameters under one CA,( ‘facial control’)…The parameters are necessary in order to instance controllers so I can have a holder for poses on the spline.
Yes it would be better to have a parameter array – that was my original idea – but how do I get rid of the string quotes? morphs_used[1] is “up”, but I want just up.

 JHN

Did you read my post? Obviously I was wondering the same thing. What you want is already there just shuffle the for loop.

-Johan

yes JHN. Of course I read your post, and I have done a lot – and I mean a LOT of shuffling of the for loop, and got nowhere… either I get ‘name expected ‘errors, or I just get the first member of the array as parameter.

 JHN

(
	ctrl = $
	-- ctrl = getnodebyname "FaceControl001"
	 
	morphs_used = #("up", "down", "turnaround")
	 
	addmodifier ctrl (EmptyModifier ())



	local attStr = ""
	attStr += "attdef = attributes facialctrl
"
	attStr += "(
"
	attStr += "	parameters face
"
	attStr += "	(
"

	for i = 1 to morphs_used.count do 
	(	
		attStr += "		" + morphs_used[i] + " type:#float
"
	)

	attStr += "	)
"
	attStr += ")"

	execute attStr
	custAttributes.add ctrl.modifiers[1] attdef
)

-Johan

Well, thanks heaps JHN. It works. However, the compilier didn’t like the local declaration…said something about :“no local declarations at top level: attStr”…apart from that, when I got rid of the local declaration, it ran fine. Also, the first two parameters appear in upper case under the CA modifier, the third in lower case. Weird. Are you up on why that happened? Anyways, thanks – youre a godamn genius,man.

Page 1 / 2