Notifications
Clear all

[Closed] read external file question

Hello all, I’m a complete novice in Maxscript, or any script for that matter and wanted assistance on one of the most basic of all operations. I checked the Maxscript help within 3dSM2009 but was unable to help myself and decided to ask here after google refused to be of assistance either.

as part of a larger script, I’m writing a command that needs to scale a render in order to be in a certain ratio to reality in pixels to inches. I made a script that will convert from max units to the manufacturer’s intended ratio if I can get that information from an external file. I’m attempting to have it grab a file, search for length, width, and depth in that file and return the values in a way I could access them as part of a variable. Currently what I’m having problems with is the very basic taking information from the file, after

  f=fopen "c:\\doortest.txt" "rt"

I’m completely clueless, I think I need to do something along the lines of

  skipToString <filestream> "width"

then somehow read the values but I’m unsure. I would like to thank anyone who helps in advance for your patient assistance.

12 Replies

how is the data laid out in your txt file?

height = xx
 width = xx
 depth = xx

or…

xx
xx
xx

The system isn’t 100% set up yet, could have it defined as either. Thank you very much for your prompt response. It’s going to end up batching a few hundred/thousand objects so

height = xx
width = xx
depth = xx
or
height = xx width = xx depth = xx Seem like they would be the most likely options.

function getDimsfromFile file =
(
 struct dimensionsStruct (height,width,depth)
 dimensions = dimensionsStruct()
 csvfile = openFile file mode:"r"
 seek csvfile 0
 skipToString csvfile "depth="
 dimensions.depth = (readline csvfile) as float
 seek csvfile 0
 skipToString csvfile "height="
 dimensions.height = (readline csvfile) as float
 seek csvfile 0
 skipToString csvfile "width="
 dimensions.width = (readline csvfile) as float
 dimensions
)

File:
width=xxx.xx
height=xxx.xx
depth=xxx.xx

Oh yeah and usage would be like

FileDimensions = getDimsfromFile “C:\file.txt”

#Returns a Struct#

FileDimensions.Width gives you the width
FileDimensions.Height gives you the height
FileDimensions.Depth gives you the depth

Thank you very much for your assistance! It was very helpful though I’ve run into another error with a piece of the script, or just max in general that I have no clue how to deal with. When opening a file with multiple components I want to scale and move things uniformly, keeping the relation between their pieces the same, when I use the in screen scale or translation tools, it scales or moves things while retaining component spacing, I copy the code that comes up in the listener and even pasting it back into the listener and pressing enter gives me completely different results, scaling each piece from a different point, typing or copy pasting the code has no luck for me whatsoever so I was wondering what I can do to get around this.

If anyone could be of assistance that would be excellent indeed!

1 Reply
(@rustyknight)
Joined: 10 months ago

Posts: 0

Okay, let me get this straight in my head…you “select” a group of objects and scale them – is this correct?

Shane

Have you tried the “in local coordsys” ? Do a search on Maxscript help to get some examples.

Alas, coordsys local seems to still result in the undesirable effect of each piece scaling from their own as opposed to performing like a combined object in Maya would. I’m very unfamiliar with 3DSM and I’m still learning, thank you very much for your assistance and patience but I think I’ll need a tad more help.

Just thought of something that probably isn’t the best way to do it but it seems to do the thing you want:

tSel=selection
tBox=box pos:tSel.Center length:1 width:1 height:1
tSel.parent=tBox
scale tBox [2,2,2]
delete tBox

It simply creates a box in the center of the selection parents the selection to that box and then scales the box, therefore having the same behaviour has scaling in selection center mode. Hope this helps, cya!

You’re making it even more difficult than it needs to be.

in coordsys (matrix3 [1,0,0] [0,1,0] [0,0,1] $.center) (blah blah blah,…)

EDIT: Scratch that. I screwed something up that doesn’t work…

Page 1 / 2