这应该给你一些思考的东西。。。
- (defun c:BlockNames (/ #SS)
- (cond
- ((setq #SS (ssget '((0 . "INSERT"))))
- (or *AcadDoc*
- (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))
- ) ;_ or
- (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
- (AT:Mtext (vla-get-insertionpoint x)
- (if (vlax-property-available-p x 'EffectiveName)
- (vla-get-effectivename x)
- (vla-get-name x)
- ) ;_ if
- 0
- (vla-get-layer x)
- 5
- ) ;_ AT:Mtext
- ) ;_ vlax-for
- (vla-delete #SS)
- )
- ) ;_ cond
- (princ)
- ) ;_ defun
您将需要此接头:
- ;;; Add MText to drawing
- ;;; #InsertionPoint - MText insertion point
- ;;; #String - String to place in created MText object
- ;;; #Width - Width of MText object (if nil, will be 0 width)
- ;;; #Layer - Layer to place Mtext object on (nil for current)
- ;;; #Justification - Justification # for Mtext object
- ;;; 1 or nil= TopLeft
- ;;; 2= TopCenter
- ;;; 3= TopRight
- ;;; 4= MiddleLeft
- ;;; 5= MiddleCenter
- ;;; 6= MiddleRight
- ;;; 7= BottomLeft
- ;;; 8= BottomCenter
- ;;; 9= BottomRight
- ;;; Alan J. Thompson, 05.23.09
- (defun AT:MText (#InsertionPoint #String #Width #Layer #Justification / #Width
- #Space #Insertion #Object
- )
- (or #Width (setq #Width 0))
- (or *AcadDoc*
- (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))
- ) ;_ or
- (setq #Space (if (or (eq acmodelspace
- (vla-get-activespace *AcadDoc*)
- ) ;_ eq
- (eq :vlax-true (vla-get-mspace *AcadDoc*))
- ) ;_ or
- (vla-get-modelspace *AcadDoc*)
- (vla-get-paperspace *AcadDoc*)
- ) ;_ if
- #Insertion (cond
- ((vl-consp #InsertionPoint) (vlax-3d-point #InsertionPoint))
- ((eq (type #InsertionPoint) 'variant) #InsertionPoint)
- (T nil)
- ) ;_ cond
- ) ;_ setq
- ;; create MText object
- (setq #Object (vla-addmtext #Space #Insertion #Width #String))
- ;; change layer, if applicable
- (and #Layer
- (tblsearch "layer" #Layer)
- (vla-put-layer #Object #Layer)
- ) ;_ and
- ;; change justification & match insertion point with new justification
- (cond ((member #Justification (list 1 2 3 4 5 6 7 8 9))
- (vla-put-attachmentpoint #Object #Justification)
- (vla-move #Object
- (vla-get-InsertionPoint #Object)
- #Insertion
- ) ;_ vla-move
- )
- ) ;_ cond
- #Object
- ) ;_ defun
|