Author Topic: Need LISP Routine to read ASCII file and generate a 3Dpoly  (Read 13510 times)

0 Members and 1 Guest are viewing this topic.

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« on: February 19, 2005, 12:56:36 PM »
Hi I'm new to this site but used a site in the past at Cadolog.com that was simular but no longer there at least that I can see.

Looking for a Lisp Routine to read an ASCII file with a list of X,Y,Z info that I have generated from a program outside of AutoCAD.  Then need the lisp routine to put that info into a 3Dpoly.

I'm currently using AutoCAD 2000 or 2002 (which I think matters with Lisp)

So for some sample data:
6421.40,1356.00,36.00
6570.60,1347.60,49.00
6771.80,1348.00,49.00
7081.90,1321.20,43.00
7138.80,1367.00,22.00
7226.20,1354.70,21.00
7298.50,1344.80,21.00
7346.10,1319.60,25.00
7454.90,1294.00,30.00

So to recap
1) Have a lisp routine ask for the ASCII file from the user (or browse would be a PLUS)
2) Then have the lisp routine add a 3Dpolyline into the drawing.

That should do it, any help would be great!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #1 on: February 19, 2005, 01:02:56 PM »
Have you searched around already?

Google: Import ASCII ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Carl

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #2 on: February 19, 2005, 01:43:35 PM »
You can do this without lisp-
Start the 3d poly command, select and copy the coordinates, paste them into AutoCAD's command line.

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #3 on: February 19, 2005, 01:51:30 PM »
Quote from: Carl
You can do this without lisp-
Start the 3d poly command, select and copy the coordinates, paste them into AutoCAD's command line.


Where's the fun in that?  :P

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #4 on: February 19, 2005, 02:07:58 PM »
I'm doing that now - copy/paste - but its very time consuming.  I just thought someone could direct me to some lisp routine that can read files or show me how to do this.  It should be very simple to do, but I'm not a Lisp routine export and wouldn't know the first thing about it.  I'm willing to learn it - but right now I got too much stuff on my plate to get into Lisp right now.  Thanks

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #5 on: February 19, 2005, 02:24:36 PM »
From this post:
Quote
Just a note to the new-comers about this forum that is vastly different from most. This place, TheSwamp, is a fishing school, generally, it will teach you how to fish. Often, they will help you land a fish you've already hooked and occasionally they will even offer a piece of fish to get you over a rough spot. Then every now and again, someone will give you a fish.


That being said, it's generally considered poor form to just pop in and ask for code. Not that you won't get what you're after, I think all of us have been in a pinch and needed a 'quick fix' before.

So, having said that, how desperate are you? Are you willing to learn to write the code (catch the fish) to do what you are trying to do or are you just looking for some free fish?

From what I gather, you are already doing what you need to do, you are just having to go about it in a fashion that seems overly complicated. And, being the smart person that you are, you realise that you can probably simplify this task using Lisp.

That would be a correct assumption.

But are you willing to learn to do it yourself?

If you are, I can promise you that there are plenty of us who would be willing to teach you.

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #6 on: February 19, 2005, 03:27:08 PM »
Thanks nivuahc for your comments.  I would like to learn how to write the code for this lisp routine that I need.  So where do I start?  

I'm sorry for being so foward - sometimes I can be strait to the point on things - I appologies to all that I may have affended coming to a site and asking for code.  

Regards,

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #7 on: February 19, 2005, 03:36:24 PM »
Actually, Garth, I doubt anyone was offended. I've seen new people demand code. Then they would get upset that no one wanted to give it to them.

Where to start...

Why don't you tell us how much you already know about writing Lisp (or any other language) and we can better answer that question.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #8 on: February 19, 2005, 03:38:10 PM »
No apologies necessary grdruck.

I apologize if my response seemed brusque, I didn't realize you wanted to learn how to write your own utility.

<adjusting scorecard ...>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #9 on: February 19, 2005, 03:47:18 PM »
well - I have an assoicated degree in programming and but have not used programming for quite some time.  

In the past (10+ years ago) I used to program in Basic, Cobol, Dataflex (a relational database package like MicroSoft Access) and more resent to that did some Website design.  

So I think I have the back ground for it.

Regards,

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #10 on: February 19, 2005, 03:58:32 PM »
This thread from this forum should be a great place for you to start. Some of it might be below your current level (i.e. what variables, arguments, etc... are) but if you have no Lisp experience that should be a great place to start.

It's something like 23 pages long so it's a lot of reading but the person who started the thread had no experience in Lisp and, by the end of it all, was able to write the exact code he needed and was considering starting some more projects.

You might even be able to skim over quite a bit of it, having some programming experience, but there is a plethora of usefull information in there. I'd read it all.

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #11 on: February 19, 2005, 04:32:43 PM »
ok - I'll read it - in the mean time from the first post of the Lisp routine I'd like to create can you at least give me the commands that I would need? (I'm not looking for a "fish" as you say, but some commands that I can look up in an old Lisp book I have so I could get started.  Commands like in basic language: IF then else.  

There's a getstring function - do I need this?
what about the read-line function or read function to read a file for user input.

I know I need to use the 3Dploy command some where in the code.

Regards,

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #12 on: February 19, 2005, 05:03:40 PM »
My advice, in that regard, is to do what I did when I (and many others) started learning Lisp.

Find a routine that almost does what you want (there are plenty out there) and play with it. Try things out, see what happens.

If you write (or at some time wrote) BASIC, then Lisp should be very familiar to you.



The first thing you'll want to do in your routine is define the function using

defun

Ahhhhhh... but how does it work?

What are it's options?

for starters, if you define your function like this

Code: [Select]
(defun c:function_name....

it can be run from the command-line by typeing function_name followed by the Enter key.

If you define it thus

Code: [Select]
(defun function_name...

It is run in this fashion:

(function_name)

And that is just the tip of the iceberg :)




If... If... If I had a fish...

If statements, at their simplest, are setup like this

Code: [Select]
(if (some_comparison)
   (if_comparison_is_true_do_this)
   (if_comparison_is_NOT_true_do_this_instead)
)


Just a little more complex, they can be defined like this

Code: [Select]
(if (some_comparison)
   (progn
   (if_comparison_is_true_do_this_first)
   (do_this_next)
   (then_do_this)
   )
   (progn
   (if_comparison_is_NOT_true_do_this_instead)
   (do_this_next)
   (then_do_this)
   )
)


And don't get even me started on COND!  :shock:




Variables

Variables are defined using setq.

Code: [Select]
(setq variable_name (something_to_set_it_to))

It's not necessary to define your variables first, as in some other languages. Variables can be created and declared all at one time at any time in the program.



Comments

Comments, in Lisp, are anything following a semicolon (;) on a single line of code. They do not continue to the next line of code, like in C so the following code demonstrates the right and wrong way to use comments

Code: [Select]
(defun c:my_routine ()
   ; This is my routine. It will do wonderful things.
   ; Like curing cancer and whatnot
   Okay, maybe not cancer... but the common cold at least.
)


The above would result in an error becase the third line "Okay, maybe not cancer... but the common cold at least." is not preceded by a semicolon (;) and 'Okay' isn't a valid command. ;)


How's that for starters?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #13 on: February 19, 2005, 05:17:48 PM »
If I might offer a bit of advice....since you obviously have some background in programming then you would be familiar with outlining your project in pseudo code.... but just in case, I'll get you started ...

pseudo code
Code: [Select]

prompt for file to read
open file
loop
read line
output line to 3DPoly
when no more lines to input break loop
loop
close file
end 3DPoly command


Now lets examine the ways to do this ...

To define a function use either:
defun
defun-q


To select a file you can use either:
getfiled
getstring
findfile


To open a file use:
open

To read a file use either:
read-line
read-char


To close a file use
close

To loop use either:
while
repeat


Now, I'll give you your first assignment to look up these lisp commands in your AutoCAD help files (use the VisualLisp IDE to easily put together code)

Once you find out what these commands are, then I want you to post an example of using each of them .. a simple short snippet will do fine ... no full functions ... just something showing you understand the syntax.

Please keep us informed of your progress...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #14 on: February 19, 2005, 05:38:32 PM »
Thank you for that help - I'll keep you posted on my progress.  Thanks again.

Also, is there a recommened Lisp Book out there that you think highly of?

There is one question about a 3Dpoly - can you join two together like you can with a polyline?

Regards,

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #15 on: February 19, 2005, 06:15:42 PM »
I can't recommend a book, but Stig Madsen and Kenny Ramage have some excellent web articles / tutorials:

www.SMadsen.com
www.AfraLISP.com


3Dpolys cannot be joined using the vanilla product, but a roll-yer-own utility could emulate that.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Carl

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #16 on: February 19, 2005, 07:07:58 PM »
Not to dissuade you from pursuing writing a routine, but....
Quote
I'm doing that now - copy/paste - but its very time consuming.


If you have a file of coordinates, or a column of coordinates in Excel, you need only *one* copy and paste of all the coordinates....were you doing it this way?

Anonymous

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #17 on: February 19, 2005, 08:23:04 PM »
Carl - No I was doing it one at a time - never thought of taking a list of them from excel and putting them into AutoCAD - thanks for the tip.

Not to worry - I will still work on making that Lisp routine that started this whole discusion.

Thanks again,

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #18 on: February 21, 2005, 12:07:21 AM »
Hi all - here is what I have so far.  I found a Lisp routine that reads a file so I copied it (hope thats not Plagiarism) and cut out the lines that did not pertain to what I was trying to do.

So here we go... (drum roll please...)
Code: [Select]

;   My3Dpoly.LSP
;   Written by Garth Druckenmiller on February 20, 2005
;      with help from various sources.  

(defun C:MY3DPOLY ()

(Prompt "\nMY3DPOLY - Draws a 3Dpolyline by reading input from coordinates file")

(Setq FILENAME (getstring "\nName of coordinate file to input : "))

(Setq FILEUNIT (open FILENAME "r"))

(setq OLD_CMDECHO (getvar "CMDECHO"))
(setvar "CMDECHO" 0)

(setq COUNTER 1)

(While (setq LINE_INPUT (read-line FILEUNIT))

(prompt (strcat "\rProcessing line number : " (itoa COUNTER)))

(setq PT LINE_INPUT)

(command ".3DPOLY" PT "")

(setq COUNTER (1+ COUNTER))
)

(close FILEUNIT)

(setvar "CMDECHO" OLD_CMDECHO)

(prompt " Program complete.")
(princ)
)

sample data...

5713.10,1208.40,40.00
5762.70,1260.90,40.00
5766.40,1262.10,45.00
5934.50,1316.80,45.00
5989.00,1325.10,47.00
6279.70,1365.90,49.00
6284.80,1366.30,36.00
6421.40,1356.00,36.00
6570.60,1347.60,49.00
6771.80,1348.00,49.00
7081.90,1321.20,43.00
7138.80,1367.00,22.00
7226.20,1354.70,21.00
7298.50,1344.80,21.00
7346.10,1319.60,25.00
7454.90,1294.00,30.00


It runs but I don't see anything in AutoCAD.  My thinking is that is has something to do with the 3DPOLY command - I have an old AutoLISP book and that command is not in it - Can someone tell me the sintex of that command.  Thanks,

Talk with you guys soon,

Fuccaro

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #19 on: February 21, 2005, 01:37:56 AM »
Grdruck

You have the coords in a text file. It should be simple to transform it in a script file.

SMadsen

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #20 on: February 21, 2005, 04:16:55 AM »
The code you picked is very well demonstrating the overall technique of reading a text file in AutoLISP. It asks for a filename, opens the file, enters a loop while reading lines and closes the files. That's pretty much the way to do it. As you correctly suspect, the problem is with the use of COMMAND.

The "syntax" of any native AutoCAD command when executed via the COMMAND function corresponds to the sequence of execution in AutoCAD. With that in mind, what does the COMMAND function inside the loop do? If you're not aware of it already, an empty string passed to COMMAND acts as Enter/Return. So the command will initiate 3DPOLY, give it a point and return to the command line, i.e. finish the command. It does this for each line - or each point - in your file, which means that it'll create tiny zero length 3DPOLY's all over your drawing.

The trick is to call 3DPOLY one time, pass it points while the command is still active and terminate the command after you run out of lines to read (i.e. points):
Code: [Select]
...
;; start 3DPOLY command (as you would in AutoCAD)
  (command ".3DPOLY")
  (While (setq LINE_INPUT (read-line FILEUNIT))
    (setq PT LINE_INPUT)
    ;; pass the active command a point (as you would in AutoCAD)
    (command PT)
  )
  ;; finish the command (as you would in AutoCAD)
  (command "")
...


Try incorporate this piece in the code. After you got it working, we can maybe hint at some other improvements.

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #21 on: February 21, 2005, 10:50:00 AM »
Thanks

Fuccaro
Not sure what a script is except a list of item one after another - in all my years doing drawings with AutoCAD I never used one - I should look into this - where could I find it

SMadsen
Thanks for your advice - Last night when I went to bed I thought I should break that line up (ie: command ".3DPOLY" PT "") but didn't know how to do that - since I very new to this programming LISP

Yes I have a file called MY3DPOLYDATA.DAT that I created with a text editor

I added your suggestions into my routine and it works!  But it exicutes very, very slowly.  It maybe my computer.

This is what I have now...

(defun C:MY3DPOLY ()

   (Prompt "\nMY3DPOLY - Draws a 3Dpolyline by reading input from coordinates file")

   (Setq FILENAME 3(getstring "\nName of coordinate file to input : "))

   (Setq FILEUNIT (open FILENAME "r"))

   (setq OLD_CMDECHO (getvar "CMDECHO"))
   (setvar "CMDECHO" 0)

   (setq COUNTER 1)

   ;; start 3DPOLY command (as you would in AutoCAD)
   (command ".3DPOLY")

   (While (setq LINE_INPUT (read-line FILEUNIT))

      (prompt (strcat "\rProcessing line number : " (itoa COUNTER)))

      (setq PT LINE_INPUT)
      
      ;; pass the active command a point (as you would in AutoCAD)
      (command PT)

      (setq COUNTER (1+ COUNTER))
   )

   ;; finish the command (as you would in AutoCAD)
   (command " ")

   (close FILEUNIT)

   (setvar "CMDECHO" OLD_CMDECHO)

   (prompt " Program complete.")
   (princ)
)

Why would it exitcute so slow?  any suggestions on that

Also, when it stoped I got the error message:

Point or option keyword required.
; error: Function cancelled

this was displayed after no more records in file.

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #22 on: February 21, 2005, 11:00:48 AM »
I ran it with the debuger on - after turning it off it works quickly - except for the error and also the (command "") is not ending the command bc It still looking for a point or <return> character - how do you type a return character into the above code?

Thanks

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #23 on: February 21, 2005, 11:20:41 AM »
Not an answer to your question but, you might want to turn your osnaps off before running that.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #24 on: February 21, 2005, 11:26:30 AM »
The "" -thingie is not a space but an empty string. Just type two double quotes as close as if they were trying to make single quotes.

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #25 on: February 21, 2005, 11:27:15 AM »
Isn't it great when people catch on so quickly?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #26 on: February 21, 2005, 11:55:26 AM »
Where you have
Code: [Select]

(command " ")


change it to
Code: [Select]

(command "")


FYI if you paste your code into a code window using the BBCode tags, it will differentiate it a little better and make it easier to read.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #27 on: February 21, 2005, 12:01:09 PM »
You could do something like this to break the plines.
Look into the getfile function, you may want to use it.

Code: [Select]
(defun c:my3dpoly ()

  (prompt
    "\nMY3DPOLY - Draws a 3Dpolyline by reading input from coordinates file"
  )

  (setq filename 3
        (getstring T "\nName of coordinate file to input : ")
  ) ; T added to allow spaces in file name, CHR 32
  ;;  need to check for a valid file name or loop using findfile

  (setq fileunit (open filename "r"))

  (setq old_cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  (setq counter 1) ; vertix counter

  ;; start 3DPOLY command (as you would in AutoCAD)
  (command ".3DPOLY")
  ;;  read the text file & create a pline
  (while (setq line_input (read-line fileunit))
    (prompt (strcat "\rProcessing line number : " (itoa counter)))
    (setq pt line_input)
    (if (= pt "") ; blank line, so break pline
      (progn
        (command "") ; end current pline
        (command ".3DPOLY") ; start another pline
      )
      (command pt)
    )
    (setq counter (1+ counter))
  )

  ;; finish the command (as you would in AutoCAD)
  (command "")

  (close fileunit)

  (setvar "CMDECHO" old_cmdecho)

  (prompt " Program complete.")
  (princ)
)


Quote
5713.10,1208.40,40.00
5762.70,1260.90,40.00
5766.40,1262.10,45.00
5934.50,1316.80,45.00  ; creates a gap in the line

5989.00,1325.10,47.00
6279.70,1365.90,49.00
6284.80,1366.30,36.00
6421.40,1356.00,36.00
6570.60,1347.60,49.00

6570.60,1347.60,49.00  ; same point as above so break pline but no gap
6771.80,1348.00,49.00
7081.90,1321.20,43.00
7138.80,1367.00,22.00
7226.20,1354.70,21.00
7298.50,1344.80,21.00
7346.10,1319.60,25.00
7454.90,1294.00,30.00
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

t-bear

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #28 on: February 21, 2005, 04:08:11 PM »
Garth......

I told you!!! :lol:  :wink:  :lol:

Peter Jamtgaard

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #29 on: February 21, 2005, 05:47:45 PM »
:roll:

Hey swamp...

I was just reviewing a few posts and stumbed onto this thread. I noticed some code that was creating a 3dpoly from an ascii text file. I was just playing around and came up with this routine. It includes a couple useful routines that you all might enjoy reviewing.

Bon apetite.

Peter Jamtgaard

Code: [Select]

; Create a 3dpolyline in the active viewport
; From a specified CSV file using activeX
; Syntax (asciipoly "mycsvfile.csv") for example


(defun ASCIIPOLY (strCSVFileName / lstCoordinates lstVertices)
 (setq lstVertices (csvfiletolist (findfile strCSVFileName) ","))
 (foreach lstPoint (reverse lstVertices)
  (foreach sngCoord (reverse lstPoint)
   (setq lstCoordinates (cons sngCoord lstCoordinates))
  )
 )
 (vla-add3dpoly
  (vla-get-block
   (vla-get-activelayout
    (vla-get-activedocument
     (vlax-get-acad-object)
    )
   )
  )
  (listToSafeArray 5 lstCoordinates); the #5 specifies a real number
 )
)

; Convert a csv file to a list
; Syntax (csvfiletolist "mycsvfilename.csv" ",")
; The comma being the delimiter

(defun csvFiletoList (strFilename strChar / lstOfSublists strText z)
 (setq z (open strFilename "r"))
 (while (setq strText (read-line z))
  (setq lstOfSublists (cons (CSVStringToList strText strChar)
                                     lstOfSublists)))
 (close z)
 (reverse lstOfSublists)
)

; Convert a list into a safearray

(defun ListToSafearray (symVariableType lstValues / safValues)
 (setq safValues (vlax-make-safearray symVariableType
                                                        (cons 0 (1- (length lstValues)))))
 (vlax-safearray-fill safValues lstValues)
)


; Safearray types for your reference

;vlax-vbInteger  (2)  Integer
;vlax-vbLong     (3)  Long integer
;vlax-vbSingle   (4)  Single-precision floating-point number
;vlax-vbDouble   (5)  Double-precision floating-point number
;vlax-vbString   (8)  String
;vlax-vbObject   (9)  Object
;vlax-vbBoolean (11)  Boolean
;vlax-vbVariant (12)  Variant



Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #30 on: February 21, 2005, 05:52:28 PM »
Quote from: Peter Jamtgaard
It includes a couple useful routines that you all might enjoy reviewing.

Or even storing in the local library. :blink:

Good stuff Peter, thanks a bunch.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #31 on: February 21, 2005, 05:55:31 PM »
Wow there Peter .. poor grdruck is trying his best  :wink:

Good to see you, though. Hope things are great.

grdruck

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #32 on: February 23, 2005, 03:01:58 AM »
Hello and thanks for helping me out.  I'm kinda liking this LISP stuff!!  :D

I added a few more things to it and looking at some other code from CAB to in corporate into it.

Take a look and see what you think.  Also, I like to set a static path so I don't have to keep searching for the directory that I placed the ".txt" files to read.  Secondly, is there a way to turn off the OSNAP's (I thought it would be (Setvar "OSNAP" 0) but its not working)

Code: [Select]
;;   My3Dpoly.LSP
;; Written by Garth Druckenmiller on February 20, 2005
;;       Updated on 02/23/2005 - read multiple coordinate files.
;;      
;;     with help from various sources.   Thanks to those on TheSwamp.org

(defun C:MY3DPOLY ()

  (Prompt "\nMY3DPOLY - Draws a 3Dpolyline by reading input from coordinates file(s)")
  (Prompt "\n")

  (setq OLD_CMDECHO (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  (setq FILENAME "")

  (while (Setq FILENAME (getfiled "Select the coordiate file to input : " FILENAME "txt" 128))
    (Setq FILEUNIT (open FILENAME "r"))

    (command ".3DPOLY")

    ;; process file
    (While (setq LINE_INPUT (read-line FILEUNIT))
      (setq PT LINE_INPUT)
      (command PT)
    )

    (command "")

    (close FILEUNIT)
  )

    (setvar "CMDECHO" OLD_CMDECHO)

    (prompt "\nProgram complete.")
    (princ)
)



All look at your code Peter at some point - its a little over my head at this point, but thanks for sharing.

Thanks again for all your help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #33 on: February 23, 2005, 08:44:11 AM »
I think Se7en may be the author f this code
Code: [Select]
;;;===================================================================;
;;; SetOsnaps                                                         ;
;;;-------------------------------------------------------------------;
;;; This function accepts a integer of 1 or 0 (on or off) to set the  ;
;;; end users osnap value to enabled or disabled.                     ;
;;;                                                                   ;
;;; Argument: 1 = Enable the users osnaps                             ;
;;;           0 = Disable the users osnaps                            ;
;;;                                                                   ;
;;; Usage: (SetOsnap 1) or (SetOsnap 0)                               ;
;;;                                                                   ;
;;;===================================================================;
(defun SetOsnaps (value / osm)
  (setq osm (getvar "OSMODE"))
  (if (or (and (= value 1) (> osm 16383))
          (and (= value 0) (<= osm 16383))
      )
    (setvar "osmode" (boole 6 (getvar "osmode") 16384))
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #34 on: February 23, 2005, 08:57:56 AM »
But the setvar should work for you. I use it when the user has no input as with your routine.
try this:

 
Code: [Select]
(defun c:my3dpoly (/ useros old_cmdecho filename line_input fileunit pt)
  (setq useros (getvar "osmode"))
  (setvar "osmode" 0)
  (setq old_cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  (prompt
    "\nMY3DPOLY - Draws a 3Dpolyline by reading input from coordinates file(s)"
  )
  (prompt "\n")

  (setq filename "")

  (while (setq filename (getfiled "Select the coordiate file to input : " filename "txt" 128))
    (setq fileunit (open filename "r"))

    (command ".3DPOLY")

    ;; process file
    (while (setq line_input (read-line fileunit))
      (setq pt line_input)
      (command pt)
    )

    (command "")

    (close fileunit)
  )

  (setvar "CMDECHO" old_cmdecho)
  (setvar "osmode" useros)

  (prompt "\nProgram complete.")
  (princ)
)
(prompt "\nMy3dPoly loaded, enter My3dPoly to run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nivuahc

  • Guest
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #35 on: February 23, 2005, 10:10:49 AM »
OSNAP != OSMODE

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Need LISP Routine to read ASCII file and generate a 3Dpoly
« Reply #36 on: February 23, 2005, 10:23:48 AM »
Quote from: nivuahc
OSNAP != OSMODE

Good catch!
I need  that second cup of coffee.
Wrong word (Setvar "OSNAP" 0)
should be (Setvar "OSMODE" 0)
I've typed that myself a time or two. 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.