TheSwamp

CAD Forums => CAD General => Topic started by: MSTG007 on June 01, 2015, 08:38:01 AM

Title: Macro Replace Text with Field
Post by: MSTG007 on June 01, 2015, 08:38:01 AM
Has anyone seen a way to select an MTEXT and then click a button or command that will insert the SheetSet Title to replace the Mtext value?
Thanks
Title: Re: Macro Replace Text with Field
Post by: ronjonp on June 01, 2015, 08:56:29 AM
I believe all you have to do is replace your text with: %<\AcSm Sheet.Title>% 
All of the Field Expressions are readily available at the bottom of the Field dialog box.
Title: Re: Macro Replace Text with Field
Post by: ChrisCarlson on June 01, 2015, 09:08:00 AM
I don't think macro's can change the value of a mtext entity.

Code: [Select]
(defun c:TextChange (/ a b)
  (vl-load-com)
  (while T
      (setq a
(car
             (nentsel "\nSelect text or mtext entity to change")))
(if (or a
(setq b(entget a))
(= (cdr (assoc 0 b)) "TEXT")
(= (cdr (assoc 2 b)) "MTEXT")
) ; end check
        (vla-put-TextString(vlax-ename->vla-object a) "%<\AcSm Sheet.Title>% ")
        (princ "\n Invalid Selection")
        ); end if
) ; end while
   (princ)
 ); end
 

Quick and dirty.
Title: Re: Macro Replace Text with Field
Post by: mjfarrell on June 01, 2015, 09:56:03 AM
alternately replace that text with an attribute in the title block, block....then let that attribute be a field....
attsync...and save/resave all sheets should accomplish the desired result
Title: Re: Macro Replace Text with Field
Post by: MSTG007 on June 01, 2015, 10:28:58 AM
I don't think macro's can change the value of a mtext entity.

Code: [Select]
(defun c:TextChange (/ a b)
  (vl-load-com)
  (while T
      (setq a
(car
             (nentsel "\nSelect text or mtext entity to change")))
(if (or a
(setq b(entget a))
(= (cdr (assoc 0 b)) "TEXT")
(= (cdr (assoc 2 b)) "MTEXT")
) ; end check
        (vla-put-TextString(vlax-ename->vla-object a) "%<\AcSm Sheet.Title>% ")
        (princ "\n Invalid Selection")
        ); end if
) ; end while
   (princ)
 ); end
 

Quick and dirty.

Well I did try the above and I get the famous (####). When I double click on the field it shows as (UNKNOWN) at the top left of the dialogue box Field Category. Other than that, its great.
Title: Re: Macro Replace Text with Field
Post by: mjfarrell on June 01, 2015, 10:58:22 AM
is this sheet part of a set?

if not then one should expect ####
Title: Re: Macro Replace Text with Field
Post by: MSTG007 on June 01, 2015, 11:01:59 AM
It is part of a sheet set. I just tried the command, saved the file, closed it and then thru the sheetset manager I re-opened the sheet. There still is the famous (####). Version of CAD shouldn't matter right?
Title: Re: Macro Replace Text with Field
Post by: ronjonp on June 01, 2015, 11:15:04 AM
Just a quick look but the entity check will never be evaluated in the code above using OR:
Code - Auto/Visual Lisp: [Select]
  1. (or a (setq b (entget a)) (= (cdr (assoc 0 b)) "TEXT") (= (cdr (assoc 2 b)) "MTEXT")) ; end check
Instead I'd use:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch (cdr (assoc 0 (entget a))) "*TEXT")
Title: Re: Macro Replace Text with Field
Post by: MSTG007 on June 01, 2015, 11:21:38 AM
Thanks for checking that out. I think I found the issue. In the lisp above it calls for the full "%<\AcSm Sheet.Title>%". But when I go to edit the field it shows the field expression as "%<AcSm Sheet.Title>%" without the (\) in it.
Title: Re: Macro Replace Text with Field
Post by: ronjonp on June 01, 2015, 11:23:11 AM
Use: "%<\\AcSm Sheet.Title>%"
Title: Re: Macro Replace Text with Field
Post by: MSTG007 on June 01, 2015, 11:27:22 AM
Guess what. Solved! works awesome.
Title: Re: Macro Replace Text with Field
Post by: ChrisCarlson on June 01, 2015, 01:50:44 PM
Derp, was too early in the morning  :embarrassed2:
Title: Re: Macro Replace Text with Field
Post by: MSTG007 on June 01, 2015, 01:52:45 PM
lol. Thanks though