TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on April 28, 2017, 12:14:36 PM

Title: Make (entlast) work like (entsel)
Post by: GDF on April 28, 2017, 12:14:36 PM
How to make (entget) work like (entsel). I do not want to select the object "line"; but use the last object "line" drawn.

For example:
(setq ent (entget (entlast)))
(list (entnext)  '(x y z))
Where '(x y z) is the (assoc 10 (entget (entlast)))

Will this example  work in place of (entsel)?

Thanks for a direction...
Title: Re: Make (entlast) work like (entsel)
Post by: Lee Mac on April 28, 2017, 12:30:58 PM
The following will return the entity name of the last LINE added to the drawing database:
Code - Auto/Visual Lisp: [Select]
  1. (defun lastline ( / s )
  2.     (if (setq s (ssget "_X" '((0 . "LINE")))) (ssname s 0))
  3. )
Title: Re: Make (entlast) work like (entsel)
Post by: GDF on April 28, 2017, 01:04:20 PM
Thanks Lee

(lastline) is the same as (entlast)
I'm looking for the :?


 
Code: [Select]
(defun C:Walls  ()
  (setq pt1 (getpoint "\n* Pick beginning point *"))
  (setq pt2 (getpoint pt1 "\n* Pick the end point *"))
  (command "line" pt1 pt2 "")
  (entget (entlast))
  (setq wallline       ;;(entsel "\n* Select Line to offset...")
        firstendpnt  (trans (cdr (assoc 10 (entget (car wallline)))) 0 1)
        secondendpnt (trans (cdr (assoc 11 (entget (car wallline)))) 0 1)
        pnt2         (getpoint "\n* Specify Offset Directiont --> ")
        ang1         (angle firstendpnt secondendpnt)) 
  (if (and (> ang1 (/ pi 2.0)) (<= ang1 (* pi 1.5)))
    (setq ang1 (+ ang1 pi))) 
  (command "offset" "3.5" wallline pnt2 "")
  (command "change" "l" "" "p" "la" "A-WALL-FULL" "")
  (command "offset" "9.0" wallline pnt2 "")
  (command "change" "l" "" "p" "la" "A-WALL-EXT" "")
   (princ))
Title: Re: Make (entlast) work like (entsel)
Post by: Lee Mac on April 28, 2017, 01:09:02 PM
(lastline) is the same as (entlast)

No it's not.
Title: Re: Make (entlast) work like (entsel)
Post by: GDF on April 28, 2017, 01:45:47 PM
Here is what I got to work:

Code: [Select]
(defun C:WW2  ()
  (ARCH:F_S-VAR)
  (defun ARCH:MIDPOINT  (w z)
    (list (/ (+ (car w) (car z)) 2) (/ (+ (cadr w) (cadr z)) 2)))
  (ARCH:LYR "A-WALL-FULL")
  (setq pt1 (getpoint "\n* Pick beginning point *"))
  (setq pt2 (getpoint pt1 "\n* Pick the end point *"))
  (command "line" pt1 pt2 "")
  (setq mid (ARCH:MIDPOINT pt1 pt2))
  (defun lastline ( / s )
    (if (setq s (ssget "_X" '((0 . "LINE"))))(ssname s 0)) 
  )
  (entget (entlast))
  (setq wallline     (list (lastline) mid) ;;(entsel "\n* Select Line to offset...")
        firstendpnt  (trans (cdr (assoc 10 (entget (car wallline)))) 0 1)
        secondendpnt (trans (cdr (assoc 11 (entget (car wallline)))) 0 1)
        pnt2         (getpoint "\n* Specify Offset Directiont --> ")
        ang1         (angle firstendpnt secondendpnt)) 
  (if (and (> ang1 (/ pi 2.0)) (<= ang1 (* pi 1.5)))
    (setq ang1 (+ ang1 pi))) 
  (command "offset" "3.5" wallline pnt2 "")
  (command "change" "l" "" "p" "la" "A-WALL-FULL" "")
  (ARCH:LYR "A-WALL-VENR")
  (command "offset" "9.0" wallline pnt2 "")
  (command "change" "l" "" "p" "la" "A-WALL-EXT" "")
  (princ)
  (ARCH:F_R-VAR)
  (princ))

Thanks Lee
Title: Re: Make (entlast) work like (entsel)
Post by: roy_043 on April 29, 2017, 04:53:33 AM
@GDF:
Why don't you use:
Code: [Select]
(list (entlast) pt1)instead of:
Code: [Select]
(list (lastline) mid)?
Code - Auto/Visual Lisp: [Select]
  1. (defun C:WW2 ( / entselLst pt1 pt2 pt3)
  2.   (ARCH:F_S-VAR)
  3.   (setq pt1 (getpoint "\n* Pick beginning point *"))
  4.   (setq pt2 (getpoint pt1 "\n* Pick the end point *"))
  5.   (command "_.line" pt1 pt2 "")
  6.   (setq entselLst (list (entlast) pt1))
  7.   (setq pt3 (getpoint "\n* Specify offset direction --> "))
  8.   (command "_.offset" "3.5" entselLst pt3 "")
  9.   (ARCH:LYR "A-WALL-FULL")
  10.   (command "_.chprop" "_last" "" "_layer" "A-WALL-FULL" "")
  11.   (command "_.offset" "9.0" entselLst pt3 "")
  12.   (ARCH:LYR "A-WALL-EXT")
  13.   (command "_.chprop" "_last" "" "_layer" "A-WALL-EXT" "")
  14.   (ARCH:F_R-VAR)
  15.   (princ)
  16. )
Title: Re: Make (entlast) work like (entsel)
Post by: GDF on April 29, 2017, 01:16:36 PM
@GDF:
Why don't you use:
Code: [Select]
(list (entlast) pt1)instead of:
Code: [Select]
(list (lastline) mid)?
Code - Auto/Visual Lisp: [Select]
  1. (defun C:WW2 ( / entselLst pt1 pt2 pt3)
  2.   (ARCH:F_S-VAR)
  3.   (setq pt1 (getpoint "\n* Pick beginning point *"))
  4.   (setq pt2 (getpoint pt1 "\n* Pick the end point *"))
  5.   (command "_.line" pt1 pt2 "")
  6.   (setq entselLst (list (entlast) pt1))
  7.   (setq pt3 (getpoint "\n* Specify offset direction --> "))
  8.   (command "_.offset" "3.5" entselLst pt3 "")
  9.   (ARCH:LYR "A-WALL-FULL")
  10.   (command "_.chprop" "_last" "" "_layer" "A-WALL-FULL" "")
  11.   (command "_.offset" "9.0" entselLst pt3 "")
  12.   (ARCH:LYR "A-WALL-EXT")
  13.   (command "_.chprop" "_last" "" "_layer" "A-WALL-EXT" "")
  14.   (ARCH:F_R-VAR)
  15.   (princ)
  16. )
Title: Re: Make (entlast) work like (entsel)
Post by: GDF on April 29, 2017, 01:17:27 PM
Thanks Roy

Title: Re: Make (entlast) work like (entsel)
Post by: BIGAL on April 29, 2017, 09:39:46 PM
GDF for future reference (entget (entlast)) will get the last entity but you did not save it to a variable so you can use it, (setq lline (entget (entlast))). But like Lee its the last entity created so you must remember to do it straight after making an entity that you know what type it is.
Title: Re: Make (entlast) work like (entsel)
Post by: GDF on April 30, 2017, 11:01:25 AM
Thanks