Notifications
Clear all

[Closed] remove quotes from string?

Hi, is there a way to basically convert string to “pure text” a.k.a without the quotes, so It can be used things like select or making variables etc.

this is just a simple example but something like this but actually working:

select (format ("$Teapot00" + (1 as string));

Working same as this:

select (getnodebyname "Teapot001")

Also, is there a way to do getnodebyname and select all nodes starting with a specific word,

Working same as this:

select $Teapot*

But like this: (not working)

select (getnodebyname "Teapot"*);

Thanks in advance.

10 Replies
teapot = execute "$Teapot00"

will select and set the variable if it exists in the scene
and

 a = execute "$Teapot*"

will create an array of all nodes called teapot…

7 Replies
(@patan77)
Joined: 11 months ago

Posts: 0

thx, that could be useful to know in the future for stuff, but not really what I’m trying to ask, these examples is very simplified and are just set up to further try explain the thing I’m looking for, its not the thing am actually doing, i’m not trying to select a teapot and create a variable, the actual thing(code) function i’m working on is way more complex.

I’m just wondering if is a way that does the opposite of ( some_text as string) and convert it back to some_text instead of “some_text”

I’ guess I might be able to do trim left and right maxscript but not sure if it actually works / should be a better way

(@swordslayer)
Joined: 11 months ago

Posts: 0

No and honestly, it wouldn’t even make sense, as string simply gives you sort of a string representation of the object/value, not the object/value itself ‘wrapped’ in quotes. Take for example ‘(Box()) as string’. You won’t be able to get the original object back. Same with float values, most of the time you will only get a value that’s nearly the same but not the same. The quote characters are only there to denote it’s a string value and are not actualy part of it so it’s not something you could trim of it.

I don’t know what you’re after but Klvnk already gave you an answer; execute is about as good a tool as you can get. Might be a good idea to tell us what is that complex function supposed to do or what’s the task at hand, too.

(@patan77)
Joined: 11 months ago

Posts: 0

well here is another example, lets say I want it to create multiple new unique variables like this:

ar_get_curent_Selection = (selection as array);	
		
		for i = 1 to ar_get_curent_Selection.count do	(
			global ("var_")+ ((ar_get_curent_Selection[i].name;) as string) = point();
			-- print (("var_")+ ((ar_get_curent_Selection[i].name;) as string))
		);
		
		
		

so if I have 5 Teapot’s selected it and I want it to create 5 new variables like this:

var_Teapot001 = point(); – would create a new point helper (Point001)
var_Teapot002 = point(); – would create a new point helper (Point002)
var_Teapot003 = point(); – would create a new point helper (Point003)
var_Teapot004 = point(); – would create a new point helper (Point004)
var_Teapot005 = point(); – would create a new point helper (Point005)

so the example above I would want to work like this:

ar_get_curent_Selection = (selection as array);	
		
		for i = 1 to ar_get_curent_Selection.count do	(
			global var_Teapot001 = point();
		);
		
		
		

But currently it is like this:

ar_get_curent_Selection = (selection as array);	
		
		for i = 1 to ar_get_curent_Selection.count do	(
			global "var_Teapot001" = point();
		);
		
		
		

Basically taking multiple strings put them together and make that an variable.

(@denist)
Joined: 11 months ago

Posts: 0

it seems like you want to make (create, define) something dynamically.
execute is the thing for 90% cases.
but it might be another solution… just tell us what exactly you want to do.

(@patan77)
Joined: 11 months ago

Posts: 0

Well here is how I ended up using it :

ar_count_fetch = (execute ("$" + "hold_point_"+ ((ar_get_curent_Selection[i].name)as string) + "*"));
temp_point_hold = (getnodebyname ("hold_point_" + ((ar_get_curent_Selection[i].name)as string) + "_" +  (ar_count_fetch.count as string))) ;

Though a few days ago I also wanted to do the “remove quotes” thing but in a bit different way, but can’t remember at the moment what exactly it was for, but pretty sure I didn’t solve it so I probably will bump in to that issue again, if so, i’ll post it then.

(@denist)
Joined: 11 months ago

Posts: 0

well… first of all it’s better to write clear code. not for other people but mostly for yourself:

name = current_selection[i].name
point_path = "$'hold_point_" + name + "'*" 
hold_points = execute point_path
temp_point_name = "hold_point_" + name + "_" + hold_points.count as string
temp_point = getnodebyname temp_point_name

is it what you really want?

honestly it doesn’t make too much sense for me

(@patan77)
Joined: 11 months ago

Posts: 0

Yeah, that also works, and sure its definitely better to try writing as clear as possible, but thats just kind of how I write stuff, so at least i’m consistent with the mess (;

He, yeah I don’t expect it to make much sense without the rest of the code, but everything works now, problem solved (for now), so don’t worry to much about it. But thanks still

Well, you can do that, the question is why on earth would you? Anyway, that would be for example:

execute (str = ""; for obj in selection do str += "var_" + obj.name + " = point();"; str)
1 Reply
(@patan77)
Joined: 11 months ago

Posts: 0

Thanks, yeah I probably wouldn’t do that, I just created that as example cause I couldn’t figure out any other way to solve that other than the “remove quotes” method, and I’m pretty sure I have done the “remove quotes” method in javascript or VB or something else by using trim on a string, but yeah I guess in max execute actually were the method I was looking for. Because I were able to use it to solve the issues I was trying to actually solve.

So thanks to the both of you.
:keenly: