PDA

View Full Version : Streamlining Charts


Robert.Hall
2005-10-21, 03:42 PM
I want to make sure everyone is pulling the correct values from a chart into drawings.
I am not sure how to do this:

1. I need a text file that contains 3 values per entry
2. In AutoCad, the user is prompted for the first entry
3. AutoCad returns the other 2 values

The data would look something like this:

1.2,1.25,1.3
1.5,1.58,1.66

etc.

The user could enter 1.2 and the get the other 2 values as either dtext or
simply shown on the command line.

Mike.Perry
2005-10-21, 03:46 PM
Hi

Pick your programming language of choice...

ARX
Dot NET
LISP
VBA

I will then move this thread to the relevant "Programming (http://forums.augi.com/forumdisplay.php?f=88)" forum.

Have a good one, Mike

Robert.Hall
2005-10-24, 02:28 PM
Autolisp would be easiest for me as I am beginning to understand how it works.

Mike.Perry
2005-10-24, 04:27 PM
Autolisp would be easiest for me as I am beginning to understand how it works.Hi

Done.

Thread moved from the CAD Mgmt. General (http://forums.augi.com/forumdisplay.php?f=119) forum to this one...

Thanks, Mike

Forum Moderator

CAB2k
2005-10-24, 07:45 PM
Here is my take on your routine.

Command name? Entered at the command line to run the lisp

If the data file is not loaded load it
... Load a list with the values delimited by comma
... List would look like this (("1.2" "1.25" "1.3")("1.5" "1.58" "1.66"))
... note that you could convert to numbers but why bother?

Prompt the user & Get the target value.

Look up the target (assoc target list)

If found display it or add to drawing as text.

Simple as that :)

Is that what you had in mind?

CAB2k
2005-10-24, 08:48 PM
This is a quickie, down and dirty.
Little error checking and meant as an example to get you started.

Requires a text file in the ACAD path named MyData.txt with your data.

(defun c:lookup (/ data target)

;; global variable *lookuplist* holds the file data

;; phraser by CAB
(defun sparser (str delim / ptr lst)
(while (setq ptr (vl-string-search delim str))
(setq lst (cons (substr str 1 ptr) lst))
(setq str (substr str (+ ptr 2)))
)
(reverse (cons str lst))
)

;; TxtFile2List by CAB
(defun File2list (filename ; file name
onestr ; t = one string
case ; nil = no change
;; U = force to upper case
;; L = force to lower case
/ handle stream result
)
(if
(and
(eq 'str (type filename))
(setq filename (findfile filename))
(setq handle (open filename "r"))
)
(progn
(while (setq stream (read-line handle))
(cond
((= case "U") (setq stream (strcase stream)))
((= case "L") (setq stream (strcase stream t)))
) ; cond stmt
(if (/= (vl-string-trim " \t\n" stream) "")
(if onestr
(setq result (strcat stream (chr 13) result))
(setq result (cons stream result))
)
)
) ; while
(close handle)
) ; progn
) ; endif
(reverse result)
)

;; load the file if not loaded
;; put data into a global variable for use later
(defun load_file (/ tmplst x)
(cond
((and *lookuplist* (listp *lookuplist*)) t)
((if (setq tmplst (File2list "MyData.txt" nil nil))
(foreach x tmplst
(setq *lookuplist* (cons (sparser x ",") *lookuplist*))
)
)
)
)
)


;; Routine Starts Here
(if (load_file)
(if (setq target (getstring "\nEnter the target. "))
(if (setq data (assoc target *lookuplist*))
(print data)
(prompt "\n*** Not in list. ***")
)
)
(alert " Data File Error.")
)
(princ)
)

(prompt "\nLookUp loaded, Enter lookup to run.")
(princ)

Robert.Hall
2005-10-25, 08:07 PM
That is exactly what I need.
I want to put in 1.2 for the user input, and then get the other 2 numbers.
I tried the 2 examples you provided for data and the routine returns "not in list" no
matter which number I type in........am I doing something wrong??


I have:

(("1.2" "1.25" "1.3")
("1.5" "1.58" "1.66"))

CAB2k
2005-10-25, 08:19 PM
This is the contents of the text file

1.2,1.25,1.3
1.5,1.58,1.66

What does your look like?
Or better yet attach it for me to look at.

Robert.Hall
2005-10-26, 02:24 PM
I figured out what I was doing wrong. This is an awesome lisp routine.
I am going to use this to make sure that my users are looking up
the correct numbers for their drawings. No more errors :wink:

CAB2k
2005-10-26, 03:25 PM
Glad you got it going. :)