TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on January 03, 2007, 11:02:30 AM

Title: text style replacement
Post by: Andrea on January 03, 2007, 11:02:30 AM
Hi all,...

first, best wishes for 2007..   :-)

Is there any way to select all text and mtext in the entire drawing including in block, layout, and model space ?

I need to do this:
I have many diffrent text style and need to purge all them and keep only 1.
so I think i need to select all text by filtering them en change style.
But if you have any other idea....i'll keep it !

thanks.
Title: Re: text style replacement
Post by: T.Willey on January 03, 2007, 11:18:10 AM
The best way (I think) is to search the block collection, filtering out xrefs, and the checking for text, mtext, attribute references, attribute definitions, constant attributes and tables.  Tables and Mtext you will have to search the string also, because they can have style overrides within the string.  This is how I would do it.
Title: Re: text style replacement
Post by: Andrea on January 03, 2007, 12:36:07 PM
thanks.... T.Willy..

I was hoping using somting like...

Code: [Select]
  (vlax-for style
    (vla-get-textstyles  (vla-get-activedocument (vlax-get-acad-object)))
            (vla-put-textstyle style "simplex.SHX")
  )
Title: Re: text style replacement
Post by: T.Willey on January 03, 2007, 12:44:59 PM
That is not changing the text style of objects, that is changing the font of a text style.  If that is what you want to do, then you can step through the text style collection of a document, and change them from there.
Code: [Select]
(vlax-for Sty (vla-get-TextStyles (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (vla-put-fontFile Sty "simplex.shx")
)
Title: Re: text style replacement
Post by: Andrea on January 03, 2007, 01:20:30 PM
ok....thanks...

but how can I use
Code: [Select]
vla-put-textstyle ?
I can't see any exemple on the web..
Title: Re: text style replacement
Post by: LE on January 03, 2007, 01:38:40 PM
OK...

Convert the selection (of text and mtexts) to vla-objects, then use the below code to change the object to the desired textstyle.

(vla-put-stylename obj "style1")


HTH
Title: Re: text style replacement
Post by: Andrea on January 03, 2007, 03:49:02 PM
thanks LE..

Code: [Select]
(setq ss1 (ssget "X" '((0 . "MTEXT,TEXT"))))
(setq sscount (sslength ss1))
(setq val1 (- sscount 1))
(repeat sscount
(setq ent (vlax-ename->vla-object (ssname ss1 val1)))
(vla-put-stylename ent "SIMPLEX")
(setq val1 (- val1 1))
)

Now all I need to do is to verify Attribute and text in existing block..
Title: Re: text style replacement
Post by: T.Willey on January 03, 2007, 03:57:47 PM
Now all I need to do is to verify Attribute and text in existing block..
Look at my first response as to how to do this.  Once you do it the way I explained, then you won't need the other code you posted.
Title: Re: text style replacement
Post by: ronjonp on January 03, 2007, 04:22:02 PM
Here is a nice description.......hey it's by TWilley :)

http://www.theswamp.org/index.php?topic=12437.msg154308#msg154308
Title: Re: text style replacement
Post by: LE on January 03, 2007, 04:37:43 PM
Now all I need to do is to verify Attribute and text in existing block..
Look at my first response as to how to do this.  Once you do it the way I explained, then you won't need the other code you posted.

Tim;

Maybe it is me, or something in my poor English translation.... but I understood something different... like he wants to select the text,mtext and the inserts.... or I am out of my mind now?, if I am, it will my last post about lisp here, I promissed -  :ugly:

Title: Re: text style replacement
Post by: T.Willey on January 03, 2007, 04:50:37 PM
Now all I need to do is to verify Attribute and text in existing block..
Look at my first response as to how to do this.  Once you do it the way I explained, then you won't need the other code you posted.

Tim;

Maybe it is me, or something in my poor English translation.... but I understood something different... like he wants to select the text,mtext and the inserts.... or I am out of my mind now?, if I am, it will my last post about lisp here, I promissed -  :ugly:


Luis,

This is the line that makes me think it is more that just selecting text and mtext
Quote from: Andrea
Is there any way to select all text and mtext in the entire drawing including in block, layout, and model space ?
And I hope you don't stop posting in the lisp section.  You are a tremendous help here.  Many people still don't know what you know about lisp.

Here is a nice description.......hey it's by TWilley :)

http://www.theswamp.org/index.php?topic=12437.msg154308#msg154308
Thanks Ron.  I forgot I did that.  :-D  This will help with the basic idea, but what Andrea is after is a little different, but this shows how to go through the block collections.
Title: Re: text style replacement
Post by: CAB on January 03, 2007, 06:21:08 PM
This is what Andrea said:
Quote
I need to do this:
I have many different text style and need to purge all them and keep only 1.
The way I read it is he wants all text styles deleted & only one left in the drawing.
This takes way more work. You need to change dimension styles & overrides, Fileds,
attributes, tables, text within blocks, plain text, and mtext. Did I miss anything?
Only the xrefs would be exempt from the process.
Title: Re: text style replacement
Post by: Andrea on January 03, 2007, 10:25:25 PM
Sorry guys....

My english seem to be not better than 2006 !

In fact,...I need to keep all existing text, including text and/or attribute in block,
and change the style.

something like...
Code: [Select]
(vlax-PUT-ALLTEXTSTYLE "SIMPLEX")
Title: Re: text style replacement
Post by: Kerry on January 03, 2007, 10:52:44 PM
"SIMPLEX" is a FontName

Do you mean change the 'TextStyle' or change the 'FontName'

I dont think the problem is your English.
Title: Re: text style replacement
Post by: Kerry on January 03, 2007, 10:57:00 PM
You mentioned
Quote
purge all them and keep only 1

.. is this still the case ?


Here's a thought .. If you were to do this process by hand how would you do it .. exactly.
Then we will know what result you want .. exactly.
Title: Re: text style replacement
Post by: Andrea on January 03, 2007, 11:14:37 PM
Hi Kerry, and thanks for the reply...

you'r right....SIMPLEX is a font name....but can be also the style name.
we work with many clients standards here...
so we are trying to make something easy for CAD user,..

STYLE NAME = FONT NAME here..

because to many architect use the something like..
STYLENAME = ARIAL
FONTNAME = SIMPLEX

see ?


there is what i was able to do with your appreciated help guys...
Code: [Select]
(defun c:test (/ ActDoc Obj Blk)
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for Blk (vla-get-Blocks ActDoc)
  (vlax-for Obj Blk
   (if
    (or
     (= (vla-get-ObjectName Obj) "AcDbText")
     (= (vla-get-ObjectName Obj) "AcDbAttributeDefinition")
    )
    (vla-put-stylename Obj "SIMPLEX")
   )
   (vla-put-layer Obj "0")
  )
 )
(princ)
)

this code seem to work.....
the problem is the block is good when inserting new one..
but all the existing are not updated.
is this in the code ?
Title: Re: text style replacement
Post by: Patrick_35 on January 04, 2007, 09:37:11 AM
Hi
And with this

Code: [Select]
(defun c:test (/ Att ActDoc att Obj Blk n tot)
  (vl-load-com)
  (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)) tot 0 n 0)
  (vlax-for Blk (vla-get-Blocks ActDoc)
    (setq tot (+ tot (vla-get-count blk)))
  )
  (acet-ui-progress-init "Traitement" tot)
  (vlax-for Blk (vla-get-Blocks ActDoc)
    (vlax-for Obj Blk
      (setq n (1+ n))(setq aa obj)
      (acet-ui-progress-safe n)
      (if  (member (vla-get-ObjectName Obj) '("AcDbText" "AcDbMText" "AcDbAttributeDefinition"))
        (vl-catch-all-apply 'vla-put-stylename (list Obj "SIMPLEX"))
      )
      (if (eq (vla-get-objectname Obj) "AcDbBlockReference")
        (if (eq (vla-get-hasattributes Obj) :vlax-true)
          (foreach Att (vlax-invoke Obj 'getattributes)
            (vl-catch-all-apply 'vla-put-stylename (list Att "SIMPLEX"))
          )
        )
      )
      (vla-put-layer Obj "0")
    )
  )
  (acet-ui-progress-done)
  (princ)
)

Amicalement

@+
Title: Re: text style replacement
Post by: Andrea on January 04, 2007, 10:01:01 AM
Bonne année Patrick..

Thanks for the help.

acet-ui-progress.....nice initiative !

I forgot the
Code: [Select]
"AcDbMText" Oops..

what is
Code: [Select]
(setq aa obj) for ?
Title: Re: text style replacement
Post by: Patrick_35 on January 04, 2007, 10:21:02 AM
Merci, à toi aussi et surtout bonne santé  :-)

Code: [Select]
(setq aa obj) It's for my tests. I forgot to remove it  :roll:

@+
Title: Re: text style replacement
Post by: Andrea on January 04, 2007, 10:58:10 AM
Thanks.   :roll:

ok..

can anyone help me to finalise the routine..with this :
Code: [Select]
(vlax-for style (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
   (if
     (and
      (= (strcase (vla-get-stylename style)) "SIMPLEX") ;;this line not working..     
      (/= (strcase (vla-get-fontfile style)) "SIMPLEX.SHX")
     )
    (vla-put-fontfile style "SIMPLEX.SHX")
   )
)
Title: Re: text style replacement
Post by: CAB on January 04, 2007, 11:14:01 AM
How about this vla-get-textfontstyle
Title: Re: text style replacement
Post by: Andrea on January 04, 2007, 11:28:53 AM
How about this vla-get-textfontstyle

??  :?

not sure to understand..
vla-get-stylename is not to get the textstyle ?
Title: Re: text style replacement
Post by: T.Willey on January 04, 2007, 11:30:52 AM
Thanks.   :roll:

ok..

can anyone help me to finalise the routine..with this :
Code: [Select]
(vlax-for style (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
   (if
     (and
      (= (strcase (vla-get-stylename style)) "SIMPLEX") ;;this line not working..     
      (/= (strcase (vla-get-fontfile style)) "SIMPLEX.SHX")
     )
    (vla-put-fontfile style "SIMPLEX.SHX")
   )
)

You shouldn't need this.  Once you change all the objects that depend on text styles, just delete the styles you don't want.

If you want to use something like this, then when you are stepping through the text style collection, you only need to check the 'Name' property, not 'StyleName' as that is only available on objects that use text objects.

The routine Patrick gave you is pretty close to what you want, but he doesn't check for 'Constant Attributes' within blocks, and nothing about 'Tables' or 'Dimensions', and nothing about text style overrides within 'Mtext' or 'Tables'.
Title: Re: text style replacement
Post by: CAB on January 04, 2007, 11:54:32 AM
Oh, I see, he is making sure Style SIMPLES uses the font file SIMPLEX.SHX

So as Tim said, this is what you need:
Code: [Select]
(= (strcase (vla-get-name style)) "SIMPLEX")
Title: Re: text style replacement
Post by: VVA on January 04, 2007, 12:03:50 PM
Corrected code Patrick_35. Checks property StyleName and TextStyle of object
Code: [Select]
(defun c:test (/ Att ActDoc att Obj Blk n tot)
  (vl-load-com)
  (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)) tot 0 n 0)
  ;_Unlock Layers
  (vlax-for lay (vla-get-layers ActDoc)
    (vla-put-Lock lay :vlax-false)
    (vl-catch-all-apply 'vla-put-Freeze (list lay :vlax-false))
    )
  (vla-put-ActiveLayer ActDoc (vla-item (vla-get-layers ActDoc) "0"))
  (vlax-for Blk (vla-get-Blocks ActDoc)
    (setq tot (+ tot (vla-get-count blk)))
  )
  ;_Make TextStyle
  (mapcar (function (lambda ( _font  / text_style)
(setq text_style  (vla-add (vla-get-textstyles ActDoc) _font))
(vla-put-fontfile text_style "SIMPLEX.SHX")
(vla-put-height text_style 0.0)
(vla-put-width text_style 1.0)
        (vla-put-activetextstyle ActDoc text_style)))
'("SIMPLEX"))
  (acet-ui-progress-init "Traitement" tot)
  (vlax-for Blk (vla-get-Blocks ActDoc)
    (vlax-for Obj Blk
      (setq n (1+ n))
      (acet-ui-progress-safe n)
      (cond
((vlax-property-available-p Obj 'TextStyle) ;_DIMENSION
(vl-catch-all-apply 'vla-put-TextStyle (list Obj "SIMPLEX"))
)
((vlax-property-available-p Obj 'StyleName) ;_TEXT,MTEXT, ATTRIBUTE
(vl-catch-all-apply 'vla-put-stylename (list Obj "SIMPLEX"))
)
((and
   (eq (vla-get-objectname Obj) "AcDbBlockReference")
   (not (vlax-property-available-p Obj 'Path)) ;_Not Xref ???
   (eq (vla-get-hasattributes Obj) :vlax-true)
   )
(foreach Att (vlax-invoke Obj 'getattributes)
            (vl-catch-all-apply 'vla-put-stylename (list Att "SIMPLEX"))
          )
)
(t nil)
)
      (vla-put-layer Obj "0")
    )
  )
  (acet-ui-progress-done)
  (princ)
)

Title: Re: text style replacement
Post by: Patrick_35 on January 04, 2007, 12:21:49 PM
I think the same thing as T.Willey but if you need this code, here

Code: [Select]
(vlax-for style (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
  (if (/= (strcase (vla-get-fontfile style)) "SIMPLEX.SHX")
    (vla-put-fontfile style "SIMPLEX.SHX")
  )
)

Quote
but he doesn't check for 'Constant Attributes' within blocks, and nothing about 'Tables' or 'Dimensions', and nothing about text style overrides within 'Mtext' or 'Tables'.
Yes, I don't think of them, but Andrea can modify the lisp

Nice code VAA  :-)

@+
Title: Re: text style replacement
Post by: Andrea on January 04, 2007, 03:41:57 PM
Nice code VAA  !!??
You mean VVA !

 :police:

yes,...very nice.

But, guys,...I don't know where you lurn all this....but very useful.
thank you very much...

last thing.....


with the..
Code: [Select]
(vla-put-layer Obj "0")It change all on layer "0".

But I need to change only all layer inside the block to "0" and leave the layer insertion of the block.
(see picture below)

for the moment I run the routine....and
add the previous code to reset the layer...

but i'm trying to understand what is the OBJ versus the BLK variable..
Title: Re: text style replacement
Post by: Andrea on January 04, 2007, 04:02:23 PM
this is how i've modified the routine for doing exactly what i need..
but i'm sure there is another solution..

Code: [Select]
(defun c:TEST (/ Att ActDoc att Obj Blk n tot f)
  (vl-load-com)
  (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)) tot 0 n 0)
  ;_Unlock les couches
  (vlax-for lay (vla-get-layers ActDoc)
    (vla-put-Lock lay :vlax-false)
    (vl-catch-all-apply 'vla-put-Freeze (list lay :vlax-false))
    )
;;  (vla-put-ActiveLayer ActDoc (vla-item (vla-get-layers ActDoc) "0"))
;;capture tous les block
  (vlax-for Blk (vla-get-Blocks ActDoc)
    (setq tot (+ tot (vla-get-count blk)))
  )
 
;;CREATION DU STYLE SIMPLEX
  (mapcar (function (lambda ( _font  / text_style)
(setq text_style  (vla-add (vla-get-textstyles ActDoc) _font))
(vla-put-fontfile text_style "SIMPLEX.SHX")
(vla-put-height text_style 0.0)
(vla-put-width text_style 1.0)
        (vla-put-activetextstyle ActDoc text_style)))
'("SIMPLEX"))
 
  (acet-ui-progress-init "Traitement" tot)
;;traitement des blocks
  (vlax-for Blk (vla-get-Blocks ActDoc)
    (vlax-for Obj Blk
      (setq n (1+ n))
      (acet-ui-progress-safe n)
      (setq f (vla-get-layer Obj))
      (vla-put-layer Obj "0")
      (cond
((vlax-property-available-p Obj 'TextStyle) ;_DIMENSION
(vl-catch-all-apply 'vla-put-TextStyle (list Obj "SIMPLEX"))
)
((vlax-property-available-p Obj 'StyleName) ;_TEXT,MTEXT, ATTRIBUTE
(vl-catch-all-apply 'vla-put-stylename (list Obj "SIMPLEX"))
)
((and
   (eq (vla-get-objectname Obj) "AcDbBlockReference")
   (not (vlax-property-available-p Obj 'Path)) ;_Not Xref ???
   (eq (vla-get-hasattributes Obj) :vlax-true)
   )
(progn
(vla-put-layer Obj f) 
(foreach Att (vlax-invoke Obj 'getattributes)
            (vl-catch-all-apply 'vla-put-stylename (list Att "SIMPLEX"))
 
   )
          )
)
(t nil)
)
     
    )
  )


(setq ss1 (ssget "X" '((0 . "MTEXT,TEXT"))))
(if ss1
  (progn
(setq sscount (sslength ss1))
(setq val1 (- sscount 1))
(repeat sscount
(setq ent (vlax-ename->vla-object (ssname ss1 val1)))
(vla-put-layer ent "TextLayer")
(setq val1 (- val1 1))
)
)
)



 
  (vla-Regen ActDoc acActiveViewport)
  (acet-ui-progress-done)
  (princ)
)
Title: Re: text style replacement
Post by: T.Willey on January 04, 2007, 06:09:04 PM
I wasn't going to, but I got bored.  Here is how I would do it.  It won't change the text for dim styles, or for formated mtext, but it will change all the rest.  It also assumes that layers that need to be unlocked are, and that the text style you name in the calling function exists in the drawing.
Code: [Select]
(defun ChangeAllTextObjectsStyle (Doc StyName / tempObjType IsLo ColCnt RowCnt)

(vlax-for Blk (vla-get-Blocks Doc)
 (setq IsLo (if (= (vla-get-IsLayout Blk) :vlax-true) T nil))
 (if (= (vla-get-IsXref Blk) :vlax-false)
  (vlax-for Obj Blk
   (setq tempObjType (vla-get-ObjectName Obj))
   (cond
    ((vl-position tempObjType '("AcDbText" "AcDbMText" "AcDbAttributeDefinition"))
     (vla-put-StyleName Obj StyName)
     (if (not IsLo)
      (vla-put-Layer Obj "0")
     )
    )
    ((wcmatch tempObjType "AcDb*Dimension")
     (vla-put-TextStyle Obj StyName)
    )
    ((= tempObjType "AcDbBlockReference")
     (foreach Att (vlax-invoke Obj 'GetAttributes)
      (vla-put-StyleName Att StyName)
     )
     (foreach Att (vlax-invoke Obj 'GetConstantAttributes)
      (vla-put-StyleName Att StyName)
     )
    )
    ((= tempObjType "AcDbTable")
     (setq ColCnt 0)
     (repeat (vla-get-Columns Obj)
      (setq RowCnt 0)
      (repeat (vla-get-Rows Obj)
       (vlax-invoke Obj 'SetCellTextStyle RowCnt ColCnt StyName)
       (setq RowCnt (1+ RowCnt))
      )
      (setq ColCnt (1+ ColCnt))
     )
    )
   )
  )
 )
)
)
Call like for the active drawing.
Code: [Select]
(ChangeAllTextObjectsStyle (vla-get-ActiveDocument (vlax-get-Acad-Object)) "Simplex")
Edit:  I changed the wording in the attribute area to be correct.  I had it trying to change 'TextStyle' but needed to be 'StyleName'.
Title: Re: text style replacement
Post by: dan19936 on January 04, 2007, 07:35:44 PM
Tim, nice code, you're very productive when you're bored...

An ignorant question, you have the acad object passed in as a variable. Does one ever not use the active document?

Thanks,

Dan
Title: Re: text style replacement
Post by: Kerry on January 04, 2007, 07:40:56 PM
Tim, nice code, you're very productive when you're bored...

An ignorant question, you have the acad object passed in as a variable. Does one ever not use the active document?

Thanks,

Dan

Sometimes, like with DBX or when reading from another db, you will need to pass 'that' doc reference.
Title: Re: text style replacement
Post by: T.Willey on January 04, 2007, 07:47:46 PM
Tim, nice code, you're very productive when you're bored...

An ignorant question, you have the acad object passed in as a variable. Does one ever not use the active document?

Thanks,

Dan

Sometimes, like with DBX or when reading from another db, you will need to pass 'that' doc reference.
Yup.  Thanks Kerry.

and Thanks Dan for the nice comment.  I just like the flexibility of it, since the way the code is written it could be called from, and used with, ObjectDBX.
Title: Re: text style replacement
Post by: Andrea on January 05, 2007, 08:46:25 AM
 :?

Tim....

Thank you !
The code work perfectly.

Title: Re: text style replacement
Post by: T.Willey on January 05, 2007, 11:04:55 AM
:?

Tim....

Thank you !
The code work perfectly.


I'm glad Andrea.  I hope you can learn from it.  And You're Welcome.
Title: Re: text style replacement
Post by: Andrea on January 05, 2007, 11:15:40 PM
:?

Tim....

Thank you !
The code work perfectly.


I'm glad Andrea.  I hope you can learn from it.  And You're Welcome.

I lurn each day Tim......but with you guys......I lurn more faster..  :roll:

just a little thing...
the code works perfectly since I got a new drawing from client...
the..
Code: [Select]
....     (if (not IsLo)
      (vla-put-Layer Obj "0")......
section seem to work.....but even with regenall or
Code: [Select]
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)all blocks seem to not being refreshed...(<- is this a english word ?)  :|
Title: Re: text style replacement
Post by: Kerry on January 05, 2007, 11:19:22 PM
just a little thing...
the code works perfectly since I got a new drawing from client...
the..
Code: [Select]
....     (if (not IsLo)
      (vla-put-Layer Obj "0")......
section seem to work.....but even with regenall or
Code: [Select]
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)all blocks seem to not being refreshed...(<- is this a english word ?)  :|

What do you think Tims code should do to the blocks Andrea ?
Title: Re: text style replacement
Post by: Joe Burke on January 07, 2007, 08:32:11 AM
Hi all,...

first, best wishes for 2007..   :-)

Is there any way to select all text and mtext in the entire drawing including in block, layout, and model space ?

I need to do this:
I have many diffrent text style and need to purge all them and keep only 1.
so I think i need to select all text by filtering them en change style.
But if you have any other idea....i'll keep it !

thanks.

Question aside, why write code given CAD Standards can do this?

I looked at Tim's code, though not in detail. I think it would not allow a text style to be purged if it is used in a dimension style.

IOM, code like Tim's is useful for examining a drawing. Tell me where this or these text styles are used, so I can decide beforehand whether it's safe to let CAD Standards do what it does.
Title: Re: text style replacement
Post by: Andrea on January 07, 2007, 06:29:34 PM
just a little thing...
the code works perfectly since I got a new drawing from client...
the..
Code: [Select]
....     (if (not IsLo)
      (vla-put-Layer Obj "0")......
section seem to work.....but even with regenall or
Code: [Select]
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)all blocks seem to not being refreshed...(<- is this a english word ?)  :|

What do you think Tims code should do to the blocks Andrea ?

Yes,..
Title: Re: text style replacement
Post by: Andrea on January 07, 2007, 06:37:18 PM
Hi all,...

first, best wishes for 2007..   :-)

Is there any way to select all text and mtext in the entire drawing including in block, layout, and model space ?

I need to do this:
I have many diffrent text style and need to purge all them and keep only 1.
so I think i need to select all text by filtering them en change style.
But if you have any other idea....i'll keep it !

thanks.

Question aside, why write code given CAD Standards can do this?

I looked at Tim's code, though not in detail. I think it would not allow a text style to be purged if it is used in a dimension style.

IOM, code like Tim's is useful for examining a drawing. Tell me where this or these text styles are used, so I can decide beforehand whether it's safe to let CAD Standards do what it does.

some client have standard.....
one of these want only SIMPLEX style in drawings..in 5 specific layers, all block created to layer "0" etc....
but we receive some drawing from architect and diffrent other discipline who work with there standard.
so when we receive these drawing we always need to clean all textstyle and fonts before returning the drawing to the client.

To obtain in the drawing this final result of textstyle:

Standard and SIMPLEX
Title: Re: text style replacement
Post by: Kerry on January 07, 2007, 06:53:19 PM
......What do you think Tims code should do to the blocks Andrea ?

Yes,..

Lets try that again ...

When you read the code that Tim provided, what do you think it does to blocks ?

Title: Re: text style replacement
Post by: Andrea on January 07, 2007, 07:52:41 PM
Code: [Select]
((vl-position tempObjType '("AcDbText" "AcDbMText" "AcDbAttributeDefinition"));;detect text TYPE
     (vla-put-StyleName Obj StyName);;put the new stylename
     (if (not IsLo);;if is not in same layout
      (vla-put-Layer Obj "0");;put the text item found to layer "0"
     )

do I'm right ?
Title: Re: text style replacement
Post by: Kerry on January 07, 2007, 07:54:16 PM
Forget posting  code and try to answer the question ..

When you read the code that Tim provided,
what do you think it does to blocks ?

Title: Re: text style replacement
Post by: M-dub on January 07, 2007, 08:33:38 PM
just a little thing...
the code works perfectly since I got a new drawing from client...
the..
Code: [Select]
....     (if (not IsLo)
      (vla-put-Layer Obj "0")......
section seem to work.....but even with regenall or
Code: [Select]
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)all blocks seem to not being refreshed...(<- is this a english word ?)  :|

What do you think Tims code should do to the blocks Andrea ?

Yes,..

Andrea,
Do you think you maybe misunderstood Kerry's question?  He's asking how the code should affect the blocks, not if it should affect the blocks.

just throwing a little hint out there ;)
Title: Re: text style replacement
Post by: Kerry on January 07, 2007, 08:52:14 PM

Andrea,
Do you think you maybe misunderstood Kerry's question?  He's asking how the code should affect the blocks, not if it should affect the blocks.

just throwing a little hint out there ;)

exactly !

I originally wrote something like
Quote
What does Tim's code do to the blocks.?
but I have been accused of being rude or blunt to Andrea in the past, so I changed it to :
Quote
What do you think Tims code should do to the blocks Andrea ?





Title: Re: text style replacement
Post by: M-dub on January 07, 2007, 08:54:59 PM
but I have been accused of being rude or blunt to Andrea in the past, so I changed it to :

Guilty as charged.  :oops:

My mistake and my apologies   :-)
Title: Re: text style replacement
Post by: Kerry on January 07, 2007, 09:21:42 PM
Wasn't trying to put you ( or anyone else ) onto a guilt trip Mike.

Title: Re: text style replacement
Post by: M-dub on January 07, 2007, 09:36:23 PM
I know...
I was jus' sayin'  :)
Title: Re: text style replacement
Post by: Joe Burke on January 08, 2007, 07:42:50 AM
Quote
some client have standard.....
one of these want only SIMPLEX style in drawings..in 5 specific layers, all block created to layer "0" etc....
but we receive some drawing from architect and diffrent other discipline who work with there standard.
so when we receive these drawing we always need to clean all textstyle and fonts before returning the drawing to the client.

To obtain in the drawing this final result of textstyle:

Standard and SIMPLEX

I understand what you want to do and why. I'm just suggesting you don't need code because CAD Standards can do it. And it would do a better job than what Tim posted. As he said, "It won't change the text (style) for dim styles, or for formated mtext."

CAD Standards would get rid of any unwanted text styles contained in dimstyles. And it purges unwanted items, those which were replaced, in the process.

Regarding Tim's comment about formatted mtext, that is, or should be, a concern. If an mtext string looks like this, "{\\Fromans|c0;SEE ROOF PLAN}" it will display using ROMANS regardless of what the style name property is. To fix that there's John Uhden's Unformat function. It allows removal of font formatting in mtext without changing other formatting codes which you'd probably want to keep.

Tim,

If you read this, I trust you know it's not meant as criticism. Basically I'm just underlining what you said.
Title: Re: text style replacement
Post by: Andrea on January 08, 2007, 09:31:08 AM
just a little thing...
the code works perfectly since I got a new drawing from client...
the..
Code: [Select]
....     (if (not IsLo)
      (vla-put-Layer Obj "0")......
section seem to work.....but even with regenall or
Code: [Select]
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)all blocks seem to not being refreshed...(<- is this a english word ?)  :|

What do you think Tims code should do to the blocks Andrea ?

Yes,..

Andrea,
Do you think you maybe misunderstood Kerry's question?  He's asking how the code should affect the blocks, not if it should affect the blocks.

just throwing a little hint out there ;)

By extracting each entity of it and change layer.
Title: Re: text style replacement
Post by: T.Willey on January 08, 2007, 11:24:52 AM
Tim,

If you read this, I trust you know it's not meant as criticism. Basically I'm just underlining what you said.
No problem at all Joe.  I was going to show how a formatted string looked like, but couldn't seem to get one to work right.  One thing I did learn from this is that you can't have formatted strings in a Table object.  Don't know if it will ever be useful, but it is something I learned.

As for stripping out formats with mtext strings, here is one I wrote a little while ago (couple of years maybe).
Code: [Select]
(defun StripString (String / cstr1 cstr2 nString cnt1 tstr1)
; Strips out formation for color, font, height and width.

(setq cnt1 1)
(while (and (setq cstr1 (substr String 1 1)) (> (strlen String) 0))
 (if (= cstr1 "\\")
  (progn
   (setq cstr2 (substr String 2 1))
   (if (member (strcase cstr2) '("C" "F" "H" "W"))
    (progn
     (while (/= (substr String cnt1 1) ";")
      (setq cnt1 (1+ cnt1))
     ); while
     (setq String (substr String (1+ cnt1) (strlen String)))
     (setq cnt1 1)
    ); progn
    (progn
     (if nString
      (setq nString (strcat nString (substr String 1 1)))
      (setq nString (substr String 1 1))
     ); if
     (setq String (substr String 2 (strlen String)))
    ); progn
   ); if
  ); progn
  (progn
   (if nString
    (setq nString (strcat nString (substr String 1 1)))
    (setq nString (substr String 1 1))
   ); if
   (setq String (substr String 2 (strlen String)))
  ); progn
 ); if
); while
(setq tstr1 (vl-string->list nString))
(if (and (not (member 92 tstr1)) (member 123 tstr1))
 (setq tstr1 (vl-remove-if '(lambda (x) (or (= x 123) (= x 125))) tstr1))
); if
(vl-list->string tstr1)
)

By extracting each entity of it and change layer.
The code doesn't care about the objects within the blocks that are not text oriented.  If you want it to change all objects in the block, then you will have to add some stuff to the code.  It shouldn't be too hard, so I will leave it up to you to try.