Results 1 to 1 of 1

Thread: General Function for converting entitynames, entitylists, handles, entsels, handles, objectid's to an object

  1. #1
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default General Function for converting entitynames, entitylists, handles, entsels, handles, objectid's to an object

    In my libraries I like to have general functions to perform common processes.

    Here is one that I thought you all might appreciate.

    Converting stuff to vla-objects

    Comments?

    P=


    Code:
    ;___________________________________________________________________________________________________________
    ; 
    ; The Object function converts objects, dotted pairs, entitynames, entitylists, handles or objectid's to
    ; object references. Returns nil if unsuccessful.
    ; Written By: Peter Jamtgaard copyright 2014 all rights reserved.
    ;___________________________________________________________________________________________________________
    
    (defun Object (value)
     (if (or 
          (= (type value) 'vla-object)
          (and 
           (or
            value
            (setq value (entsel "\nSelect object: "))
           )
           (or   
            (and  ; Entsel
             (= (type value) 'LIST)
             (= (type (car value)) 'ENAME)
             (setq value (car value))
            )
            (and  ; Dotted Pair
             (= (type value) 'LIST)
             (/= (type (cdr value)) 'LIST)
             (setq value (cdr value))
            )
            (and  ; Ename
             (= (type value) 'ENAME)      
             (setq value (vlax-ename->vla-object value))
            )
            (and  ; Entity List
             (= (type value) 'LIST)
             (= (type (car value)) 'LIST)
             (setq value (car value))
            )
            (and  ; Handle
             (= (type value) 'STR)
             (setq value (handent value))         
             (entget value)
            )
            (and  ; ObjectID 
             (= (type value) 'INT)
             (= (strlen (itoa value)) 10)         
             (setq value (errortrap '(vla-objectidtoobject 
                                      (vla-get-activedocument 
                                       (vlax-get-acad-object)) 
                                      value )))
            )
            
           )
           (setq value (object value))
           
          )
         )
      value 
     )
    )
    
    ; General Error Trapping function
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (X)(set X (eval symFunction)))
                          (list 'result))))
      nil
      (if result result 'T)
     )
    )
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2014-12-29 at 08:20 AM.
    AutomateCAD

Similar Threads

  1. Help with Handles!
    By dupuy77362646 in forum AutoLISP
    Replies: 11
    Last Post: 2013-03-03, 10:52 PM
  2. Changing object handles
    By yellowplanet in forum AutoCAD General
    Replies: 11
    Last Post: 2008-03-20, 06:16 PM
  3. Knobs and Handles
    By checkpost100 in forum AutoCAD Gallery
    Replies: 10
    Last Post: 2005-10-12, 08:45 PM
  4. Entities and Handles
    By jason907238 in forum VBA/COM Interop
    Replies: 4
    Last Post: 2004-09-23, 10:03 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
  •