Author Topic: Make (entlast) work like (entsel)  (Read 4431 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Make (entlast) work like (entsel)
« 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...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Make (entlast) work like (entsel)
« Reply #1 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. )

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make (entlast) work like (entsel)
« Reply #2 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))
« Last Edit: April 29, 2017, 07:50:36 AM by CAB »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Make (entlast) work like (entsel)
« Reply #3 on: April 28, 2017, 01:09:02 PM »
(lastline) is the same as (entlast)

No it's not.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make (entlast) work like (entsel)
« Reply #4 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Make (entlast) work like (entsel)
« Reply #5 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. )

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make (entlast) work like (entsel)
« Reply #6 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. )
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make (entlast) work like (entsel)
« Reply #7 on: April 29, 2017, 01:17:27 PM »
Thanks Roy

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Make (entlast) work like (entsel)
« Reply #8 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.
A man who never made a mistake never made anything

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make (entlast) work like (entsel)
« Reply #9 on: April 30, 2017, 11:01:25 AM »
Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64