BTW Tiger, I wrote this a while back, may be of use:
- ;;------------------------=={ Tag }==-------------------------;;;; ;;;; Prompts the user for a tag prefix and starting tag number ;;;; then proceeds to add tag blocks with incrementing tag ;;;; attribute until the user fails to pick a tag point. ;;;; ;;;; Tag block is created if non-existent. Tag Block layers ;;;; are created if non-existent. ;;;;------------------------------------------------------------;;;; Author: Lee McDonnell, 2010 ;;;; ;;;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;;;------------------------------------------------------------;;(defun c:tag ( / *error* ATT BL BLK BNME DEF DOC P1 P2 PR SCL SPC ) (vl-load-com) ;; © Lee Mac 2010 (setq bNme "TAG" scl (cond ( (zerop (getvar 'DIMSCALE)) 1. ) ( (getvar 'DIMSCALE) ))) (defun *error* ( msg ) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (LM:ActiveSpace 'doc 'spc) (if (not (LM:Itemp (setq blk (vla-get-Blocks doc)) bNme)) (progn (setq def (vla-Add blk (vlax-3D-point '(0. 0. 0.)) bNme)) (vla-put-layer (vla-AddCircle def (vlax-3D-point '(0. 0. 0.)) 5.) "0") (setq att (vla-AddAttribute def 2.5 0 "Tag Number: " (vlax-3D-point '(0. 0. 0.)) "TNO" "N1")) (vla-put-layer att "0") (vla-put-Alignment att acAlignmentMiddleCenter) ) ) (foreach l '("2" "5") (or (tblsearch "LAYER" l) (vla-Add (vla-get-layers doc) l))) (setq pr (getstring t "\nSpecify Tag Prefix: ")) (setq *tag* (cond ( (getint (strcat "\nSpecify Tag Number : " ) ) ) ( *tag* ) ) ) (while (and (setq p1 (getpoint "\nSpecify First Point : ")) (setq p2 (getpoint (strcat "\nSpecify Point for Tag (" pr (itoa *tag*) ") : ") p1))) (vla-put-Layer (vla-AddLine spc (vlax-3D-point (trans p1 1 0)) (vlax-3D-point (trans (polar p2 (angle p2 p1) (* 5.0 scl)) 1 0)) ) "5" ) (setq bl (vla-InsertBlock spc (vlax-3D-point (trans p2 1 0)) bNme scl scl scl 0.)) (vla-put-layer bl "2") (mapcar (function (lambda ( att ) (if (eq "TNO" (vla-get-TagString att)) (vla-put-TextString att (strcat pr (itoa *tag*))) ) ) ) (vlax-invoke bl 'GetAttributes) ) (setq *tag* (1+ *tag*)) ) (princ));;-----------------------=={ Itemp }==------------------------;;;; ;;;; Retrieves the item with index 'item' if present in the ;;;; specified collection, else nil ;;;;------------------------------------------------------------;;;; Author: Lee McDonnell, 2010 ;;;; ;;;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;;;------------------------------------------------------------;;;; Arguments: ;;;; coll - the VLA Collection Object ;;;; item - the index of the item to be retrieved ;;;;------------------------------------------------------------;;;; Returns: the VLA Object at the specified index, else nil ;;;;------------------------------------------------------------;;(defun LM:Itemp ( coll item ) ;; © Lee Mac 2010 (if (not (vl-catch-all-error-p (setq item (vl-catch-all-apply (function vla-item) (list coll item) ) ) ) ) item ));;--------------------=={ ActiveSpace }==---------------------;;;; ;;;; Retrieves pointers to the Active Document and Space ;;;;------------------------------------------------------------;;;; Author: Lee McDonnell, 2010 ;;;; ;;;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;;;------------------------------------------------------------;;;; Arguments: ;;;; *doc - quoted symbol other than *doc ;;;; *spc - quoted symbol other than *spc ;;;;------------------------------------------------------------;;(defun LM:ActiveSpace ( *doc *spc ) ;; © Lee Mac 2010 (set *spc (if (or (eq AcModelSpace (vla-get-ActiveSpace (set *doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ) (eq :vlax-true (vla-get-MSpace (eval *doc))) ) (vla-get-ModelSpace (eval *doc)) (vla-get-PaperSpace (eval *doc)) ) ))
|