Lisp: Select a line so it spits out the length??

Status
Not open for further replies.

abevlad

Usenet Archive
Joined
Aug 20, 2001
Messages
37
Reaction score
0
How do I write a simple lisp that allows me to make a single selection of a line, then have it sets the length of the line to a variable (setq x..
 
(while (not (setq obj (entsel "\nPick a line: "))))
(setq ent (entget (car obj)))
(if (= (cdr (assoc 0 ent)) "LINE")
(progn
(setq x (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent)))) (alert (strcat "Length = " (rtos x))) ) ;; progn (alert "Object is not a LINE.") ) ;; if ___

"abevlad" wrote:

How do I write a simple lisp that allows me to make a single selection of
a
line, then have it sets the length of the line to a variable (setq x..
 
If you already have set a length to a variable, say 'linelength', you can change the line length with the following:

(command "._lengthen" "_T" linelength pause "")

It will pause for a single selection, and will work on a line, polyline and arc.

Carl

"abevlad" wrote:
How do I write a simple lisp that allows me to make a single selection of a line, then have it sets the length of the line to a variable (setq x..
 
???
What's that got with assigning the length of an existing line to a variable?
___

"CarlB" wrote:

If you already have set a length to a variable, say 'linelength', you can change the line length with the following:

(command "._lengthen" "_T" linelength pause "")

It will pause for a single selection, and will work on a line, polyline and arc.

Carl

"abevlad" wrote:
...
> How do I write a simple lisp that allows me to make a single selection
of a
> line, then have it sets the length of the line to a variable (setq x..
 
On Wed, 16 Jan 2002 18:06:31 -0800, "Paul Turvill"
wrote:

???
What's that got with assigning the length of an existing line to a variable?
___

I see two interpretations of the request, the first being for a program that changes the length of the selected entity to the value of a variable set by user input. The second being selecting a line and assigning the value of its length to a variable.

"CarlB" wrote:

> If you already have set a length to a variable, say 'linelength', you
> can change the line length with the following:
>
> (command "._lengthen" "_T" linelength pause "")
>
> It will pause for a single selection, and will work on a line,
> polyline and arc.
>
> Carl
>
...
 
That's a bit of a stretch, the way I understand English grammar, but ... ok, I can see how it might be interpreted that way.

Anyway, here's yet another case where the original poster seems to have abandoned us, leaving us all guessing what he was looking for, and wondering if he ever found it ...
___

"William Wingstedt" wrote:

On Wed, 16 Jan 2002 18:06:31 -0800, "Paul Turvill"

I see two interpretations of the request, the first being for a program that changes the length of the selected entity to the value of a variable set by user input. The second being selecting a line and assigning the value of its length to a variable.
 
"abevlad" wrote:
How do I write a simple lisp that allows me to make a single selection of a line, then have it sets the length of the line to a variable (setq x..

(setq
lineSel (entget (car (entsel "\nSelect Line\n")))
pt1 (cdr (assoc 10 ll))
pt2 (cdr (assoc 11 ll))
linlen (distance pt1 pt2)
)

HTH -Mark
 
... so now we've been full circle.
___

"Mark Thomas" wrote:

"abevlad" wrote:
...
> How do I write a simple lisp that allows me to make a single selection
of a
> line, then have it sets the length of the line to a variable (setq x..

(setq
lineSel (entget (car (entsel "\nSelect Line\n")))
pt1 (cdr (assoc 10 ll))
pt2 (cdr (assoc 11 ll))
linlen (distance pt1 pt2)
)

HTH -Mark
 
If you don't mind, could you give me the "bottom line" and post the entire code for this lisp. I could find a lisp like this very useful but I got lost in the post and could not put it together myself (i'm still learning lisp).

Thanks.
 
(defun C:HOWLONG (/ obj ent x)
(while (not (setq obj (entsel "\nPick a line: ")))) (setq ent (entget (car obj))) (if (= (cdr (assoc 0 ent)) "LINE") (progn (setq x (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent)))) (alert (strcat "Length = " (rtos x))) ) ;; progn (alert "Object is not a LINE.") ) ;; if (princ) ) ;; defun ___

"cuzinlarry" wrote:

If you don't mind, could you give me the "bottom line" and post the entire
code
for this lisp. I could find a lisp like this very useful but I got lost
in the
post and could not put it together myself (i'm still learning lisp).
 
Can you explain what is the purpose of this line and
and what exactly does it do.
;CAR returns the first element of a list

(setq ent (entget (car obj)))

"Paul Turvill" wrote:

(while (not (setq obj (entsel "\nPick a line: "))))
(setq ent (entget (car obj)))
(if (= (cdr (assoc 0 ent)) "LINE")
(progn
(setq x (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent)))) (alert (strcat "Length = " (rtos x))) ) ;; progn (alert "Object is not a LINE.") ) ;; if ___

"abevlad" wrote:
...
of
a
> line, then have it sets the length of the line to a variable (setq x..
 
This assigns the entity data list to the symbol ent; (entget) gets the list for the entity name, which extracted from 'obj' by (car obj). The symbol obj contains a list consisting of the entity name, and the pick point provided by (entsel) in the line above.

Might I suggest that you explore the documentation on AutoLISP? You could then look up the purpose and syntax of each function on your own -- it's a very good way to learn LISP. In AutoCAD R14 and earlier, LISP functions are detailed in the Customization Guide (part of the HELP system, if you don't have hardcopy docs; and in 2000 and later, there's a PDF document in the HELP subfolder called AlispRef.pdf, which contains detailed information on all AutoLISP and Visual LISP functions.
___

"abevlad" wrote:

Can you explain what is the purpose of this line and
and what exactly does it do.
;CAR returns the first element of a list

> (setq ent (entget (car obj)))
 
Status
Not open for further replies.

Latest threads

Back
Top