Notifications
Clear all

[Closed] Remove the quotes marks from a string how.?

[font=Arial]I want to make a script that changes material properties base on what the user type on the edittext dialog[/font]

 [font=Arial]So the user types in an edittext the material property like    mat.texmap_reflection.ior = 0[/font]

 [font=Arial]But the result from the edittext.text is 

[/font]

[font=Arial]“mat.texmap_reflection.ior = 0”
and I need
mat.texmap_reflection.ior = 0[/font]

 [font=Arial]Any ideas?[/font]

see this sample please.

rollout test "test" width:300
 (
 	edittext edi_Custom "mat." fieldWidth:165  align:#left across:2
 	spinner spn_Custom "%" range:[-1000,1000,0]   align:#right
 	button go "Go"
 	
 	on test open do
 		(
 			edi_Custom.text = "specularLevel"
 		)
 		
 	on go pressed do
 		(
 			format "what:%  value:% 
" edi_Custom.text spn_Custom.value
 			theChange = edi_Custom.text
 			meditMaterials[1].theChange = spn_Custom.value
 		)
 )
 createdialog test 

[font=Arial][/font]

 Thanks,

Guillermo Leal
[font=Arial][/font]

8 Replies

Not sure if this will help but you can evaluate a string as though it were a statement by using the execute command.

thanls Eric for your replay,

i did try the execute and it works on a single item but not in an array. see the two samples.

this works.

rollout test "test" width:300
  (
  	edittext edi_Custom "mat." fieldWidth:165  align:#left across:2
  	spinner spn_Custom "%" range:[-1000,1000,0]   align:#right
  	button go "Go"
  	
  	on test open do
  		(
  			edi_Custom.text = "specularLevel"
  		)
  		
  	on go pressed do
  		(
  			--format "what:%  value:% 
" edi_Custom.text spn_Custom.value			
  			str = "meditMaterials[1]." + edi_Custom.text + "=" + spn_Custom.value as string
  			execute str
  		)
  )
  createdialog test 

this dosen’t

rollout test "test" width:300
  (
  	edittext edi_Custom "mat." fieldWidth:165  align:#left across:2
  	spinner spn_Custom "%" range:[-1000,1000,0]   align:#right
  	button go "Go"
  	
  	on test open do
  		(
  			edi_Custom.text = "specularLevel"
  		)
  		
  	on go pressed do
  		(
  			--format "what:%  value:% 
" edi_Custom.text spn_Custom.value				
  			TheMaterials = sceneMaterials
  			numOfMatInScene = TheMaterials.count
  				for i = 1 to numOfMatInScene do 
  				(
  					--print TheMaterials[i]
  					str = TheMaterials[i] as string + "." + edi_Custom.text + "=" + spn_Custom.value as string
  					execute str
  					--print str
  				)
  		)
  )
  createdialog test 

Guillermo Leal

In order to troubleshoot your code, I recommend you try to do the same exact execute command with each version (the single versus the array). You’re doing enough different stuff in the one that’s not working that it would be worth your while to mimick the one that IS working first.

Ok I have broken down the issue here. basically when you execute TheMaterials[i] it returns the name and type of that material instead of an index of the material. So the best soultion is to use scenematerials[i] directly to get your materials. Also you have to include the index number seperately and include the square bracke s in the surrounding strings. Im not sure if this makes sense, but here is the code that works.

rollout test "test" width:300
   (
 	  edittext edi_Custom "mat." fieldWidth:165  align:#left across:2
 	  spinner spn_Custom "%" range:[-1000,1000,0]   align:#right
 	  button go "Go"
 	  
 	  on test open do
 		  (
 			  edi_Custom.text = "specularLevel"
 		  )
 		  
 	  on go pressed do
 		  (
 			  --format "what:%  value:% 
" edi_Custom.text spn_Custom.value				
 				  for i = 1 to sceneMaterials.count do 
 				  (
 					  --print TheMaterials[i]
 					  str = "sceneMaterials["+ (i as string) + "]." + edi_Custom.text + "=" + spn_Custom.value as string
 					  execute str
 					  --print str
 				  )
 		  )
   )
   createdialog test 

Eric,

Cool, that did the trick! thanks a lot.

Guillermo M Leal.

This is probably a stupid statement, but couldn’t you use filterstring??


[font=Arial]sText = [/font][font=Arial]“mat.texmap_reflection.ior = 0” [/font][font=Arial] 
aText = filterString sText "/"" -- #([/font][font=Arial]"/“", mat.texmap_reflection.ior = 0, "/"”)[/font]
[font=Arial]
sValue = aText[2] //[/font][font=Arial]mat.texmap_reflection.ior = 0[/font]

Shane

Please delete, double post

Rusty, isn’t the issue that even with filtering a string, you still have to execute it… the “‘s aren’t the problem, the fact that it is a string is, which is taken care of by executing it.

The thread title is not really what the OP wanted to do…