Streamstream (Can it be used to store seperate strings and then replace?)

OldStringCorona =  "_Corona"
OldStringVRay =  "_Vray"
OldStringScanline =  "_Scanline"
NewString = ""
 
--fileName = getFilenameFile (maxFilename)
 
fileName = "sdd_Scanline"
 
if fileName != undefined and matchPattern fileName pattern:("*"+OldStringCorona+"*" OR "*"+OldStringVRay+"*" OR "*"+OldStringScanline+"*") ignoreCase:false == true then (
		Newfilename = if fileName != undefined and matchPattern fileName pattern:("*"+OldStringCorona+"*") ignoreCase:false == true then (fileNameTemp = replace fileName (findstring fileName OldStringCorona) OldStringCorona.count NewString)
		Newfilename = if fileName != undefined and matchPattern fileName pattern:("*"+OldStringVRay+"*") ignoreCase:false == true then (fileNameTemp = replace fileName (findstring fileName OldStringVRay) OldStringVRay.count NewString)
		Newfilename = if fileName != undefined and matchPattern fileName pattern:("*"+OldStringScanline+"*") ignoreCase:false == true then (fileNameTemp = replace fileName (findstring fileName OldStringScanline) OldStringScanline.count NewString)
	)
Newfilename

1. I want this script to get the filename. Code not working above but just to gice you an idea where I'm at.
2. Remove either '_VRay' '_Corona' '_Scanline' from this to ''.
3. I tried StringStream Values in my first version but didn't get success.

Can it be used in this instance?

Link for StringStream http://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/201...

My initial version was like:

TrimMe = stringstream "\"_VRay.max\\t_Corona.max\\t_Scanline.max\"" --notes \" Escape and \\t is the StringEscapes
seek TrimMe 0
readvalue TrimMe
max_file_name = getFilenameFile (trimright maxFilename TrimMe)

But this trimright yielded unsuccessful results.

Any help would be grateful. Thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
3dwannab's picture

Regexpression Example

These 4 line of code do the exact same only better as long as you learn regular expressions:

OldString =@"(?i)_Corona$|_Vray$|_Scanline$"
OldMaxFileName = getFilenameFile (maxFilename)
rgx = dotnetObject "System.Text.RegularExpressions.Regex" OldString
NewMaxFileName = rgx.Replace OldMaxFileName ""

(?i) turns on case insensitive
_Corona$ Matches a string with _Corona at the end
| separates each match

3dwannab's picture

Small bug in last code

NEW:

OldStringCorona =  "_Corona"
OldStringVRay =  "_Vray"
OldStringScanline =  "_Scanline"
NewString = ""
 
max_file_name = "test_Corona" --getFilenameFile (maxFilename)
 
try(
	case of
	(
		(matchPattern max_file_name pattern:("*"+OldStringCorona) ignoreCase:true): (fileNameNew = replace max_file_name (findstring max_file_name OldStringCorona) OldStringCorona.count NewString)
		(matchPattern max_file_name pattern:("*"+OldStringVRay) ignoreCase:true): (fileNameNew = replace max_file_name (findstring max_file_name OldStringVRay) OldStringVRay.count NewString)
		(matchPattern max_file_name pattern:("*"+OldStringScanline) ignoreCase:true): (fileNameNew = replace max_file_name (findstring max_file_name OldStringScanline) OldStringScanline.count NewString)
		(matchPattern max_file_name pattern:("*") ignoreCase:true): (fileNameNew = max_file_name)
	)
)catch()
print fileNameNew

Added:
(matchPattern max_file_name pattern:("*") ignoreCase:true): (fileNameNew = max_file_name)
at the last case of to ensure matching strings where none of the first matchpatterns didn't exist.

fajar's picture

using case of will solve this

using case of will solve this ....

case yourCase of
(
OldStringCorona   : (do something)
OldStringVRay     : (do something)
OldStringScanline : (do something)
)

I think that will give you an idea to do that, making it function will be good too.

3dwannab's picture

Sorry For The Late Replay.

Sorry For The Late Replay. Been busy elsewhere:

Here's the code now with some of the other code (The script rename objects to filename and based on object type) . Maybe the case of could do with a clean up, any suggestions?

Thanks very muchio :)

-- PREFIXES: use these or a spectator of your choice (do not leave blank)
cameraPreFix = "_Cam_" as string
lightPreFix = "_Light_" as string
geoPreFix = "_Geo" as string
 
--------------------------------------------------------------------------------------
OldStringCorona =  "_Corona"
OldStringVRay =  "_Vray"
OldStringScanline =  "_Scanline"
NewString = ""
 
max_file_name = getFilenameFile (maxFilename)
 
try(
	case ReplacePrefix of
	(
		(matchPattern max_file_name pattern:("*"+OldStringCorona+"*") ignoreCase:false): (fileNameNew = replace max_file_name (findstring max_file_name OldStringCorona) OldStringCorona.count NewString)
		(matchPattern max_file_name pattern:("*"+OldStringVRay+"*") ignoreCase:true): (fileNameNew = replace max_file_name (findstring max_file_name OldStringVRay) OldStringVRay.count NewString)
		(matchPattern max_file_name pattern:("*"+OldStringScanline+"*") ignoreCase:true): (fileNameNew = replace max_file_name (findstring max_file_name OldStringScanline) OldStringScanline.count NewString)
	)
)catch()
 
if fileNameNew == undefined then fileNameNew = max_file_name
 
if max_file_name == "" then(
		max_file_name = getSaveFileName getSaveFileName()
		if max_file_name == undefined then messagebox "Output File Not Set !\n\nSave file first !"
	)
	else(
		--clearsel
		clearselection()
 
		--geometry
		for obj in geometry do obj.name = fileNameNew + geoPreFix

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.