Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Lisp to extract Handle

  1. #1
    Member
    Join Date
    2008-03
    Posts
    7
    Login to Give a bone
    0

    Default Lisp to extract Handle

    How can i write a lisp to extract the handle of an object and then paste it in the dwg?

  2. #2
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    You'll probably get better help from the lisp forum.

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    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

  4. #4
    Member
    Join Date
    2008-05
    Posts
    3
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    Would it be possible to modify the Lisp to pick several objects and show the handle instead of 1 at a time?
    Thanks

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    Quote Originally Posted by dmccann.183909 View Post
    Would it be possible to modify the Lisp to pick several objects and show the handle instead of 1 at a time?
    Thanks
    how would you know which handle belongs to which object?

  6. #6
    Member
    Join Date
    2008-05
    Posts
    3
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    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.

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    Quote Originally Posted by dmccann.183909 View Post
    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.
    Sorry, I didnt actually read the lisp routine. After looking at it, you could use the ssget function, with a while loop to cycle through each selected object.

  8. #8
    Mod / Salary / SM Wanderer's Avatar
    Join Date
    2001-12
    Location
    St. Louis
    Posts
    5,406
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    Quote Originally Posted by jaberwok View Post
    You'll probably get better help from the lisp forum.
    I've moved this thread from the General forum to the lisp forum.

    Cheers.
    Melanie Stone
    @MistresDorkness

    Archibus, FMS/FMInteract and AutoCAD Expert (I use BricsCAD, Revit, Tandem, and Planon, too)
    Technical Editor
    not all those who wander are lost

  9. #9
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    Quote Originally Posted by Ducky View Post
    Would it be possible to modify the Lisp to pick several objects and show the handle instead of 1 at a time?
    Thanks
    Something like this:
    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)
    )
    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.

    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.

  10. #10
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Lisp to extract Handle

    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.

Page 1 of 2 12 LastLast

Similar Threads

  1. Extract the radius of a 3D cylinder using LISP?
    By Cadapult in forum AutoLISP
    Replies: 10
    Last Post: 2018-10-14, 05:11 PM
  2. Lisp for Handle
    By tguy in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-11, 02:08 AM
  3. Create lisp to extract data from excel file
    By Lions60 in forum AutoLISP
    Replies: 7
    Last Post: 2008-01-30, 04:32 AM
  4. Replies: 5
    Last Post: 2007-04-30, 08:14 PM
  5. Lisp to extract and add numbers from text/mtext string
    By cblendermann.91943 in forum AutoLISP
    Replies: 26
    Last Post: 2005-08-18, 03:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •