Notifications
Clear all

[Closed] String to new file

When printing a string value into a new file…is it possible to do it without the quotes getting written out as well?

Thanks!!

18 Replies
 lo1

Please show your code, the quotes are not supposed to be written.

Well…don’t laugh…just trying to figure out how to build a file that i already have a template for…so heres where i am.


 hve3d_template_part_1="This is my string"
 
 out_name = getSaveFileName \
  Filename: "c:/Temp/stringtest.dat" \
  types:"Data(*.dat)|*.dat|Text(*.txt)|Excel(*.csv)|All(*.*)|"
 							
 							
 out_file = createfile out_name													 
 print hve3d_template_part_1 to:out_file							
 							
 close out_file
 
 

I tried to assemble the first part of the template i have but it has strings inside it so not sure how to approach that either. The first part looks like this:


 #Inventor V2.0 ascii
 Separator
 {
 	Info
 	{
 		string	"Details about the vehicle - Year/Make/Model"
 	}
 	ShapeHints
 	{
 		vertexOrdering COUNTERCLOCKWISE
 		shapeType UNKNOWN_SHAPE_TYPE
 		faceType CONVEX
 	}
 
 	Switch {
 	whichChild -1
 
 

Thanks for the help.

 lo1

use format instead of print, just remember that you need to add
for line breaks.

If you need to print actual ” characters, use the escape code:

\"

see string literals in the maxscript help.

Thank you soooooooooo much…got it working perfectly! If we’re ever in the same place i’ll buy you a beer!

One more quick question. If i’m using something like this(not the whole code bit):


  for v = 1 to num_verts do
  format "%
" (getVert tmesh v)  to:out_file
  

Why do the vert coordinates come out like this:

[-0.420152,20.7161,0]
  [-0.420152,19.7908,3.45334]
  [-0.420152,17.2628,5.98135]
  [-0.420151,13.8094,6.90667]
  [-0.420151,10.3561,5.98135]
  [-0.420151,7.82808,3.45334]
  

…and not like this in the out_file:


  -0.420152,20.7161,0
  -0.420152,19.7908,3.45334
  -0.420152,17.2628,5.98135
  -0.420151,13.8094,6.90667
  -0.420151,10.3561,5.98135
  -0.420151,7.82808,3.45334
  

Thanks!

Because every coordinates always come out like point2 ([x,y]) or point3 ([x,y,z]) value.
Try this

for v = 1 to num_verts do
 (
 	local coord = getVert tmesh v
 	format "%,%,%
" coord.x coord.y coord.z  to:out_file
 )

Hmmm…that didn’t work. It threw this into the listener:


$Torus:Torus001 @ [-0.420151,-1.604431,0.000000]
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2012\Scripts\DDE Scripts\Vehicle Metrics\IndividualScripts\Building the h3d file\; position: 1489; line: 45
--  Frame:
--   num_verts: 288
--   coord: undefined
--   num_faces: 576
-- Unknown property: "x" in undefined
OK

1 Reply
 lo1
(@lo1)
Joined: 2 years ago

Posts: 0

It could be understandable how this would not work on a Torus since getVert only accepts an editable mesh, but in that case it would raise an exception and would never simply return undefined into coord. Please post the code you’re using.

Here it is:


  
  fn GetGeometry o = (
   Superclassof o == Geometryclass and classof o != TargetObject )  
  obj = pickobject filter:GetGeometry  
  if isValidNode obj then  
  (
  
  tmesh =snapshotAsMesh obj  
  
   out_name = getSaveFileName \
 Filename: "c:/Temp/geometrytest/geometryoutputtest.txt" \
 types:"Text (*.txt)"  
  							
  							
   if out_name != undefined then  
   (
  
  
  	 
    out_file = createfile out_name  
  	 
  
  	
    num_verts = tmesh.numverts  
    num_faces = tmesh.numfaces  
  	 
    for v = 1 to num_verts do  
  	
  	
    local coord = getVert tmesh v
  	 format "%,%,%
" coord.x coord.y coord.z  to:out_file
     --format "%
" (getVert tmesh v)  to:out_file 
  
    for f = 1 to num_faces do   
  	  
    (
     face = getFace tmesh f 
  	
     format "%
" face to:out_file 
    )
    close out_file
    edit out_name
   )
  )
  
  
  

I test this and it works

fn GetGeometry o = (Superclassof o == Geometryclass and classof o != TargetObject)
  obj = $Torus001 --pickobject filter:GetGeometry  
  if isValidNode obj then  
  (
  	tmesh =snapshotAsMesh obj  
  	out_name = getSaveFileName \
  	Filename: "c:/Temp/geometryoutputtest.txt" \
  	types:"Text (*.txt)"  
  							  
  	if out_name != undefined then  
  	(
  		out_file = createfile out_name  
  		num_verts = tmesh.numverts  
  		num_faces = tmesh.numfaces  
  		for v = 1 to num_verts do  
  		(
  			local coord = getVert tmesh v
  			format "%,%,%
" coord.x coord.y coord.z  to:out_file
  		)
  		for f = 1 to num_faces do   
  		(
  			face = getFace tmesh f 
  			format "%
" face to:out_file 
  		)
  		close out_file
  		edit out_name
  	)
  )

Maybe is better to use *.ini then *.txt in your case

Page 1 / 2