String to new file

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2012   #1
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!!
 
Old 06 June 2012   #2
Please show your code, the quotes are not supposed to be written.
 
Old 06 June 2012   #3
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.
 
Old 06 June 2012   #4
use format instead of print, just remember that you need to add \n for line breaks.

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

see string literals in the maxscript help.
 
Old 06 June 2012   #5
Thank you soooooooooo much....got it working perfectly! If we're ever in the same place i'll buy you a beer!
 
Old 06 June 2012   #6
One more quick question. If i'm using something like this(not the whole code bit):


  for v = 1 to num_verts do
  format "%\n" (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!
 
Old 06 June 2012   #7
Originally Posted by dellis: One more quick question. If i'm using something like this(not the whole code bit):


    for v = 1 to num_verts do
    format "%\n" (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 "%,%,%\n" coord.x coord.y coord.z  to:out_file
 )
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2012   #8
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
 
Old 06 June 2012   #9
Originally Posted by dellis: 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


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.
 
Old 06 June 2012   #10
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 "%,%,%\n" coord.x coord.y coord.z  to:out_file
     --format "%\n" (getVert tmesh v)  to:out_file 
  
    for f = 1 to num_faces do   
  	  
    (
     face = getFace tmesh f 
  	
     format "%\n" face to:out_file 
    )
    close out_file
    edit out_name
   )
  )
  
  
  
 
Old 06 June 2012   #11
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 "%,%,%\n" coord.x coord.y coord.z  to:out_file
  		)
  		for f = 1 to num_faces do   
  		(
  			face = getFace tmesh f 
  			format "%\n" face to:out_file 
  		)
  		close out_file
  		edit out_name
  	)
  )

Maybe is better to use *.ini then *.txt in your case
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2012   #12
Originally Posted by dellis: Here it is:
  
    for v = 1 to num_verts do   	
(
    local coord = getVert tmesh v
  	 format "%,%,%\n" coord.x coord.y coord.z  to:out_file
 )
  


your problem was a lack of brackets. Your original code is like writing:
for v = 1 to num_verts do (local coord = getVert tmesh v)
 format "%,%,%\n" coord.x coord.y coord.z  to:out_file


the second line has no idea what coord is because it was local to the scope of the for loop. Not only that, it will only run once because it's outside of the loop.
 
Old 06 June 2012   #13
Originally Posted by lo: your problem was a lack of brackets. Your original code is like writing:
for v = 1 to num_verts do (local coord = getVert tmesh v)
  format "%,%,%\n" coord.x coord.y coord.z  to:out_file


the second line has no idea what coord is because it was local to the scope of the for loop. Not only that, it will only run once because it's outside of the loop.

lo, thanks for the explanations.
I just post working code to dellis to see by yourself where he is wrong.
But your comment is a bonus.
Cheers!
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2012   #14
Thank you guys so much! And i appologize if its stupid...but i can't get the brackets off the coordinates in the face index. I looked in the help file but i can't seem to find what i am looking for. My mistake that you corrected above works perfect and i understand that you used this because each vertex has a a number and an x,y,z....just not sure what i should use for a face to get rid of the square brackets since i'm not looking for coords...

This is what i'm getting for output right now which is really, really close!


  DEF BODY0 Separator 
  	{
  		Coordinate3
  		{
  			point [
  2.68518,-62.1888,0.0
  47.9616,-62.1888,0.0
  2.68518,-25.3717,0.0
  47.9616,-25.3717,0.0
  2.68518,-62.1888,29.7604
  47.9616,-62.1888,29.7604
  2.68518,-25.3717,29.7604
  47.9616,-25.3717,29.7604
  	]
  		}
  
  USE BODY		
  		IndexedFaceSet		
  		{		
  			coordIndex [
  [1,3,4]
  [4,2,1]
  [5,6,8]
  [8,7,5]
  [1,2,6]
  [6,5,1]
  [2,4,8]
  [8,6,2]
  [4,3,7]
  [7,8,4]
  [3,1,5]
  [5,7,3]
  ]	
  		}		
  				
  	}
  


I just have to get rid of the orange guys...

Again..thanks for all your help! Maxscript is awesome....lots to learn though!!
 
Old 06 June 2012   #15
Originally Posted by dellis: i understand that you used this because each vertex has a a number and an x,y,z....


Faces are represented as Point3 values as well, and therefore also have .x .y .z properties (or alternatively, can be indexed using [1] [2] [3]. The fact that the .x .y .z properties don't actually represent cartesian coordinates, but vertex indices, is of no importance.

face = getFace tmesh f 
format "%, %, %\n" (face.x as integer) (face.y as integer) (face.z as integer) to:out_file


I am casting to integer because Point3 values are always stored as float, and would result in
1.0, 3.0, 4.0
instead of
1, 3, 4
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:27 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.