Selecting a block with coordinate input?

Discussion in 'AutoCAD' started by VikCAD04, Oct 16, 2004.

  1. VikCAD04

    VikCAD04 Guest

    ok, it is Friday and I feel like there's a real easy solution to this, but my brain seems to already be on vacation.
    So i'm using :
    (setq br(cdr (assoc 2 (entget (car (entsel))))))

    to get the block name stored to a BR, but this ofcourse still asks me to pick the object. But i know the coordinates of that object, they are 0.5,0.5. Where do I plug that into?
    BRAINFREEZE....
     
    VikCAD04, Oct 16, 2004
    #1
  2. VikCAD04

    Jeff Mishler Guest

    look at the (nentselp) function....
     
    Jeff Mishler, Oct 16, 2004
    #2
  3. VikCAD04

    VikCAD04 Guest

    thanks for quick reply, but nentselp will not work for me, as I need to get the actual name of the block, basically I need to check if it's blockA or blockB, then in my lisp i have IF function that will operate from whatever that block is.

    So maybe i'm not using it right, but it only gives me Ename and some other things, but not the name.
     
    VikCAD04, Oct 16, 2004
    #3
  4. VikCAD04

    VikCAD04 Guest

    James,
    Actually it's for a title block so it will be at 0,0 all the time.
    I used to use the limits for my IF function, but found out that not every drawing has their limits set accurately.
    So i'm using the titleblock name to find the difference between E and D size drawing.
    So what other functions can I use other than nentselp?
     
    VikCAD04, Oct 16, 2004
    #4
  5. VikCAD04

    Jeff Mishler Guest

    nentselp would work, subject to James' comments, and use (entget) on the
    result.
    Alternatively, you could use
    (or (setq ss1 (ssget "x" (list '(10 0.0 0.0 0.0)(cons 2
    "Etitleblockname"))))
    (setq ss2 (ssget "x" (list '(10 0.0 0.0 0.0)(cons 2
    "Dtitleblockname"))))
    )
     
    Jeff Mishler, Oct 16, 2004
    #5
  6. VikCAD04

    James Allen Guest

    nentselp

    Beware though. If you would get nothing in the pickbox by picking that
    point on screen, this won't find anything either. For example, you nentselp
    looking for a block by it's insertion point, but this block's geometry is
    actually away from it's insertion point, you may not find it.
     
    James Allen, Oct 16, 2004
    #6
  7. VikCAD04

    James Allen Guest

    nentselp will work. I know the help files are a little cluttered on this
    subject, but nonetheless... Study the help file for nentsel and notice what
    each element of the list means. Then look at the help for nentselp and
    notice that they are identical except that nentselp returns a different kind
    of matrix and allows the program to pass a pick point (as you requested).

    (entsel)->(<ename> pkpt)
    (nentsel)->(<nstdenm#+1> pkpt 4x3Tmtrx (<nstdinsenm#> ... <nstdinsenm1>
    <insenm>))
    (nentselp)->(<nstdenm#+1> pkpt 4x4Tmtrx (<nstdinsenm#> ... <nstdinsenm1>
    <insenm>))

    So the list you get from nentselp is just like what you are using from
    entsel except that the first element is a nested item, not the insert
    itself, and there are two additional elements. If you succeed in picking a
    block with nentselp, then
    (last (last (nentselp)))
    returns exactly the same thing as
    (car (entsel))

    That will plug right into the code you posted, and you can supply a pick
    point. Or you can use the selection method Jeff proposed, which doesn't
    have the graphical limitation.

    James
     
    James Allen, Oct 16, 2004
    #7
  8. VikCAD04

    Jürg Menzi Guest

    Hi VikCAD04

    This may help to solve the problem:
    Code:
    ;
    ; == Function MeGetBlockAtPoint
    ; Returns the block(s) at the specified point.
    ; Arguments [Type]:
    ;   Nme = Block name(s) "MyBlock1,MyBlock2" [STR]
    ;   Pnt = Insertion point of block '(X Y Z) [LIST]
    ;   Pre = Precision to select the block insertion point [REAL]
    ; Return [Type]:
    ;   > Selection set [PICKSET]
    ;   > False if no block found
    ; Notes:
    ;   - Use Nme argument '*' to select *all* blocks at point.
    ;
    (defun MeGetBlockAtPoint (Nme Pnt Pre / LolPnt UprPnt)
    (setq LolPnt (mapcar '- Pnt (list Pre Pre Pre))
    UprPnt (mapcar '+ Pnt (list Pre Pre Pre))
    )
    (ssget "X" (list
    '(0 . "INSERT")
    (cons 2 Nme)
    '(-4 . ">,>,>") (cons 10 LolPnt)
    '(-4 . "<,<,<") (cons 10 UprPnt)
    )
    )
    )
    
    Use:
    (MeGetBlockAtPoint "MyBlock" '(0.5 0.5 0.0) 1E-6)

    Cheers
     
    Jürg Menzi, Oct 17, 2004
    #8
  9. VikCAD04

    VikCAD04 Guest

    Thanks to everyone for their help.
    I still can't get either one of the options to work for me, maybe it's my lack of lisp education.
    If someone could maybe point me to some help files it would be great.
    Or someone could help me just finish this thing so that i can be over with it.

    My Border names are CORP-D and CORP-E
    Bottom left corner of them is 0.5, 0.5 , 0
    I need to have some function either NENTSELP or MAPCAR? pick the object and see if it's D or E and store the name in a
    "BR".
    So that later I can use BR in the IF function.
    I will keep testing this and try to figure out how this works, but please help me out with some useful info.

    Thanks.
    PS, I've been through a couple of tutorials but they are not either up to date or just not quiet deep enough, to get to things like this.

    Viktor
     
    VikCAD04, Oct 19, 2004
    #9
  10. VikCAD04

    Jeff Mishler Guest

    Here's one way:

    (if (and (setq ss (ssget "x" '((0 . "INSERT")(10 . 0.5 0.5 0.0))));change
    this to the blocks' insertion point
    (setq blk (entget (ssname ss 0)))
    );and
    (progn
    (if (eq (setq bname (cdr (assoc 2 blk))) "CORP-D")
    (progn
    ;do your "D" stuff......
    );progn
    (progn
    ;do your "E" stuff......
    );progn
    );if
    );progn
    );if
     
    Jeff Mishler, Oct 19, 2004
    #10
  11. VikCAD04

    Jürg Menzi Guest

    Hi Viktor

    If your block is the only instance with this name you can use this function:
    Code:
    (defun C:CheckStamp ( / BlkNme CurSet)
    (if (setq CurSet (ssget "X" '((0 . "INSERT") (2 . "CORP-D,CORP-E"))))
    (progn
    (setq BlkNme (cdr (assoc 2 (entget (ssname CurSet 0)))))
    (cond
    ((eq BlkNme "CORP-D")
    (alert (strcat "Block " BlkNme " found.")) ;do the D stuff
    )
    ((eq BlkNme "CORP-E")
    (alert (strcat "Block " BlkNme " found.")) ;do the E stuff
    )
    )
    )
    (alert "Block CORP-D or CORP-E not found.")
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Oct 19, 2004
    #11
  12. VikCAD04

    VikCAD04 Guest

    Thanks all of you, the last one worked good after i figured out it's case sensitive on the block name.
    Thanks again,
    Viktor
     
    VikCAD04, Oct 19, 2004
    #12
  13. VikCAD04

    Jürg Menzi Guest

    Glad to help you...¦-)

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