Notifications
Clear all

[Closed] format to file with ""

I need to send the name of an object out to a text file with the “” intact around the string.
.
At the moment I have the line

format "objectName = %
" objectName to:file

which produces

objectName = Small

in the text file.

What I’m after is this

objectName = "Small"

How would I go about this? It’s got me a bit stumped.

Thanks,
Cg.

23 Replies

format "objectName = \"%\"
" objectName to:file

Try that

 PEN

Just wondering why you need this. When a file is read in, it is read as a string. These means that all data written to a file will have “” around them once read in.

1 Reply
(@pjanssen)
Joined: 11 months ago

Posts: 0

It could be anything parsing the file, so it can just as well be required syntax.
And of course there’s a difference between what you suggest:
“objectName = Small”
and what he’s after:
objectName = “Small”

 JHN

…skip this

What paul is saying is that it’s always
“objectName = Small” anyways. It’s always a string, so adding additional quote brackets is serving no purpose.

-Colin

 PEN

I would normaly use something like filterString str “=” and then get the two parts and do somthing with it. That way I can test both parts to make sure that it is what I want.

I need to do that cause I’m writing a script that will write a script that wil rebuild poly objects. I’m writing a way for me to take models from say max 9 to max 8. So I want to be able to run this script on a poly object and have it write out a script that when run in another version of max it will rebuild the poly object with all the cool max stuff that other export formats won’t support like ALL the UV channels, vert colours etc. I am relatively new to maxscript so I may be doing some stuff awkwardly.

Here’s my script as it stands now. It’s far from finshed but the base is working but it’s also really slow to rebuild big objects as it is. I’m going to test whether writing an array into the built script and using a for loop instead of writing every line out will make it run faster. Any suggestions are very welcome.


  clearlistener()
  
  if (selection.count == 1) and (superclassof $ == geometryclass) and (classof $ != TargetObject) then
  (
  	outName = ("C:\\PolyExport.ms")
  	outFile = createfile outName
  	tempObj = snapshot $
  	convertTo tempObj PolyMeshObject
 	vertCount = polyop.getnumVerts tempObj
  	polyCount = polyop.getNumFaces tempObj
  	objectName = $.name
  
  	format "clearlistener()
" to:outFile
  --	format "objectName = %
" objectName to:outFile
  	format "newPoly = editable_mesh()
" to:outFile
  	format "convertTo newPoly PolyMeshObject
" to:outFile
  
  	for i = 1 to vertCount do
  	(	
  		vert = polyop.getvert tempObj i
  		format "polyop.createvert newPoly %
" vert to:outFile
  
  	)
  	for i = 1 to polyCount do
  	(
  		poly = polyop.getFaceVerts tempObj i
  		format "polyop.createPolygon newPoly %
" poly to:outFile
  
  	)
  	close outFile	
  	delete tempObj
  )
  else
  (
  	messagebox "Select one geometry object to export" title:"Selection Error"
  )

In some cases, yes.

But not in all cases.
For example XML requires the data to be in quotes:

<NODE NAME=“paulNeale” TYPE=“TD”>
</NODE>

If you don’t add the additional quotes, things go very wrong.
Pjanssen’s suggestion is the correct way to solve the problem when you need additional quotes.

Take care,

I’d have to agree with moondoggie and Paul on this way, although kees is absolutly correct. Seen as the output is actually a script, then cg needs this approach. He’s not just dumping data, but he’s also creating a “self run” script to re-compile the objects…

I think Bobo did something simular sometime ago, might be worth looking at…

Shane

The one that Bobo wrote, are you meaning the BFF (back from five) that has since changed to Bobo’s file format?

2 Replies
(@gravey)
Joined: 11 months ago

Posts: 0

Yes I believe that’s the one Shane’s talking about. I recently checked out the code for it and it really helped to get me on the right track for a script i’ve been writing for work. I’d say definatly take a look if you havn’t already

(@rustyknight)
Joined: 11 months ago

Posts: 0

Yeah, that’s the one. I tried it last year to go from 9 to 8, but it didn’t quite meet our needs, but it looked really interesting!

Well worth a look into to help out with any problem areas you might have.

Shane

Page 1 / 3