CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 06-21-2012, 02:33 PM   #1
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
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-21-2012, 02:46 PM   #2
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,840
Please show your code, the quotes are not supposed to be written.
 
Old 06-21-2012, 02:58 PM   #3
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
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.

Code:
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:

Code:
#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-21-2012, 03:05 PM   #4
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,840
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:
Code:
\"

see string literals in the maxscript help.
 
Old 06-21-2012, 03:23 PM   #5
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
Thank you soooooooooo much....got it working perfectly! If we're ever in the same place i'll buy you a beer!
 
Old 06-21-2012, 07:48 PM   #6
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
One more quick question. If i'm using something like this(not the whole code bit):

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


Why do the vert coordinates come out like this:
Code:
[-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:
Code:
-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-21-2012, 08:37 PM   #7
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by dellis
One more quick question. If i'm using something like this(not the whole code bit):

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


Why do the vert coordinates come out like this:
Code:
[-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:
Code:
-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
Code:
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-22-2012, 01:26 PM   #8
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
Hmmm...that didn't work. It threw this into the listener:

Code:
$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-22-2012, 02:42 PM   #9
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,840
Quote:
Originally Posted by dellis
Hmmm...that didn't work. It threw this into the listener:

Code:
$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-22-2012, 05:03 PM   #10
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
Here it is:

Code:
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-22-2012, 06:07 PM   #11
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
I test this and it works
Code:
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-22-2012, 07:26 PM   #12
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,840
Quote:
Originally Posted by dellis
Here it is:
Code:
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:
Code:
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-22-2012, 09:15 PM   #13
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by lo
your problem was a lack of brackets. Your original code is like writing:
Code:
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-26-2012, 08:09 PM   #14
dellis
Know-it-All
 
dellis's Avatar
portfolio
Dwayne Ellis
Ellis Digital Solutions Inc.
Tecumseh, Canada
 
Join Date: Dec 2004
Posts: 321
Send a message via MSN to dellis
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!

Code:
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-26-2012, 09:46 PM   #15
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,840
Quote:
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.

Code:
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
Code:
1.0, 3.0, 4.0
instead of
Code:
1, 3, 4
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:07 PM.


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