Author Topic: text style replacement  (Read 18267 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: text style replacement
« Reply #15 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 ?
« Last Edit: January 04, 2007, 09:05:52 AM by Andrea »
Keep smile...

Patrick_35

  • Bull Frog
  • Posts: 276
  • Rennes, France
Re: text style replacement
« Reply #16 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

@+
The shape even of the pyramids of Egypt shows that already the workmen tended to make some less and less.
Will Cuppy, 1884-1949.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: text style replacement
« Reply #17 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 ?
Keep smile...

Patrick_35

  • Bull Frog
  • Posts: 276
  • Rennes, France
Re: text style replacement
« Reply #18 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:

@+
The shape even of the pyramids of Egypt shows that already the workmen tended to make some less and less.
Will Cuppy, 1884-1949.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: text style replacement
« Reply #19 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")
   )
)
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10389
Re: text style replacement
« Reply #20 on: January 04, 2007, 11:14:01 AM »
How about this vla-get-textfontstyle
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: text style replacement
« Reply #21 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 ?
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5241
Re: text style replacement
« Reply #22 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'.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10389
Re: text style replacement
« Reply #23 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")
« Last Edit: January 04, 2007, 11:58:38 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VVA

  • Newt
  • Posts: 166
Re: text style replacement
« Reply #24 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)
)


Patrick_35

  • Bull Frog
  • Posts: 276
  • Rennes, France
Re: text style replacement
« Reply #25 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  :-)

@+
The shape even of the pyramids of Egypt shows that already the workmen tended to make some less and less.
Will Cuppy, 1884-1949.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: text style replacement
« Reply #26 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..
« Last Edit: January 04, 2007, 03:43:30 PM by Andrea »
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: text style replacement
« Reply #27 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)
)
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5241
Re: text style replacement
« Reply #28 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'.
« Last Edit: January 04, 2007, 06:49:17 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

dan19936

  • Guest
Re: text style replacement
« Reply #29 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