Author Topic: remove $0$ prefix from dim and text styles and merge  (Read 3288 times)

0 Members and 1 Guest are viewing this topic.

ROBBO

  • Bull Frog
  • Posts: 217
remove $0$ prefix from dim and text styles and merge
« on: April 23, 2014, 04:08:06 AM »
Can anyone point me in the direction of a routine that can remove $0$ prefix from dim and text styles and merge dim and text styles?

I have a routine that will do this for Layers but not dims and text styles.

Any help always appreciated.

Kind regards, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)


ROBBO

  • Bull Frog
  • Posts: 217
Re: remove $0$ prefix from dim and text styles and merge
« Reply #2 on: April 23, 2014, 05:38:28 AM »
Thanks Fixo for your prompt reply.

Have used this prior to my post, but does not merge styles if the same style name already exists prior to binding in the dwg.

With my limited experience with lisp can a subroutine be added to achieve this?

Cheers, Robbo
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: remove $0$ prefix from dim and text styles and merge
« Reply #3 on: April 23, 2014, 06:10:52 AM »
It's quite possible to do. Basically you'd iterate across the entire drawing and all its block definitions. Finding dims/text/etc. set to those types. Then adjust them to be of the type without those $ prefixes. Finally purge out the $-prefixed styles.

BTW, the $0$ prefix comes from the RefEdit command. If you use it on normal blocks all the styles (and layers) inside that block is "temporarily" converted to these names. The trouble is that after ending the RefEdit it sometimes doesn't convert those names back - thus you end up with these strange names.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ROBBO

  • Bull Frog
  • Posts: 217
Re: remove $0$ prefix from dim and text styles and merge
« Reply #4 on: April 23, 2014, 09:12:01 AM »
Found this link http://www.cadtutor.net/forum/showthread.php?83584-Merge-Dimstyle-amp-Text-style-after-removing-of-binding-prefix-0/page2 with a routine from Lee Mac. Not quite sure how this works but I get the error: "; error: ActiveX Server returned an error: Type mismatch" when I try and run it in AutoCAD 2014.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: remove $0$ prefix from dim and text styles and merge
« Reply #5 on: April 23, 2014, 10:00:58 AM »
It seems the error only happens on some DWG's ... well so it appears from that other thread. It might be a good idea to post one of your DWGs where this error still happens. Then Lee, myself or someone else might be able to more easily figure out why this error happens. I think there might be some strange object with a property not working well in ActiveX - i.e. type not supported.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ROBBO

  • Bull Frog
  • Posts: 217
Re: remove $0$ prefix from dim and text styles and merge
« Reply #6 on: April 23, 2014, 11:24:26 AM »
Snippet of dwg attached as requested.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

ROBBO

  • Bull Frog
  • Posts: 217
Re: remove $0$ prefix from dim and text styles and merge
« Reply #7 on: April 24, 2014, 02:09:42 AM »
In addition to the above. Please note if I rename the text style G-NOTES to _G-NOTES the routine works.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

roy_043

  • Water Moccasin
  • Posts: 1876
  • BricsCAD 18
Re: remove $0$ prefix from dim and text styles and merge
« Reply #8 on: April 24, 2014, 05:00:15 AM »
I can't reproduce the error in BricsCAD. But I will suggest 3 improvements for Lee Mac's code.
Does anybody understand why Lee is purging regapps in this context?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mergedimtxt ( / N_UpdateDimTextStyle cmd doc pos str )
  2.  
  3.   ;; 20140424: Added Start:
  4.   (defun N_UpdateDimTextStyle ( dimStyleObj / dimStyleElist str pos txtStyleEname txtStyleObject )
  5.     (setq txtStyleObject
  6.       (vlax-ename->vla-object
  7.         (cdr (assoc 340 (setq dimStyleElist (entget (vlax-vla-object->ename dimStyleObj)))))
  8.       )
  9.     )
  10.     (setq str (vla-get-name txtStyleObject))
  11.     (if
  12.       (and
  13.         (setq pos (vl-string-position 36 str nil t))
  14.         (setq txtStyleEname (tblobjname "style" (substr str (+ 2 pos))))
  15.       )
  16.       (entmod
  17.         (subst
  18.           (cons 340 txtStyleEname)
  19.           (assoc 340 dimStyleElist)
  20.           dimStyleElist
  21.         )
  22.       )
  23.     )
  24.   )
  25.   ;; =======================
  26.  
  27.   (foreach col '(textstyles dimstyles)
  28.     (mergedimtxt:processcollection (vlax-get-property doc col))
  29.   )
  30.   (vlax-for blk (vla-get-blocks doc)
  31.     (if (= :vlax-false (vla-get-isxref blk))
  32.       (vlax-for obj blk
  33.         (if
  34.           (and
  35.             (wcmatch (vla-get-objectname obj) "AcDb*Text,AcDb*Dimension")
  36.             (setq
  37.               str (vla-get-stylename obj)
  38.               pos (vl-string-position 36 str nil t)
  39.             )
  40.             (vlax-write-enabled-p obj)
  41.           )
  42.           (vla-put-stylename obj (substr str (+ 2 pos)))
  43.         )
  44.       )
  45.     )
  46.   )
  47.   ;; 20140424: Added Start:
  48.     (N_UpdateDimTextStyle dim)
  49.   )
  50.   ;; =======================
  51.   (setq cmd (getvar 'cmdecho))
  52.   (setvar 'cmdecho 0)
  53.   ;; 20140424: Changed Start:
  54.   (setvar 'textstyle (if (tblobjname "style" "Standard") "Standard" "ISO"))
  55.   (command "_.-dimstyle" "_restore" (if (tblobjname "dimstyle" "Standard") "Standard" "ISO"))
  56.   ; (command "_.-purge" "_regapps" "*" "_no")
  57.   (command "_.-purge" "_dimstyles" "*" "_no")
  58.   (command "_.-purge" "_styles" "*" "_no")
  59.   ;; =======================
  60.   (setvar 'cmdecho cmd)
  61.   (vla-regen doc acallviewports)
  62.   (princ)
  63. )
  64.  
  65. (defun mergedimtxt:processcollection ( col / pos str )
  66.   (vlax-for obj col
  67.     (if
  68.       (and
  69.         (setq
  70.           str (vla-get-name obj)
  71.           pos (vl-string-position 36 str nil t)
  72.         )
  73.         (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list col (substr str (+ 2 pos)))))
  74.       )
  75.       (vla-put-name obj (substr str (+ 2 pos)))
  76.     )
  77.   )
  78. )

fixo

  • Guest
Re: remove $0$ prefix from dim and text styles and merge
« Reply #9 on: April 24, 2014, 05:04:34 AM »
In addition to the above. Please note if I rename the text style G-NOTES to _G-NOTES the routine works.
  If dimstyle name contains underscore character after "$0$" ,
  then try this code snip
Code: [Select]
(setq pos (vl-string-position 36 str nil t))
(if (eq "_" (substr str (+ 2 pos)1))

(setq tstr (vl-string-subst "" (strcat (strcase(vl-filename-base (getvar 'dwgname))) "$0$_")  str))
(setq tstr (vl-string-subst "" "$0$")  str)
)

ROBBO

  • Bull Frog
  • Posts: 217
Re: remove $0$ prefix from dim and text styles and merge
« Reply #10 on: April 24, 2014, 05:18:32 AM »
I can't reproduce the error in BricsCAD.

Thanks roy_043 for the code, but unfortunately I still get the same error in AutoCAD.

Many thanks for your efforts, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: remove $0$ prefix from dim and text styles and merge
« Reply #11 on: April 24, 2014, 01:47:19 PM »
Does anybody understand why Lee is purging regapps in this context?

The code is purging everything available to be purged - regapps aren't included in the 'All' option, so I purge these separately.

roy_043

  • Water Moccasin
  • Posts: 1876
  • BricsCAD 18
Re: remove $0$ prefix from dim and text styles and merge
« Reply #12 on: April 24, 2014, 03:27:36 PM »
Does anybody understand why Lee is purging regapps in this context?

The code is purging everything available to be purged - regapps aren't included in the 'All' option, so I purge these separately.
Right, just as I thought, this has no relation to text styles or dimension styles. Thanks.

ROBBO

  • Bull Frog
  • Posts: 217
Re: remove $0$ prefix from dim and text styles and merge
« Reply #13 on: April 25, 2014, 09:00:59 AM »
The 'Rename-Objects' batch command from this useful app http://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3abatch-in-editorv10%3aen helps achieve this.

Thank you all for your interest, advice and assistance. As always much appreciated.

Cheers, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)