Get points using entlast

Discussion in 'AutoCAD' started by Gary Fowler, Apr 6, 2005.

  1. Gary Fowler

    Gary Fowler Guest

    Using (entlast), how would you get the two end points if the
    object is a line? Also the midpoint?

    Sorry, I'm brain dead right now.

    (setq pnts (list (cdr (assoc 10 (entget (entlast))))(cdr (assoc 11 (entget
    (entlast))))))?
     
    Gary Fowler, Apr 6, 2005
    #1
  2. Gary Fowler

    Jeff Mishler Guest

    Something like this.....

    (setq ent (entget (entlast))
    startPt (cdr (assoc 10 ent))
    endPt (cdr (assoc 11 ent))
    midPt (mapcar '/ (mapcar '+ startPt endPt) '(2.0 2.0 2.0))
    )
     
    Jeff Mishler, Apr 6, 2005
    #2
  3. Gary Fowler

    Gary Fowler Guest

    Perfect, once I have another cup....I will
    work on my emailing skills.

    Thanks again

    [_]P
     
    Gary Fowler, Apr 6, 2005
    #3
  4. Gary Fowler

    Gary Fowler Guest

    Here is the routine I was wanting to modify. Jeff Mishler provided
    the missing part. The routine inserts text centered between two
    parallel lines and matches the line rotation. I am sure there
    are easier ways to do this...but for now this is working. I still
    have a lot of code cleanup to do...............

    Thanks again Jeff.

    Code:
    (defun ARCH:CEN-BETWEEN-LIN2  (/ a b p1 p2 pt ent1 ent2 ent3 elist)
    (if (not ARCH:GetIntersect)
    (load (strcat ARCH#UTIF "ARCH_GET_INTERSECT")))
    (defun CEN-BETWEEN-LIN-DOIT  ()
    (command "line" a b "")
    (setq ent1 (entlast))
    (cond (SS1
    (repeat (sslength SS1)
    (setq ent2 (cdr (assoc -1 (entget (ssname SS1 0)))))
    (setq p1 (ARCH:GetIntersect ent1 ent2))
    (setq ent3 (cdr (assoc -1 (entget (ssname SS1 1)))))
    (setq p2 (ARCH:GetIntersect ent1 ent3)))))
    (command "dist" "nea" p1 "per" p2)
    (setq dist_1 (getvar "distance"))
    (setq dist_2 (/ dist_1 2.0))
    (setq x (/ (+ (car p1) (car p2)) 2))
    (setq y (/ (+ (cadr p1) (cadr p2)) 2))
    (setq z (/ (+ (caddr p1) (caddr p2)) 2))
    (setq p3 (list x y z))
    (command "offset" dist_2 ent2 p3 "")
    (entdel ent1)
    (princ))
    (setvar "orthomode" 0)
    (setvar "osmode" 0)
    ;;(initget 1)
    (setq a (getpoint "\n* Draw Crossing Line *"))
    (initget 33)
    (setq b (getpoint a))
    (setq pt (list a b))
    (setq SS1 (ssget "F" pt '((0 . "LINE"))))
    (cond
    ((or (= SS1 nil) (/= (sslength SS1) 2))
    (ARCH:ALERT-E
    "MsgBox \"
    Selection Error Message
    --------------------------------------------------------------------------------------------
    Invalid Selection...either you selected nothing, a
    double line <line on top of a line>, or a polyline.
    If a double line, delete one, or if a polyline
    change it to a line. Now you can try again...\""))
    ((CEN-BETWEEN-LIN-DOIT)))
    (princ))
    
    (defun c:WAL-2X6IT (/ ent entl startPt endPt angl)
    ;;(ARCH:F_S-VAR)
    (setvar "osmode" 0)
    (setvar "orthomode" 0)
    (ARCH:CEN-BETWEEN-LIN2)
    (command "change" "l" "" "p" "lt" "hidden" "c" "6" "")
    ;;(ARCH:CUSTOM_LAYERS-ANNO)
    ;;(ARCH:SET-NOTES)
    (setq ITEM "2x6")
    (setq entl (entlast))
    (setq ent (entget (entlast))
    startPt (cdr (assoc 10 ent))
    endPt (cdr (assoc 11 ent))
    midPt (mapcar '/ (mapcar '+ startPt endPt) '(2.0 2.0 2.0))
    );;Jeff Mishler
    (setvar "osmode" 0)
    ;;p3 from ARCH:CEN-BETWEEN-LIN2...global var
    (if p3 (command "_.text" "j" "mc" p3 "" 0 ITEM))
    (setvar "osmode" 0)
    (setq ang (angle startPt endPt))
    (if (and (<= ang 4.71239) (> ang 1.5708))
    (setq ang (angle endPt startPt))
    )
    (setq angl (car (list (cons 50 ang))))
    (setq N 0)
    (setq TXT (ssget "L"))
    (repeat (sslength TXT)
    (setq
    Elist
    (subst
    angl
    (assoc 50 (entget (ssname TXT N)))
    (entget (ssname TXT N))
    )
    )
    (entmod Elist)
    (entupd (ssname TXT N))
    (setq N (+ N 1))
    )
    (entdel entl)
    (setq p3 nil)
    ;;(ARCH:F_R-VAR)
    (princ)
    )
    
    (c:WAL-2X6IT)
    
     
    Gary Fowler, Apr 6, 2005
    #4
  5. Gary Fowler

    Gary Fowler Guest

    Sorry, I forgot to include this code.

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;; Get the Intersection Function
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;One of the better ways is to use the IntersectWith method:
    ;;;Written by R. Robert Bell
    ;;;Takes either ENames or Objects, returns list or nil.
    (defun ARCH:GetIntersect (obj1 obj2)
    (foreach
    obj '(obj1 obj2)
    (if (= (type (eval obj)) 'ENAME)
    (set obj
    (vlax-EName->vla-Object
    (eval obj)
    )
    )
    )
    )
    (vlax-Invoke obj1 'IntersectWith obj2 acExtendBoth)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun C:TEST (/ a b pt ss1 ent1 ent2 ent3)
    (setq t1 nil t2 nil)
    (setvar "orthomode" 1)
    (initget 1)
    (setq a (getpoint "\n* Draw Crossing Line *"))
    (initget 33)
    (setq b (getpoint a))
    (setq pt (list a b))
    (setq SS1 (ssget "F" pt '((0 . "LINE"))))
    (command "line" a b "")
    (setq ent1 (entlast))
    (cond
    (SS1
    (repeat (sslength SS1)
    (setq ent2 (cdr (assoc -1 (entget (ssname SS1 0)))))
    (setq t1 (ARCH:GetIntersect ent1 ent2))
    (setq ent3 (cdr (assoc -1 (entget (ssname SS1 1)))))
    (setq t2 (ARCH:GetIntersect ent1 ent3))
    )
    )
    )
    (princ t1)
    (princ t2)
    (entdel ent1)
    (princ)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun CFLITx (/ p1 p2 a b pt ss1 ent1 ent2 ent3 pkrobj)
    (ARCH:F_S-VAR)
    (setq t1 nil t2 nil)
    (setvar "orthomode" 1)
    (initget 3)
    (setq pkrobj (entsel "\n* Select line...*"))
    (setq p1 (cdr (assoc 10 (entget (car pkrobj)))))
    (setq p2 (cdr (assoc 11 (entget (car pkrobj)))))
    (setvar "orthomode" 1)
    (setvar "SNAPANG" (angle p1 p2))
    (setq a (cadr pkrobj))
    (initget 33)
    (setvar "osmode" 0)
    (setq b (getpoint a "\n* pick point...*"))
    (setq pt (list a b))
    (setq SS1 (ssget "F" pt '((0 . "LINE"))))
    (command "line" a b "")
    (setq ent1 (entlast))
    (cond
    (SS1
    (repeat (sslength SS1)
    (setq ent2 (cdr (assoc -1 (entget (ssname SS1 0)))))
    (setq t1 (ARCH:GetIntersect ent1 ent2))
    (setq ent3 (cdr (assoc -1 (entget (ssname SS1 1)))))
    (setq t2 (ARCH:GetIntersect ent1 ent3))
    )
    )
    )
    (princ t1)
    (princ t2)
    (if ent1 (entdel ent1))
    (ARCH:F_R-VAR)
    (princ)
    )
    (defun mid (w z)
    (LIST (/ (+ (CAR w) (CAR z)) 2) (/ (+ (CADR w) (CADR z)) 2))
    )
    (defun CFLIT (/ p1 p2 a b pt ss1 ent1 ent2 ent3 pkrobj)
    (ARCH:F_S-VAR)
    (setq t1 nil t2 nil)
    (setvar "orthomode" 1)
    (initget 3)
    (setq pkrobj (entsel "\n* Select line...*"))
    (setq p1 (cdr (assoc 10 (entget (car pkrobj)))))
    (setq p2 (cdr (assoc 11 (entget (car pkrobj)))))
    (setvar "orthomode" 1)
    (setvar "SNAPANG" (angle p1 p2))
    ;;(setq a (cadr pkrobj))
    (setq a (mid p1 p2))
    (initget 33)
    (setvar "osmode" 0)
    (setq b (getpoint a "\n* pick point...*"))
    (setq pt (list a b))
    (setq SS1 (ssget "F" pt '((0 . "LINE"))))
    (command "line" a b "")
    (setq ent1 (entlast))
    (cond
    (SS1
    (repeat (sslength SS1)
    (setq ent2 (cdr (assoc -1 (entget (ssname SS1 0)))))
    (setq t1 (ARCH:GetIntersect ent1 ent2))
    (setq ent3 (cdr (assoc -1 (entget (ssname SS1 1)))))
    (setq t2 (ARCH:GetIntersect ent1 ent3))
    )
    )
    )
    (princ t1)
    (princ t2)
    (if ent1 (entdel ent1))
    (ARCH:F_R-VAR)
    (princ)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (princ)
    
    --
    Gary Fowler - Architect



     
    Gary Fowler, Apr 6, 2005
    #5
  6. Gary Fowler

    Adesu Guest

    or
    _$ (setq elast (entget (entlast)))
    (setq sp (cdr (assoc 10 elast)))
    (setq ep (cdr (assoc 11 elast)))
    (setq mp (osnap sp "mid"))

    ((-1 . <Entity name: 15fe598>) (0 . "LINE") (330 . <Entity name: 15fe4f8>)
    (5 . "6B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 .
    "AcDbLine") (10 0.0 0.0 0.0) (11 10.0 0.0 0.0) (210 0.0 0.0 1.0))
    (0.0 0.0 0.0)
    (10.0 0.0 0.0)
    (5.0 0.0 0.0)
    _$
     
    Adesu, Apr 7, 2005
    #6
  7. Gary Fowler

    devitg Guest

    Hi Ade , nice trick , could you explain how the "OSNAP" work in this case.
    It do , but I do not know how.
     
    devitg, Apr 7, 2005
    #7
  8. Gary Fowler

    Jeff Mishler Guest

    The lisp function Osnap takes a point as an argument and looks for an object
    at that point....just as if you were selecting an object. However, that is
    why I prefer the mathematical approach......if there is more than one object
    at that point, depending on your aperture setting and the Object sort mode
    you may not get the midpt of the desired object.
     
    Jeff Mishler, Apr 7, 2005
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.