How can i write a lisp to extract the handle of an object and then paste it in the dwg?
![]() |
|
![]() |
|
![]() |
|
![]() |
How can i write a lisp to extract the handle of an object and then paste it in the dwg?
You'll probably get better help from the lisp forum.
John B
"You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan
Here:Code:(defun c:ShowHandle (/ en ed newtxt) (if (setq en (entsel "Pick object: ")) ;Ask user to select object (progn (setq ed (entget (car en))) ;Get data of object ;; Create new text object's data (setq newtxt (list '(0 . "TEXT") (assoc 10 ed) ;Insert point on the same os the object's 1st point (cons 1 (cdr (assoc 5 ed))) ;Text value as per object's handle (cons 40 (getvar "TEXTSIZE")) ;Text height as per default ) ;_ end of list ) ;_ end of setq (if (setq newtxt (entmake newtxt)) ;Create the text (alert (strcat "The object's handle [" (cdr (assoc 5 ed)) "] is now copied to a text object.\nUse last to select it." ) ;_ end of strcat ) ;_ end of alert (alert (strcat "There was an error creating the text.\nHowever, the entity's handle is:\n\n" (cdr (assoc 5 ed)) ) ;_ end of strcat ) ;_ end of alert ) ;_ end of if ) ;_ end of progn (princ "Canceled") ) ;_ end of if (princ) ) ;_ end of defun
Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!
Would it be possible to modify the Lisp to pick several objects and show the handle instead of 1 at a time?
Thanks
Christopher T. Cowgill, P.E.Autodesk Expert Elite
AEC Collection Civil 3D 2020
Windows 10
The lisp already places the text at the objects base point, why couldn't it cycle through each object to do the same thing. A program that I use to place location points on my drawing for hangers does this so it must be possible.
Christopher T. Cowgill, P.E.Autodesk Expert Elite
AEC Collection Civil 3D 2020
Windows 10
Melanie Stone
@MistresDorkness
ARCHIBUS, FMS/FMInteract and AutoCAD Expert (I use BricsCAD, Revit, & Tririga, too)
Technical Editornot all those who wander are lost
Something like this:Much reduced and not tested much, but should do a lot similar to my earlier code - only that alert is omitted since i don't think you want a dialog popping up for each entity selected.Code:(defun c:PlaceHandles (/ ss n ed sz) (setq sz (getvar 'TextSize)) (prompt "Select objects: ") (if (and (setq ss (ssget)) (setq n (sslength ss))) (while (>= (setq n (1- n)) 0) (setq ed (entget (ssname ss n))) (entmake (list '(0 . "TEXT") (assoc 10 ed) (cons 1 (cdr (assoc 5 ed))) (cons 40 sz) ) ) ) ) (princ) )
Note this is a really basic code. The text would always be placed on Layer 0, and no accommodation for annotative or any such, also the MS / PS tab is disregarded. I still can't really figure what use a handle is for the normal acad user though, but it's possible to show of course.
Last edited by irneb; 2012-03-03 at 05:43 AM.
Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!
Excuse me if this sounds "harsh" ... but what do you actually want with the handle? To me it seems rather useless to have a hexadecimal number displayed for each object. It doesn't read well for a human, its only use is to uniquely identify each object in the drawing - and in most cases only for a program. Thus I can much more easily see uses for a defun returning a list of handles, than for one creating text of displaying these handles in a dialog / text screen.
Now if you want it the other way round: Say you've got a txt file exported through AttOut and you want to find the block reference with a handle "ABC". Then look for the built-in lisp function handent.
Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!