TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on November 30, 2004, 07:42:06 AM

Title: Question of the day #4
Post by: Mark on November 30, 2004, 07:42:06 AM
Write the necessary code to return the entity type of that selected.

pseudo code:
prompt the user> Select an entity
determine entity type and save in variable 'typ'
return to the user> The entity you selected is of type 'typ'
Title: Question of the day #4
Post by: Keith™ on November 30, 2004, 09:36:35 AM
HUH? No takers?
Title: Question of the day #4
Post by: David Bethel on November 30, 2004, 09:58:47 AM
this is taken from a program I wrote in the '90s and keep modifing it as ACAD evolves.  -David

Code: [Select]
(defun c:info (/ ss en ed)
  (while (or (not ss)
             (> (sslength ss) 1))
         (princ "\nSelect An Entity To Describe:   ")
         (setq ss (ssget)))
  (setq en (ssname ss 0)
        ed (entget en))
  (textpage)
  (princ "\nSelected Entity  ")
  (prin1 en)
  (terpri)
  (princ (strcat "\nType (0) = "
               (cdr (assoc 0 ed))))
  (if (assoc 1 ed)
      (princ (strcat "\nText (1) = " (cdr (assoc 1 ed)))))
  (if (assoc 2 ed)
      (princ (strcat "\nName (2) = " (cdr (assoc 2 ed)))))
  (princ (strcat "\nHandle (5) = "
               (if (assoc 5 ed)
                   (cdr (assoc 5 ed))
                   "Disabled")))
  (princ (strcat "\nLinetype (6) = "
               (if (assoc 6 ed)
                   (cdr (assoc 6 ed))
                   "ByLayer")))
  (if (assoc 7 ed)
      (princ (strcat "\nStyle (7) = " (cdr (assoc 7 ed)))))
  (princ (strcat "\nLAyer (8) = "
               (cdr (assoc 8 ed))))
  (princ (strcat "\nThickness (39) = "
               (if (assoc 39 ed)
                   (rtos (cdr (assoc 39 ed)) 2)
                   "0.0")))
  (princ (strcat "\nLTScale (48) = "
               (if (assoc 48 ed)
                   (rtos (cdr (assoc 48 ed)) 2)
                   "1.0")))
  (princ (strcat "\nVisibilty (60) = "
               (cond ((not (assoc 60 ed))         "Visible")
                     ((zerop (cdr (assoc 60 ed))) "Visible")
                     (T                         "Invisible"))))
  (princ (strcat "\nColor (62) = "
               (cond ((not (assoc 62 ed))         "ByLayer")
                     ((zerop (cdr (assoc 62 ed))) "ByBlock")
                     (T           (itoa (cdr (assoc 62 ed)))))))
  (princ (strcat "\nSpace (67) = "
               (cond ((not (assoc 67 ed))         "ModelSpace")
                     ((= (cdr (assoc 67 ed)) 0)   "ModelSpace")
                     (T                           "PaperSpace"))))
  (princ (strcat "\nUCS (210) = "
               (cond ((not (assoc 210 ed))         "WCS")
                     ((equal (cdr (assoc 210 ed))
                             '(0 0 1) 1e-11)       "WCS")
                     (T                            "OCS"))))

(prin1))

Title: Question of the day #4
Post by: ImaJayhawk on November 30, 2004, 10:29:32 AM
Code: [Select]

(setq typ (cdr (assoc 0 (entget (car (entsel "\nSelect Object:   "))))))
(princ (strcat "The entity you selected is of type " typ))





--ImaJayhawk
Title: Question of the day #4
Post by: ImaJayhawk on November 30, 2004, 10:36:58 AM
Code: [Select]

(vl-load-com)
(setq typ (vlax-get-property (vlax-ename->vla-object (car (entsel)))'objectname))
(princ (strcat "The entity you selected is of type " typ))



--ImaJayhawk