entsel and then nil

Discussion in 'AutoCAD' started by kpennell, Jul 21, 2004.

  1. kpennell

    kpennell Guest

    How do I specify an action based on wheather or not an object exists at a given point. For example, first step, if an object does not exist at 0,0,0, then I want to set 0,0,0 as pt1 for the rest of my lisp. If an object do exist, the next point, I want it to be 16,0,0 and have that co-ordinate set as my pt1 for my lisp. If an object exists at 16,0,0, then I want to use 32,0,0 and so on. Basically the first point that creats a nil, I want it to become my pt1.
    Also, eventually when i travel too far the right I'm going to be inserting a negative Y co-ordinate, but I haven't decided what my extents are going to be.
    tnx
    kpennell
     
    kpennell, Jul 21, 2004
    #1
  2. kpennell

    ECCAD Guest

    To check for an object at 0,0:
    (setq pt1 (list 0.0 0.0 0.0))
    (setq pt2 pt1)
    (setq ss (ssget "c" pt1 pt2))
    (if ss
    (progn
    (........there was something there..do your thing)
    )
    )
    To increment the next point..
    (setq pt1 (+ (car pt1) 16.0)(+ (cadr pt1) 0.0)))

    Bob
     
    ECCAD, Jul 21, 2004
    #2
  3. kpennell

    Jürg Menzi Guest

    Hi kpennell

    Do you use a specific object like a block or so?

    Cheers
     
    Jürg Menzi, Jul 21, 2004
    #3
  4. Another way:

    (setq pnt '(0 0 0))
    (while (not ent)
    (setq ent (nentselp pnt))
    (if (zerop (car pnt))
    (setq pnt (append (list (+ (car pnt) 16)) (cdr pnt)))
    (setq pnt (append (list (* (car pnt) 2)) (cdr pnt)))
    )
    )

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

    at a given point. For example, first step, if an object does not
    exist at 0,0,0, then I want to set 0,0,0 as pt1 for the rest of my
    lisp. If an object do exist, the next point, I want it to be 16,0,0
    and have that co-ordinate set as my pt1 for my lisp. If an object
    exists at 16,0,0, then I want to use 32,0,0 and so on. Basically the
    first point that creats a nil, I want it to become my pt1.
    inserting a negative Y co-ordinate, but I haven't decided what my
    extents are going to be.
     
    Ken Alexander, Jul 21, 2004
    #4
  5. kpennell

    kpennell Guest

    There is a template that is inserted based on my variable p1, that if there is nothing at 0,0 (p1), then insert the template at 00 (p1), but if a template already exists there (i.e. 0,0-p1) then insert it at 16,0, and still have that co-ordinate as p1 for the rest of my Lisp
    Is that clearer
     
    kpennell, Jul 21, 2004
    #5
  6. kpennell

    Jürg Menzi Guest

    Hmmm... template - you mean a block do you?

    In case of a block you can use this function:
    ;
    ; == Function GetBlockAtPoint
    ; Returns the block entity at given point.
    ; Argumente [Type]:
    ; Pnt = Insertion point of block '(X Y Z)

    • ; Pre = Precision to select the insertion point [REAL]
      ; Return [Type]:
      ; > Block ename [ENAME]
      ; nil if no block found at the point
      ; Notes:
      ; None
      ;
      (defun GetBlockAtPoint (Pnt Pre / CurSet LolPnt UprPnt)
      (setq LolPnt (mapcar '- Pnt (list Pre Pre 0.0))
      UprPnt (mapcar '+ Pnt (list Pre Pre 0.0))
      CurSet (ssget "X" (list
      '(0 . "INSERT")
      '(-4 . ">,>,*") (cons 10 LolPnt)
      '(-4 . "<,<,*") (cons 10 UprPnt)
      )
      )
      )
      (if CurSet (ssname CurSet 0))
      )
      If the object is not a block, you've to change the filter to the corresponding
      entity name. Does not work with entities they have multiple 10 codes like
      Plines. Consider the 3D point for the Pnt argument.

      Cheers
     
    Jürg Menzi, Jul 21, 2004
    #6
  7. kpennell

    kpennell Guest

    this casues my session to lock-up, 2000
     
    kpennell, Jul 21, 2004
    #7
  8. kpennell

    kpennell Guest

    and this one has too few arguments
     
    kpennell, Jul 21, 2004
    #8
  9. kpennell

    ECCAD Guest

    Did you call it correctly ?
    (defun GetBlockAtPoint (Pnt Pre / CurSet LolPnt UprPnt)
    In the call, you need to supply (2) items. (Pnt Pre /...
    Implies a Point e.g. '(0.0 0.0 0.0)
    and a Pre(cision) e.g. (setq Pre 0.01)
    Then call it this way.

    (setq Pre 0.01 Pnt (list (0.0 0.0 0.0)))
    (GetBlockAtPoint Pnt Pre)

    Bob
     
    ECCAD, Jul 21, 2004
    #9
  10. kpennell

    T.Willey Guest

    (defun check-obj(/ ent)

    (setq pt1 '(0.0 0.0 0.0))
    (setq ent (nentselp pt1))
    (while (not ent)
    (setq pt1 (list (+ 16.0 (car pt1)) 0.0 0.0))
    (setq ent (nentselp pt1))
    )
    (princ)
    )

    Try this.
    Tim
     
    T.Willey, Jul 21, 2004
    #10
  11. kpennell

    ECCAD Guest

    Or try:
    ;; Initial Point to test..
    (setq ss nil ip nil)
    (setq pt1 (list 0.0 0.0 0.0))
    (setq pt2 (+ (car pt1) 0.1)(- (cadr pt1) 0.1)))
    (setq ss (ssget "c" pt1 pt2))
    (if (= ss nil)
    (setq ip pt1)
    );if
    (while ss
    (progn
    (setq pt1 (+ (car pt1) 16.0)(+ (cadr pt1) 0.0)))
    (setq pt2 (+ (car pt1) 0.1)(- (cadr pt1) 0.1)))
    (setq ss (ssget "c" pt1 pt2))
    (if (= ss nil)
    (setq ip pt1)
    );if
    );progn
    );while
    (princ)
    (prompt "\nNew Insert Point =")
    (if ip (princ ip))

    Bob
     
    ECCAD, Jul 21, 2004
    #11
  12. kpennell

    Jürg Menzi Guest

    kpennel

    Would it be impolite to expect think for one's self?

    Cheers
     
    Jürg Menzi, Jul 21, 2004
    #12
  13. kpennell

    kpennell Guest

    yes it would be
    you are mistaking me for someone who leaches all this lisp information that I am so gratious of receiving. My apologies for my ignorance, as I am not near as advanced in programing as most of you blokes are.
    Sincerly in not trying to offend anyone here
    kpennell
     
    kpennell, Jul 22, 2004
    #13
  14. kpennell

    kpennell Guest

    maybe if I word it this way

    setq p1
    where p1 equals the FIRST point (in a series of points) that does NOT contain an object at that point. The first point in that series of points is 0,0 and the X co-ordinate for the series of points thereafter is a multiple of 16.

    (defun getvars ()
    here is where I'm trying to define p1
    ;defun
    ________________________________________________________________________________________________________________

    ( defun insert ()
    ( command "_SCINSERTSTIFFENERS" p1 )
    );defun insert
    ________________________________________________________________________________________________________________

    ( defun getvars_again ()
    ( setq FN ( getvar "dwgname" ))

    ( setq pt2 ( list 0.9369 10.3109 0.0 ))
    ( setq pt3 ( list 2.0 10.3108 0.0 ))
    ( setq txt ( ssget "C" pt2 pt3 ))
    ( if txt
    ( progn
    ( setq ent ( ssname txt 0 ))
    ( setq ent ( entget ent ))
    ( setq STK ( cdr ( assoc 1 ent )))))

    and the order comes from

    ( getvars )
    ( insert )
    ( command "ucs" "n" p1)
    ( command "zoom" "window" "-0.5,-0.5" "16,11")
    ( command "-osnap" "end" )
    ( command "-layer" "s" "0" "")
    ( getvars_again )
     
    kpennell, Jul 22, 2004
    #14
  15. kpennell

    kpennell Guest

    No takers?
     
    kpennell, Jul 22, 2004
    #15
  16. Did you try Tim's?

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 22, 2004
    #16
  17. kpennell

    T.Willey Guest

    (defun check-obj(/ ent)

    (setq pt1 '(0.0 0.0 0.0))
    (setq ent (nentselp pt1))
    (while (not ent)
    (setq pt1 (subst (+ 16.0 (car pt1)) (car pt1) pt1))
    (setq ent (nentselp pt1))
    )
    (princ)
    )

    This will return the point (pt1) that doesn't have an object there. If an object exist and (0,0,0) then pt1 is (0.0,0.0,0.0), if not then it adds 16.0 to the x value until it hits something.

    Tim
     
    T.Willey, Jul 22, 2004
    #17
  18. kpennell

    MP Guest

    What happens if nothing is found?
    maybe an upper counter limit to prevent infinite loop in empty dwg?

    object exist and (0,0,0) then pt1 is (0.0,0.0,0.0), if not then it adds 16.0
    to the x value until it hits something.
     
    MP, Jul 22, 2004
    #18
  19. kpennell

    kpennell Guest

    I'm running AutoCAD 2000
    When I run your lisp, it locks up on me. What version are you running
     
    kpennell, Jul 22, 2004
    #19
  20. kpennell

    kpennell Guest

    I'll try again. If something is found at p1, then go to the next point. (i.e. a multiple of 16 for the x co-ordinate) if nothing is found at p1 well then I want to do bunch of things based on the point that have nothing existing and re-define p1
     
    kpennell, Jul 22, 2004
    #20
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.