Message 1 of 11
Routine for Creating Equipment Tags with EQ and # Attributes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Select two MTEXT entities interactively in AutoCAD.
- Create a single block called "equiptag" with two attributes: "EQ" and "#."
- Assign the text content from the first selected MTEXT entity to the "EQ" attribute.
- Assign the text content from the second selected MTEXT entity to the "#" attribute.
- Erase the selected MTEXT entities after extracting their content.
(defun c:f11 (/ sel int ent att spc ang eqText noteText)
;; Tharwat - Date: 19.Jun.2017 ;;
(setq Size1 (getvar "dimscale"))
(if
(and
(or (tblsearch "BLOCK" "equiptag")
(alert "Attributed Block <equiptag> is not found in drawing <!>")
)
(setq sel (ssget)) ; Allow the user to select MTEXT entities interactively
)
(progn
(defun unformatmtext (string / text str)
;; ASMI - sub-function ;;
;; Get string from Formatted Mtext string ;;
(setq text "")
(while (/= string "")
(cond ((wcmatch (strcase (setq str (substr string 1 2)))
"\\[\\{}`~]"
)
(setq string (substr string 3)
text (strcat text str)
)
)
((wcmatch (substr string 1 1) "[{}]")
(setq string (substr string 2))
)
((and (wcmatch (strcase (substr string 1 2)) "\\P")
(/= (substr string 3 1) " ")
)
(setq string (substr string 3)
text (strcat text " ")
)
)
((wcmatch (strcase (substr string 1 2)) "\\[LOP]")
(setq string (substr string 3))
)
((wcmatch (strcase (substr string 1 2)) "\\[ACFHQTW]")
(setq string (substr string
(+ 2 (vl-string-search ";" string))
)
)
)
((wcmatch (strcase (substr string 1 2)) "\\S")
(setq str (substr string 3 (- (vl-string-search ";" string) 2))
text (strcat text (vl-string-translate "#^\\" " " str))
string (substr string (+ 4 (strlen str)))
)
(print str)
)
(t
(setq text (strcat text (substr string 1 1))
string (substr string 2)
)
)
)
)
text
)
(setq spc
(vlax-get (vla-get-activelayout
(vla-get-activedocument (vlax-get-acad-object))
)
'block
)
)
(repeat (setq int (sslength sel))
(setq ent (ssname sel (setq int (1- int))))
(setq ang (cdr (assoc 50 (entget ent)))) ;; get the Mtext Angle (in radians) and set it to the variable ang
;; Prompt for EQ and # values
(setq eqText (unformatmtext (cdr (assoc 1 (entget ent)))))
(setq noteText "")
(if (= int 1)
(setq eqText (unformatmtext (cdr (assoc 1 (entget ent)))))
(setq noteText (unformatmtext (cdr (assoc 1 (entget ent)))))
)
(and (setq att (vla-insertblock
spc
(vlax-3d-point (cdr (assoc 10 (entget ent))))
"equiptag"
Size1
Size1
Size1
ang ;; the block rotation from the Mtext rotation
)
)
(vl-some
'(lambda (x)
(if (or (eq (strcase (vla-get-tagstring x)) "EQ")
(eq (strcase (vla-get-tagstring x)) "#"))
(progn (vla-put-textstring
x
(if (eq (strcase (vla-get-tagstring x)) "EQ")
eqText ; Set the EQ attribute to eqText
noteText ; Set the # attribute to noteText
)
)
t
)
)
)
(vlax-invoke att 'getattributes)
)
(progn (vla-put-layer att (cdr (assoc 8 (entget ent)))) t)
(entdel ent)
)
)
)
)
)
When I run this I get two blocks one with the value for "EQ " and one with the value for "#" in the place of "EQ"
(SEE JPG)
Can someone help me out?