Creating text inside rectangles at lower-right

Creating text inside rectangles at lower-right

Anonymous
Not applicable
1,351 Views
4 Replies
Message 1 of 5

Creating text inside rectangles at lower-right

Anonymous
Not applicable

I'm not a terribly proficient LISP writer, but I'm getting better...

 

I'm working on a LISP that will allow me to select rectangles and create a piece of text on a certain layer on their lower right bounds for an elaborate parsing system.

 

I've managed to make my selection filter and declare the text I want to create.

(defun C:HWEA ( / flt ss source_text n e1)
  (vl-load-com)                          ;load extended ActiveX just in case
  (setvar "CMDECHO" 1)                   ;I need a high level of verbosity during testing
  (prompt "\nSelect all racks - ")       ;set current layer to extended text layer
  (command "._layer" "_M" "G-ANNO-EXT-TEXT" "_Color" "4" "") ;create ext text layer 
(setvar "clayer" "G-ANNO-EXT-TEXT") ;set newly created layer to current (setq flt '((100 . "LWPOLYLINE") ;must be LWPOLYLINE (8 . "E-EQPM-RACK*") ;must be on a 'E-EQPM-RACK' layer (-4 . "<NOT") ;NOT FUTURE racks (8 . "E-EQPM-RACK-FUTURE") (-4 . "NOT>") (410 . "Model") ;only select objects in Model space ) );setq (setq ss (ssget flt)) ;selection set flt (setq source_text "H:100,D:42") ;text to create at each rectangle

 Attached a screenshot and DXF for my examples.

Any advice would be much appreciated.

0 Likes
Accepted solutions (1)
1,352 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor
Accepted solution

Its pretty easy to do there is an option bonding box that gets the lower left and upper right co-ordinates so you can then work out where you want the text to go.

;minpoint contains the minimum point of the bounding box
;maxpoint contains the maximum point of the bounding box

(defun c:al-getboundingbox ()
(vl-load-com)
(repeat (setq x (sslength ss)) 
(vla-GetBoundingBox (vlax-ename->vla-object(ssname ss (setq x (- x 1)))) 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))
(princ pointmin)
(princ "\n")
(princ pointmax)
(princ )
)
)
0 Likes
Message 3 of 5

ВeekeeCZ
Consultant
Consultant

To filter lwpolylines use code 0. Layers could be simpler...

 

(ssget '((0 . "LWPOLYLINE")       ;must be LWPOLYLINE
	 (8 . "E-EQPM-RACK*")       ;must be on a 'E-EQPM-RACK' layer
	 (8 . "~E-EQPM-RACK-FUTURE") ; but not this one
	 (410 . "Model")                ;only select objects in Model space
	))
0 Likes
Message 4 of 5

ronjonp
Mentor
Mentor

Have you thought about using an attributed block for this rather than separate components?

0 Likes
Message 5 of 5

Anonymous
Not applicable

@Sea-Haven - This is great, thank you. I managed to learn entmake and how to utilize this subroutine. I've got a lot of learning to do re: vl & vla calls.

 

@ВeekeeCZ - Thank you! That is cleaner and appreciate the DXF group code help.

 

@Anonymous - I wish I could do that easily. This is just one tool I'm working on of many that is part of 3rd party tool that parses metadata from my design files to populate a database.

 

Here was the finished subroutine.

(defun C:HDEA ( / flt ss sourceText pointMin pointMax ptx pty ptz insertionPoint) ;Height Depth Extended Attribute
  (vl-load-com)                        ;load extended ActiveX?
  (setvar "CMDECHO" 0)
  (command "._layer" "_M" "G-ANNO-EXT-TEXT" "_Color" "4" "") ;create ext text layer
  (setvar "clayer" "G-ANNO-EXT-TEXT")  ;set new layer to current
  (command "")
  (prompt "\nSelect all racks - ")     ;set current layer to extended text layer

  (setq flt '((0 . "LWPOLYLINE")       ;must be LWPOLYLINE
	      (8 . "E-EQPM-RACK*")     ;must be on a 'E-EQPM-RACK' layer
        (8 . "~E-EQPM-RACK-FUTURE")    ;NOT future racks
	      (410 . "Model")          ;only select objects in Model space
      )
	);flt setq
  (setq ss (ssget flt))                ;selection set flt
  (setq sourceText "H:100,D:42")       ;text to create at each rectangle

  (repeat (setq x (sslength ss))       ;repeat bounding box command
  (vla-GetBoundingBox (vlax-ename->vla-object(ssname ss (setq x (- x 1)))) 'minpoint 'maxpoint)
  (setq pointMin (vlax-safearray->list minpoint)) ;set minpoint x,y,z
  (setq pointMax (vlax-safearray->list maxpoint)) ;set maxpoint x,y,z
    (princ pointMin)
    (princ "\n")
    (princ pointMax)
    (princ)

    (setq ptX (car pointMin)) 		;separate coordinate list
    (setq ptY (cadr pointMin))
    (setq ptZ (caddr pointMin))
    (setq insertionPoint (list (1+ ptX) (1+ ptY) ptZ) ;; create new list w/translation
      )
    (entmake ;make text object for each bounding box
      (list
        (cons 0 "TEXT")     		;text obj
        (cons 10 insertionPoint) 	;offset insertion point
        (cons 40 1.5)       		;text height
        (cons 7 "1 048 (1 4  1')") 	;text style
        (cons 1 sourceText) 		;text value
        )
      ))
  (princ)
);defun
0 Likes