Author Topic: Zoom and select by handle  (Read 5398 times)

0 Members and 1 Guest are viewing this topic.

DvR

  • Guest
Zoom and select by handle
« on: November 18, 2013, 01:26:29 PM »
Hi All,

I have borrowed from another lisp routine to create the following to zoom to a entity based on an user input handle:

Code: [Select]
(defun c:zh ( / hdl xy enttype ed en xy2)
 (setq YourHandle (getstring "\nEnter Handle: "))
 (if (handent YourHandle)
 (command "._zoom" "_ob" (handent YourHandle) "")
 (princ "\nHandle not in drawing")
 )
)

I did use part of the code from Nate Holt's routine (http://nateholt.wordpress.com/2009/10/15/zoom-to-handle-utility-autocad-electrical/), but I did not use all of it for a number of reasons:
 1. For a line entity it zooms to an endpoint, while I wanted to zoom to the entire entity. Which my modified routine does better, but not completely (I see that blocks are not zoomed in very well).
 2. I did not want to have the option of continuously adding to the selection set (?) as my users will be editing one entity at a time.
 3. The highlighting (?) in Nate's routine is not as clear as actually selecting the entity. I have overlapping entities in my drawings. For Nate's original routine the user would need to either:
 i) Press return to end the routine (which then unhighlights the entity, counter to my purpose of showing the user the entity in question);
 ii) Press escape which ends the routine and allows the user to manually select the entity (but with overlapping entities and the less clear highlighting this is not always easy). The user would now have to manually select the entity and escape to unhighlight it.
 4. I want the entity selected as well as zoomed to in order to enable users to start editing object data, and/or move endpoints or blocks. Manually selecting would introduce additional user error.

But I lack the knowldge and/or couldn't find (or make work) code I found to select the handle. I would like to be able to zoom to the entity (centered on the entity and showing the entire entity) and then have the entity selected (grips) so that the user knows which entity it is (there are overlapping entities in my drawings).

I am using AutoCAD Map 3D 2014 if that makes any difference.
 
Thanks,
 David

<edit: code tags added>
« Last Edit: November 19, 2013, 08:15:32 AM by CAB »

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Zoom and select by handle
« Reply #1 on: November 18, 2013, 01:54:07 PM »
Not sure, maybe this :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:zh ( / YourHandle ll ur )
  2.   (setq YourHandle (getstring "\nEnter Handle: "))
  3.   (if (handent YourHandle)
  4.     (progn
  5.       (vla-getboundingbox (vlax-ename->vla-object (handent YourHandle)) 'll 'ur)
  6.       (sssetfirst nil (ssadd (handent YourHandle)))
  7.     )
  8.     (princ "\nHandle not in drawing")
  9.   )
  10.   (princ)
  11. )
  12.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

DvR

  • Guest
Re: Zoom and select by handle
« Reply #2 on: November 18, 2013, 03:13:58 PM »
This code selects and zooms to the user input handle, all without the disadvantages (IMO and my need) of the original code I had gotten it from.  It also zooms better than the code I had been using.

Thanks Marko!  Fast service!

AcDbZombieEntity

  • Mosquito
  • Posts: 20
Re: Zoom and select by handle
« Reply #3 on: November 19, 2013, 01:29:51 AM »
btw. is there any posibility to lisp an "handle-walk" sorted up by handles? maybe like laywalk

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Zoom and select by handle
« Reply #4 on: November 19, 2013, 05:20:58 PM »
It's not like laywalk, but it may serve its purpose...

I hope Alan won't be mad as I used his code that I adapted to this purpose... If dialog box doesn't show up, you probably have to set its new width/height values... It is allowed up to 256 entities in dialog box, so this is lack of this routine...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:selbyhand (/ ss i e d lst sss *ent:hand*)
  2.   (if (setq ss (ssget "_X"
  3.                       (list (if (eq (getvar 'CVPORT) 1)
  4.                               (cons 410 (getvar 'CTAB))
  5.                               '(410 . "Model")
  6.                             )
  7.                       )
  8.                )
  9.       )
  10.       (progn
  11.         (repeat (setq i (sslength ss))
  12.           (setq e            (ssname ss (setq i (1- i)))
  13.                 d            (entget e)
  14.                 *ent:hand* (cons (vl-remove nil (list (cdr (assoc 5 d)) (assoc 0 d) (assoc 8 d) (assoc 6 d) (assoc 38 d) (assoc 40 d) (assoc 41 d) (assoc 42 d) (assoc 50 d) (assoc 51 d) (assoc 62 d) (assoc 70 d) (assoc 90 d) (assoc 10 d) (assoc 11 d) (assoc 210 d) (assoc 410 d)))
  15.                                    *ent:hand*
  16.                              )
  17.           )
  18.         )
  19.         (setq lst (AT:ListSelect
  20.                      "Select dialog box"
  21.                      "Select items to highlight:"
  22.                      50
  23.                      200
  24.                      "true"
  25.                      (mapcar 'vl-prin1-to-string *ent:hand*)
  26.                   )
  27.         )
  28.         (setq lst (mapcar '(lambda (x) (substr x 3 (- (vl-string-position (ascii ".") x) 7))) lst))
  29.         (setq sss (ssadd))
  30.         (foreach h lst
  31.           (ssadd (handent h) sss)
  32.         )
  33.         (sssetfirst nil sss)
  34.       )
  35.   )
  36.   (princ)
  37. )
  38.  
  39. (defun AT:ListSelect (title label height width multi lst / fn fo d item f)
  40.   ;; List Select Dialog (Temp DCL list box selection, based on provided list)
  41.   ;; title - list box title
  42.   ;; label - label for list box
  43.   ;; height - height of box
  44.   ;; width - width of box
  45.   ;; multi - selection method ["true": multiple, "false": single]
  46.   ;; lst - list of strings to place in list box
  47.   ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
  48.   (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  49.   (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
  50.                    (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
  51.                    (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
  52.                    (strcat "width = " (vl-princ-to-string width) ";")
  53.                    (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
  54.              )
  55.     (write-line x fo)
  56.   )
  57.   (close fo)
  58.   (new_dialog "list_select" (setq d (load_dialog fn)))
  59.   (start_list "lst")
  60.   (setq item (set_tile "lst" "0"))
  61.   (action_tile "lst" "(setq item $value)")
  62.   (if (= f 1)
  63.     (mapcar '(lambda ( n ) (nth n lst)) (read (strcat "(" item ")")))
  64.   )
  65. )
  66.  

Regards, M.R.
 :wink:
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

littlepeterpan821

  • Guest
Re: Zoom and select by handle
« Reply #5 on: April 07, 2017, 05:47:56 AM »
Code: [Select]
(defun c:zh ( / YourHandle ll ur )
  (vl-load-com)
  (setq YourHandle (getstring "\nEnter Handle: "))
  (if (handent YourHandle)
    (progn
      (vla-getboundingbox (vlax-ename->vla-object (handent YourHandle)) 'll 'ur)
      (vla-zoomwindow (vlax-get-acad-object) ll ur)
      (sssetfirst nil (ssadd (handent YourHandle)))
    )
    (princ "\nHandle not in drawing")
  )
  (princ)
)

I founded that this lisp is just simple but great, anyone can help me edit a little bit more pls!? I have a list of handle ID like
A;B;C;D....
I wanna use this lisp for single HandleID either for multiple Handle too!! ^^