Author Topic: Entity Handles  (Read 2316 times)

0 Members and 1 Guest are viewing this topic.

QuestionEverything

  • Guest
Entity Handles
« on: September 25, 2016, 01:06:07 PM »
What are entity handles, and more importantly what are they used for?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Entity Handles
« Reply #1 on: September 25, 2016, 01:27:57 PM »
Welcome to The Swamp. :)

I assume you have already read the existing developer documentation?

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-30C33AF6-4BE3-4334-96BD-F929040C31D3

QuestionEverything

  • Guest
Re: Entity Handles
« Reply #2 on: September 25, 2016, 02:12:29 PM »
Hello, thanks for welcoming me.
 I have been reading about them several times but still can't seem to find any practical usage.. so what are they used for?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Entity Handles
« Reply #3 on: September 25, 2016, 03:39:06 PM »
Handles provide the means to perform a wide spectrum of activities including inter object linking, serialization, database use etc. tl;dr: they're invaluable. Welcome to the best AutoCAD website on the web.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

QuestionEverything

  • Guest
Re: Entity Handles
« Reply #4 on: September 25, 2016, 04:32:32 PM »
Hi,
As far I can understand, using "handles" I would be able to store a list of entities, end the drawing session, then in a new session I could access that same entities and for example erase them or grip them in a selection set. Is that correct ? Do you have any practical explanations or examples?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Entity Handles
« Reply #5 on: September 26, 2016, 10:15:32 AM »
Handles provide the means to perform a wide spectrum of activities including inter object linking, serialization, database use etc. tl;dr: they're invaluable. Welcome to the best AutoCAD website on the web.

Well, that's what they can be used for.  What they are, is a unique index in the drawing database.  Each handle will refer to one and only one object (not all entities are objects, but all objects have a handle); each object will have one, and only one, handle.  The handle doesn't change, either in the drawing session or between drawing sessions (it may appear to do so in some circumstances, however what is happening is the original object is being copied or recreated - hence the new handle).  Handles are NOT unique between drawings.

One of our third-party programs provides the option to manage part data in an associated database.  It uses a combination of DWG filename and handle to uniquely identify which part in the database is which part in the DWG file.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Entity Handles
« Reply #6 on: September 26, 2016, 10:19:41 AM »
Ummm. Lee already addressed the "what are handles?" question, I responded to the "what are they used for?" question.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

QuestionEverything

  • Guest
Re: Entity Handles
« Reply #7 on: September 26, 2016, 01:16:16 PM »
Ummm. Lee already addressed the "what are handles?" question, I responded to the "what are they used for?" question.
Okay, I understood "what are handles", but still can't seem to understand their usage. Any simple and precise examples?
Quote
(setq ent (car (entsel)))
(setq data (entget ent))
(setq hand (cdr (assoc 5 data)))
(setq handy (handent hand))
What can I do with 'handy' or 'hand' once I have them?

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Entity Handles
« Reply #8 on: September 26, 2016, 01:26:22 PM »
Ummm. Lee already addressed the "what are handles?" question, I responded to the "what are they used for?" question.
Okay, I understood "what are handles", but still can't seem to understand their usage. Any simple and precise examples?
Quote
(setq ent (car (entsel)))
(setq data (entget ent))
(setq hand (cdr (assoc 5 data)))
(setq handy (handent hand))
What can I do with 'handy' or 'hand' once I have them?

You can store them inside variables after you can save them into *.txt file and reuse them in next CAD session - here is this one example :
http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/extract-a-text-from-a-long-text/m-p/5955380/highlight/true#M337556

To save variables during session in some *.txt file, check another link from post that I just pointed out...

So that's one example of using handles... I must admit I don't use them a lot, but someone else may show something else also interesting...

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

:)

M.R. on Youtube

danallen

  • Guest
Re: Entity Handles
« Reply #9 on: September 26, 2016, 01:27:07 PM »
An example might be to remember a specific entity, though that could be done with selection set. I have a couple examples in my code library
Code - Auto/Visual Lisp: [Select]
  1. ;;;  by sinc @ the Swamp  07/22/2004
  2. ;;;  Repeatedly draws a line from a pick point perpendicular
  3. ;;;  to a selected object
  4. ;;;  modified by Dan Allen to remember entity between uses
  5. (defun c:lp (/ entity pt deleted)
  6.   (princ "\nDraw perpedicular lines from selected entity")
  7.   (if SAA_C:LP_ENTITY
  8.     (progn
  9.       (setq entity (car (entsel "\nSelect entity or <use last chosen>: ")))
  10.       (if (and (not entity)                                             ;if nothing chosen
  11.                (setq entity (handent SAA_C:LP_ENTITY))                  ;and entity can be found
  12.                (setq deleted (entget (handent SAA_C:LP_ENTITY))))       ;and not deleted (entget returns nil if deleted)
  13.         (princ "\nUsing last entity chosen.")
  14.         (progn
  15.           (if deleted
  16.             (progn
  17.               (setq entity nil)                         ;in case was deleted
  18.               (princ "\nLast entity chosen can't be found, pick again.")
  19.             ) ;_progn
  20.           ) ;_if
  21.         )
  22.       ) ;_if
  23.     ) ;_progn
  24.   ) ;_if
  25.   (if (not entity) (setq entity (car (entsel "\nSelect entity: "))))
  26.   (if entity
  27.     (progn
  28.       (setq SAA_C:LP_ENTITY (cdr (assoc 5 (entget entity))))    ;remember for reuse
  29.       (while
  30.         (setq pt (getpoint "\nSelect point to draw perpendicular from: "))
  31.          (entmake (list '(0 . "LINE") (cons 10 (trans pt 1 0))
  32.             (cons 11 (vlax-curve-getClosestPointTo entity (trans pt 1 0)))) ;_ list
  33.          ) ;_ entmake
  34.       ) ;_ while
  35.     ) ;_progn
  36.   ) ;_if
  37.   (princ)
  38. ) ;_ defun
  39.  
  40. ;;;=========================================================================
  41. ;;; Return previous entity in order of creation
  42. ;;; entprev  -  Lee Mac 2013-11-22
  43. ;;;=========================================================================
  44. (defun entprev ( e1 / e2 h1 h2 )
  45.     (setq h1 (cdr (assoc 5 (entget (entnext))))
  46.           h2 (cdr (assoc 5 (entget e1)))
  47.     )
  48.     (if (/= h1 h2)
  49.         (while
  50.             (not
  51.                 (or (= h1 (setq h2 (hex-- h2)))
  52.                     (and (setq e2 (handent h2)) (entnext e2))
  53.                 )
  54.             )
  55.             (setq e2 nil)
  56.         )
  57.     )
  58.     e2
  59. )
  60.  

QuestionEverything

  • Guest
Re: Entity Handles
« Reply #10 on: September 26, 2016, 03:07:31 PM »
Okay guys, now theres finally a place where someone like me would understand them well enough - THIS THREAD.
Thank you all for the help!