# Thread: Put 2 and 2 together

1. ## Put 2 and 2 together

Registered forum members do not see this ad.

I've been racking my brain all day - and now I think the Americans are waking up, so I mind as well as a Q!

I have done my very first LISP today (woohoo) to get AutoCAD 2006 to list coordinates on a polyline. And I have also got a LISP that inserts a line into each point I give it - now: How do I combine the two? That is to insert a line on each point of the polyline?

To make it clearer, here is what I've got:

Code:
```(defun c:coord (/ e len n e1)
(setq e (entget (car (entsel))))
;get the entity list
(setq len (length e))
;get the length of the list
(setq n 0)
;set counter to zero
(repeat len
;repeat for the length of the entity list
(setq e1 (car (nth n e)))
;get each item in the entity list
;and strip the entity code number
(if (= e1 10)
;check for code 10 (vertex)
(progn
;if it's group 10 do the following
(terpri)
;new line
(princ (cdr (nth n e)))
;print the co-ordinates

);progn
);if
(setq n (1+ n))
;increment the counter
);repeat
(princ)
);defun
(princ)

(defun c:lines ()
;input
(setq k1 (getpoint "\nPunkt 1: "))
(setq k2 (getpoint "\nPunkt 2: "))
(setq k3 (getpoint "\nPunkt 3: "))
(setq k4 (getpoint "\nPunkt 4: "))

;polarpunkter
(setq j1 (polar k1 (dtr 90) 50))

(setq j2 (polar k2 (dtr 90) 50))
(setq j3 (polar k3 (dtr 90) 50))
(setq j4 (polar k4 (dtr 90) 50))

;line
(command "Line" k1 j1 ""
"Line" k2 j2 ""
"Line" k3 j3 ""
"Line" k4 j4 ""
)

(princ)
)
(defun dtr (x)
(* pi (/ x 180.0))
)```

2. You just want to draw a line at each vertex? Then just need a little modification of first routine:

Change:
(princ (cdr (nth n e)))

to:

(setq pt (cdr (nth n e)))
(princ pt)
(setq j2 (polar pt (dtr 90) 50))
(command "Line" pt j2 "")

And, include the 'dtr' defun with the first routine.

3. To get coordinates of lightweightpolyline you can use this code:
Code:
```(defun lwpline-get-coord (ent)
(if (= (type ent) 'vla-object)
(setq ent (vlax-vla-object->ename ent))
) ;_ end of if
(if (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
(vl-remove-if '(lambda (x) (/= (car x) 10)) (entget ent))
) ;_ end of if
) ;_ end of defun```
Call parameters: ent - entity pointer (ename type)
Call samples:
Code:
`(lwpline-get-coord (car (entsel)))`
Something else: when you're drawing entities through (command) interface, set osmode to 0 before drawing. After drawing do not forget to restore it

4. With a vla-object, you can use

Code:
`(vlax-get ent 'coordinates)`
@+

5. > Patrick_35 : And you'll get a variant which should be converted to array of doubles and atfer that convert it to list of points (2d or 3d). in case of lightweight polyline there is more simple to use (entget) functions.

6. Simpler, I don't know.
Sourer with the code dxf 10, yes. But it's especially por to avoid tranformer a vla object

For a array of doubles
Code:
```(setq xy (vlax-get ent 'coordinates))
(while xy
(setq lst (append lst (list (list (car xy) (cadr xy))))
)```
@+

7. (vlax-get) is undocumented method and it supporting could be stopped in next versions of AutoCAD (AFAIK). 'Cos of this i prefer not to use it (and vlax-put method also).

8. Registered forum members do not see this ad.

Perhaps, it functions since the version 2000

@+

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts