Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help required on AutoLISP 1

Status
Not open for further replies.

rakes

Aerospace
Jul 6, 2001
25
0
0
IN
I am writing an AutoLISP program to read a text file and write the whole text on to AutoCAD graphics screen exactly as it would've appeared in the text file. Here is the code: (setq f1 (open f_name "r"))
(setq str 1)
(setq block (read-line f1))

(while (/= str nil)
(setq str (read-line f1))
(if (/= str nil)
(setq block (strcat block str (chr 10)))
(princ)
)
)
(command "text" pause 10 0 block)

(close f1)
(princ)
But the text command does not print it the way it appears in the text file. Instead, it offsets each line. Can anybody tell what's wrong with my code?
 
Replies continue below

Recommended for you

It looks like the "newline" character (chr 10) causes printing to drop down a line from the end of the print string and not go back to the beginning of the line. One approach would be to have the "text" command inside the loop so it prints each file line as it is read. You can have the new staring point calculated and passed to the "text" command, or have the text command issue a return to drop down a line. First time through the text command is as you have it, other times use: (command "text" "" 10 0 str).

Good luck,
Carl
 
Sure, you are appending a single new-line character (chr 10)without the carriage return (chr 13), so, if you wish to put the entire contents of the file into a single element such as BLOCK, you would need to append a newline character "\n" to the string at each new line. I would suggest to do each line of the file separately though, since the text command does not fully support creating paragraphs. It would be much simpler to use:

(defun c:asctext ()
(setq a (getfiled "Select File" "" "txt;lsp" 8))
(if a
(if (setq fn (open a "r"))
(progn
(setq ip (getpoint "\nStart point: "))
(setvar "texteval" 1)
(setq val (read-line fn))
(command "._text" ip "0" val)
(while (setq val (read-line fn))
(command "._text" "" val)
)
(close fn)
)
(alert "File cannot be opened")
)
)
)

Just try this command on any text file, making sure you have a text style already defined.

Cheers.....
 
Thanks for the help, guys. Striker's routine was able to do the job better indeed. But tell me, what's the difference between a simple "text" command and a "._text".

Thanks once again to CarlB & Striker for the help.

rakes
 
There is absolutely no difference in the final product when calling any internal function from lisp via the COMMAND function call, however, people can get pretty creative in customizing these internal commands by undefining the original and redefining a new one to take it's place. So... when this happens (and it happens more than you think), Autodesk provided a means to call the internal function simply by adding a period prefix to the command and circumvent the redefined command, since you cannot know all of the particulars about the redefined command ahead of time (and to make it portable to other systems where the command has not been redefined). Now, when you have other versions of Autodesk products installed, (or other than the native language version installed) there are differences in the command line call, i.e. If you are prompted in a German language version the mnemonics and command call would be in German not English. To fix this obvious problem when making command calls across multi-language installations, Autodesk, in their infinite wisdom, provided a means to call the native language version by adding the underscore as a prefix. So what we have is a very long explanation as to why you should always use _.xxxxx as your command call instead of xxxxx. You could just as well use ._xxxxx or _xxxxx or .xxxxx, but for each call, you will have the results based on which internal version of the function you have called. Whew........


Have a nice day.....
 
To any autoCADders... I'm trying to figure out the function that will let me do what I want to, and THAT is:
6 different viewports on the same layoutare showing different areas of a floor plan containing different colours of dense hatching. In order to dodge duplicating the model and making the file size huge, I'm trying to set up certain hatches shown through certain viewports... i don't know if its possible.... and I don't know how well I explained it.
please help.
-work guy
 
I am not sure I understand the qouestion, but here goes. You have a floor plan with multiple hatches, however, you want to view each hatch independently in its own viewport. Well, you could do a few different things, but none of them are very good solutions. It really depends on what version of Acad you have. If you have ADT, then you can apply a hatch and have it visible on several different layers when attached to an ADT object. This way you could toggle the layer visibility in each viewport, and have the colors defined by the object. The hatch would then act as a single hatched object with only a minor increase in drawing overhead required. You could also define a custom viewport in the shape of the hatch you want to show, then apply that viewport in the correct location, have a single hatch for each color, then view the hatch in the hatch viewport. This would require less drawing overhead but maintaining it would be more difficult, particularly if you were not plotting the hatch in color.
 
Status
Not open for further replies.
Back
Top