Changing text style name

Changing text style name

Anonymous
Not applicable
1,154 Views
5 Replies
Message 1 of 6

Changing text style name

Anonymous
Not applicable

I'd like to change the text style names in the same way that the lisp below changes layer names but am not sure how to access the text style table?

ie changing AQ_DIMS to SLD DIMS text style.

 

(defun C:LyrSub (/ LAY OBJ STR1 STR2 STR3 STR4)
 (setq STR1 "AQ "
       STR2 "SLD ")
 (vl-load-com)
 (vlax-for OBJ
   (vla-get-layers
    (vla-get-activedocument
     (vlax-get-acad-object)
   )
  )
  (setq LAY (vla-get-name OBJ)
         LAY (vl-string-subst STR2 STR1 LAY)
  )
  (if (not (tblsearch "LAYER" LAY))
   (vl-catch-all-apply
    'vla-put-name (list OBJ LAY)
   )
  )
 )
 )

0 Likes
Accepted solutions (1)
1,155 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I'd like to change the text style names in the same way that the lisp below changes layer names but am not sure how to access the text style table?

....
 (vlax-for OBJ
   (vla-get-layers
    (vla-get-activedocument
     (vlax-get-acad-object)
   )
  )
....

  (if (not (tblsearch "LAYER" LAY))

....


....

     (vla-get-textstyles

....

     (if (not (tblsearch "STYLE" LAY))

....

 

with appropriate alterations of variable names, etc.

Kent Cooper, AIA
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thank you very much Kent, will try that.....
0 Likes
Message 4 of 6

Anonymous
Not applicable

I did substitute what I thought would be correct but although the program runs it does not make the substitutions unfortunately I don't know anything about visual lisp and refuse to go through the agony of learning yet another programming language.

 

(defun C:StylSub (/ STL OBJ STR1 STR2)
 (setq STR1 "AQ"
       STR2 "SLD ")
 (vl-load-com)
 (vlax-for OBJ
   (vla-get-textstyles
    (vla-get-activedocument
     (vlax-get-acad-object)
   )
  )
  (setq STL (vla-get-name OBJ)
         STL (vl-string-subst STR2 STR1 STL)
  )
  (if (not (tblsearch "STYLE" STL))
   (vl-catch-all-apply
    'vla-put-name (list OBJ STL)
   )
  )
 )
 (prin1)
)

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

I did substitute what I thought would be correct but although the program runs it does not make the substitutions ....

 

....
  (if (not (tblsearch "STYLE" STL))
   (vl-catch-all-apply
    'vla-put-name (list OBJ STL)
   )
  )
....


I'm not as versed as some in the syntax of certain (vla...) functions, so I don't know whether that's the issue, but this works for me in place of the portion quoted above:
....

    (if (not (tblsearch "STYLE" STL))
      (command "_.rename" "_style" (vla-get-name OBJ) STL)
    )

....

 

Yes, it's "slower" than the (vla) method, but unless you have very large numbers of Style names, you would never detect the difference.

 

Consider whether to:

  (setq STR1 "AQ_"

[with the underscore], in keeping with your sample name change at the beginning of Post 1.

 

Also consider checking each Style name for whether it contains the old character string, before constructing a new name and substituting it [which is "wasted effort" when it doesn't -- the original name will be substituted for itself].

 

And finally, might any of these have aq_ [lower-case, or perhaps not both the same case] rather than AQ_ in their names?  Though the Rename command would work either way, the (...-subst) function is case-sensitive, but if needed, you can make it account for that possibility.

Kent Cooper, AIA
Message 6 of 6

Anonymous
Not applicable

Yes that is working now just have to tweek it a bit I think, thank you very much!

0 Likes