bypass user input, have a look

Discussion in 'AutoCAD' started by mnash, Jul 20, 2004.

  1. mnash

    mnash Guest

    I have the following strings of text and its working fine, but I'd like to do something else to it.

    ( setq txt ( entget ( car ( entsel "\nSelect Stock: " ))))
    ( setq STK ( cdr ( assoc 1 txt)))

    In all cases the entity that the user is being asked to select is in the same area, EVERY time. If we know that the text field is in a vicinity (I don't want to select one point, but I want to cross over the text because the text is always different), can we automatically specify the points in the LISP, so that we can avoid any user input at this point?
    Hope this is clear.... thanks all
    MN
     
    mnash, Jul 20, 2004
    #1
  2. mnash

    T.Willey Guest

    You can use (ssget "c" pt1 pt2 '((0 . "TEXT")))

    Tim
     
    T.Willey, Jul 20, 2004
    #2
  3. mnash

    mnash Guest

    I've tried this but don't seem to work

    ( setq txt ( ssget "C" '(0.9369 10.3109) '(2 10.3109)))
    ( setq STK ( cdr ( assoc 1 txt)))

    as you can see, it's a pretty specific area
    error is
    Error: bad argument type: listp <Selection set: 2a>
     
    mnash, Jul 20, 2004
    #3
  4. mnash

    ECCAD Guest

    ( setq txt ( ssget "C" '(0.9369 10.3109) '(2 10.3109)))
    ( setq STK ( cdr ( assoc 1 txt)))
    To:
    (setq txt (ssget "C" '(0.9369 10.3109) '(2.0 10.3109)))
    (if txt
    (setq STK (cdr (assoc 1 txt)))
    )

    Bob
     
    ECCAD, Jul 20, 2004
    #4
  5. mnash

    T.Willey Guest

    After you get the selection set then you need to cycle thru and find the entity's.

    (setq ent1 (ssname txt 0))
    (setq stk (assoc 1 (entget ent1)))

    Tim
     
    T.Willey, Jul 20, 2004
    #5
  6. mnash

    Tom Smith Guest

    ( setq txt ( ssget "C" '(0.9369 10.3109) '(2 10.3109)))
    No, txt is a selection set. He needs to get the entity data for the first
    member of the selection set.

    (if txt
    (setq stk (cdr (assoc 1 (entget (ssname txt 0)))))
    )
     
    Tom Smith, Jul 20, 2004
    #6
  7. mnash

    mnash Guest

    From your suggestion I get this error
    Error: bad argument type: listp <Selection set: 3e>

    maybe its because:
    ( setq txt (ssget "C" '(0.9369 10.3109) '(2.0 10.3109)))
    ( if txt ( setq STK (cdr (assoc 1 txt))))
    ( setq txt ( entget ( car ( entsel "\nSelect First Endcut: " ))))
    ( setq E1 ( cdr ( assoc 1 txt)))
    ( setq txt ( entget ( car ( entsel "\nSelect Second Endcut: " ))))
    ( setq E2 ( cdr ( assoc 1 txt)))
     
    mnash, Jul 20, 2004
    #7
  8. mnash

    T.Willey Guest

    Error: bad argument type: listp <Selection set: 3e>
    Look at your error. You are getting a selection set, but you can't get an (assoc 1... from there. You need to get the entity first with (entget, then you can get (assoc 1 from that.

    Tim
     
    T.Willey, Jul 20, 2004
    #8
  9. mnash

    ECCAD Guest

    Got it.

    (setq pt1 (list 0.9369 10.3109 0.0))
    (setq pt2 (list 2.0 10.3109 0.0))
    (setq txt (ssget "c" pt1 pt2))
    ;( setq txt (ssget "C" '(0.9369 10.3109) '(2.0 10.3109)))
    (if txt
    (progn
    (setq ent (ssname txt 0))
    (setq ent (entget ent))
    (setq STK (cdr (assoc 1 ent)))
    ); progn
    ); if
    ;;
    ( setq txt ( entget ( car ( entsel "\nSelect First Endcut: " ))))
    ( setq E1 ( cdr ( assoc 1 txt)))
    ( setq txt ( entget ( car ( entsel "\nSelect Second Endcut: " ))))
    ( setq E2 ( cdr ( assoc 1 txt)))
     
    ECCAD, Jul 20, 2004
    #9
  10. mnash

    ECCAD Guest

    Tom,
    Yes I see that (upon review)..Thanks.
     
    ECCAD, Jul 20, 2004
    #10
  11. mnash

    Jürg Menzi Guest

    Hi mnash

    First of all, the solution with 'ssget' works only if the text is inside the
    visible area of the screen - therefore not reliable.
    If the text is always at the same position, it makes sense to use 'ssget' with
    a logical filter to search for 'TEXT' AND InsertionPoint > LowerLeftCorner
    AND InsertionPoint < UpperRightCorner. This method works also for text outside
    the visible screen area.
    <snip>
    (setq CurSet (ssget "X" (list
    '(-4 . ">,>,*") (cons 10 '(9.9 9.9 0.0)) ;LowerLeft
    '(-4 . "<,<,*") (cons 10 '(10.1 10.1 0.0)) ;UpperRight
    '(0 . "TEXT")
    )
    )
    )
    (if CurSet ;avoid an error if there is no text
    (progn
    (setq txt (ssname CurSet 0) ;extract entity from selection set
    stk (cdr (assoc 1 (entget CurEnt))) ;extract text from entity
    )
    ;
    ;rest of your code here
    ;
    )
    )
    )
    <snip>

    To find the text insertion point information, use property -> read the X and
    Y position. For my example the text had X=10.0 and Y=10.0.

    Cheers
     
    Jürg Menzi, Jul 21, 2004
    #11
  12. mnash

    Jürg Menzi Guest

    Oops...
    Must be:
    First of all, the solution with 'ssget crossing' works only...

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

    Jürg Menzi Guest

    And another point...

    The filter works more efficient if you make this modification:
    <snip>
    (setq CurSet (ssget "X" (list
    '(0 . "TEXT")
    '(-4 . ">,>,*") (cons 10 '(9.9 9.9 0.0)) ;LowerLeft
    '(-4 . "<,<,*") (cons 10 '(10.1 10.1 0.0)) ;UpperRight
    )
    )
    )
    <snip>

    Cheers
     
    Jürg Menzi, Jul 21, 2004
    #13
  14. mnash

    Jürg Menzi Guest

    Hi mnash

    Must be a lack of coffee this morning...;-)
    Ok, forget my other messages (Anne, delete them please), this is the final one:

    First of all, the solution with 'ssget crossing' works only if the text is
    inside the visible area of the screen - therefore not reliable.
    If the text is always at the same position, it makes sense to use 'ssget' with
    a logical filter to search for 'TEXT' AND InsertionPoint > LowerLeftCorner
    AND InsertionPoint < UpperRightCorner. This method works also for text outside
    the visible screen area.
    <snip>
    (setq CurSet (ssget "X" (list
    '(0 . "TEXT")
    '(-4 . ">,>,*") (cons 10 '(9.9 9.9 0.0)) ;LowerLeft
    '(-4 . "<,<,*") (cons 10 '(10.1 10.1 0.0)) ;UpperRight
    )
    )
    )
    (if CurSet ;avoid an error if there is no text
    (progn
    (setq txt (ssname CurSet 0) ;extract entity from selection set
    stk (cdr (assoc 1 (entget txt))) ;extract text from entity
    )
    ;
    ;rest of your code here
    ;
    )
    )
    <snip>

    To find the text insertion point information, use property -> read the X and
    Y position. For my example the text had X=10.0 and Y=10.0.

    Cheers
     
    Jürg Menzi, Jul 21, 2004
    #14
  15. mnash

    mnash Guest

    Yes I agree, which is what is was in the first place... entget. But I wanted to put in a crossing window to always select an area for that entity
     
    mnash, Jul 21, 2004
    #15
  16. mnash

    mnash Guest

    from the way you are explaining it, your code is more reliable, but when I do snip your code and modify the co-ordinates for my task, I get a malformed error. The brackets and quotes seem fine to me though

    When you say
    "rest of your code here" what i've got to do is select two other pieces of text in the same fashion as what we've been talking about all along, so I'm a little confused. I hve it set up so that I get all variables first.... I'm gettin' a coffee
     
    mnash, Jul 21, 2004
    #16
  17. mnash

    Jürg Menzi Guest

    Hi mnash
    Did you use 3D points? It's necessary, because code 10 of a text returns 3D
    points.
    (cons 10 '(9.9 9.9 0.0)) ;<- 3 numbers required
    (cons 10 '(10.1 10.1 0.0)) ;<- 3 numbers required
    In this case you should change the code to a function:
    ;
    ; == Function GetTextAtPoint
    ; Reads text string from text at given point.
    ; Argumente [Type]:
    ; Pnt = Insertion point of text '(X Y Z)

    • ; Pre = Precision to select the text point [REAL]
      ; Return [Type]:
      ; > Text string [STR]
      ; nil if no text found at the point
      ; Notes:
      ; None
      ;
      (defun GetTextAtPoint (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 . "TEXT")
      '(-4 . ">,>,*") (cons 10 LolPnt)
      '(-4 . "<,<,*") (cons 10 UprPnt)
      )
      )
      )
      (if CurSet (cdr (assoc 1 (entget (ssname CurSet 0)))))
      )

      Use this function like:
      <snip>
      (cond
      ;exit here when first text not found
      ((not (setq FstTxt (GetTextAtPoint '(10 10 0) 0.1)))
      (princ "\nFirst text not found! - Exit.")
      )
      ;exit here when second text not found
      ((not (setq SecTxt (GetTextAtPoint '(10 20 0) 0.1)))
      (princ "\nSecond text not found! - Exit.")
      )
      ;exit here when third text not found
      ((not (setq ThiTxt (GetTextAtPoint '(10 30 0) 0.1)))
      (princ "\nThird text not found! - Exit.")
      )
      ;else...
      (T
      ;all text found, continue program between (T ... )
      )
      );end cond
      Got it in meantime...¦-)

      Cheers
     
    Jürg Menzi, Jul 21, 2004
    #17
  18. mnash

    mnash Guest

    wow, quite the script there pal
    but guess what, I got it to work and it works like a charm
    thanks all for your help and patience. Your discussion are very valuable..
    Mn
     
    mnash, Jul 21, 2004
    #18
  19. mnash

    Jürg Menzi Guest

    mnash

    Welcome...¦-)

    Cheers
     
    Jürg Menzi, Jul 21, 2004
    #19
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.