Author Topic: Dimension Text - Dtext or Mtext  (Read 11151 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dimension Text - Dtext or Mtext
« Reply #30 on: January 20, 2006, 07:10:09 PM »
Worked for me although I added this.
Code: [Select]
(defun c:RewriteDimText (/ ss Ent tmpEnt EntData OldStr NumStr)

(if (setq ss (ssget "x" '((0 . "DIMENSION")
 (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
<snip>
That is a good add.  I don't use the "-4"s at all with ssget.  I guess I should learn that one one of these days.
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: 10401
Re: Dimension Text - Dtext or Mtext
« Reply #31 on: January 20, 2006, 08:32:31 PM »
Thanks Tim,

Well this is as far as I got, fighting the flu, so maybe tomorrow.
Did not know how to get the actual rotation of the dimension line.

Code: [Select]
(defun c:fixdims ()
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (and (or (ssget '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>")))
           (ssget "X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
       (setq ss (vla-get-activeselectionset
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
                )
       ) ;use ActiveX ss
       (setq mspace (vla-get-modelspace
  (vla-get-activedocument
(vlax-get-acad-object)
)
  ))
       (vlax-for x ss
         (if (vl-string-search "%%2" (setq str (vla-get-textoverride x)))
          (progn
            (vlax-dump-object x T)
            (if (setq newobj (vla-addtext mspace str (vla-get-textPosition x) (vla-get-textheight x)))
              (progn
                (vlax-put-property newobj 'Alignment  acAlignmentMiddleCenter)
                (vla-put-textAlignmentPoint newobj (vla-get-TextPosition x))
                ;;(vla-put-Rotation newobj (vla-get-Rotation x))
                (vla-put-StyleName newobj  (vla-get-TextStyle x))
                (vla-put-Height newobj  (* (vla-get-ScaleFactor x)(vla-get-TextHeight x)))
                (vla-put-Layer newobj  (vla-get-Layer x))
                (vla-put-Color newobj  (vla-get-TextColor x))
 
                (vla-put-textoverride x " ")
                (vlax-release-object newobj)
              )
              (prompt (strcat "\nERROR replacong dimtext " str))
            )
          )
         )
       )
       (vlax-release-object mspace)
  )
  (vla-endundomark doc)
  (princ) 
)
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.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Dimension Text - Dtext or Mtext
« Reply #32 on: January 20, 2006, 09:37:41 PM »
Just to throw out another idea......

Why not just change the "%%XXX" to be the actual symbol? To get MTEXT to display the character defined as 202, in the editor hold down the ALT key while typing 0202 on the numeric keypad. This works in lisp, too. Just set up a (cond) based on the value of "%%XXX" and set it to the corresponding ASCII value......it will display differently based on which font is used, just as it does now.....and there's no messing with exploding blocks and getting a TEXT object to appear exactly as the MTEXT object did.

Aw heck, here's my stab at it...note that I do not have a drawing to test this on.....so as MP would say: YMMV ;-)

Code: [Select]
(defun c:FixDimText (/ ss Ent obj txt pos code new)
  (if (setq ss (ssget "x" '((0 . "DIMENSION")(-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
    (while (setq Ent (ssname ss 0))
      (setq obj (vlax-ename->vla-object ent)
    txt (vla-get-textoverride obj))
      (if (wcmatch txt "*%%###*")
(progn
  (setq pos (vl-string-search "%%" txt))
  (setq code (atoi (substr (substr txt (+ 3 pos)) 1 3)))
  (cond ((= code 202)(setq val "Ê"))
((= code 203)(setq val "Ë"))
((= code 204)(setq val "Ì"))
((= code 205)(setq val "Í"))
((= code 206)(setq val "Î"))
((= code 207)(setq val "Ï"))
((= code 208)(setq val "Ð"))
((= code 209)(setq val "Ñ"))
((= code 210)(setq val "Ò"))
((= code 211)(setq val "Ó"))
((= code 212)(setq val "Ô"))
((= code 213)(setq val "Õ"))
((= code 214)(setq val "Ö"))
((= code 215)(setq val "×"))
((= code 216)(setq val "Ø"))
)
  (setq new (vl-string-subst val (strcat "%%" (itoa code)) txt))
  (vla-put-textoverride obj new)
  )
)
        (ssdel ent ss) ; CAB added
      )
    )
  (princ)
  )
« Last Edit: January 20, 2006, 10:10:28 PM by CAB »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension Text - Dtext or Mtext
« Reply #33 on: January 20, 2006, 10:05:45 PM »
Party pooper. :-D
Just kidding Jeff, nice solution.

Here is my last attempt tonight.
The problem with the dimension angle has been approached by using dxf codes 10 & 11
But when the extension lines are not equal length this angle is incorrect.
There must be a better solution somewhere.

Code: [Select]
(defun c:fixdims (/ doc elst mspace newobj ss str)
 
  (defun get_angle (obj / ang)
    (setq elst (entget (vlax-vla-object->ename obj)))
    (setq ang (angle (cdr (assoc 10 elst)) (cdr (assoc 11 elst))))
    (cond
      ((and (> ang (/ pi 2)) (<= ang pi))
       (setq ang (+ ang pi))
      )
      ((and (> ang pi) (< ang (* pi 1.5)))
       (setq ang (- ang pi))
      )
    )
  )


  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (and (or (ssget '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>")))
           (ssget "X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>")))
       )
       (setq ss (vla-get-activeselectionset doc)
       ) ;use ActiveX ss
       (setq mspace (vla-get-modelspace doc))
       (vlax-for x ss
         (if (vl-string-search "%%2" (setq str (vla-get-textoverride x)))
           (progn
             (vlax-dump-object x t)
             (if (setq newobj (vla-addtext mspace str (vla-get-textposition x) (vla-get-textheight x)))
               (progn
                 (vlax-put-property newobj 'alignment acalignmentmiddlecenter)
                 (vla-put-textalignmentpoint newobj (vla-get-textposition x))
                 (vla-put-stylename newobj (vla-get-textstyle x))
                 (vla-put-height newobj (* (vla-get-scalefactor x) (vla-get-textheight x)))
                 (vla-put-layer newobj (vla-get-layer x))
                 (vla-put-color newobj (vla-get-textcolor x))
                 (vla-put-rotation newobj (get_angle x))
                 (vla-put-textoverride x " ")
                 (vlax-release-object newobj)
               )
               (prompt (strcat "\nERROR replaceing dimtext " str))
             )
           )
         )
       )
       (vlax-release-object mspace)
  )
  (vla-endundomark doc)
  (princ)
)
« Last Edit: January 21, 2006, 08:25:05 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension Text - Dtext or Mtext
« Reply #34 on: January 20, 2006, 10:11:28 PM »
Jeff,
Nice job I added one line of code and it worked perfectly.  :-)
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.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Dimension Text - Dtext or Mtext
« Reply #35 on: January 20, 2006, 10:59:52 PM »
Thanks, Alan....that's what happens when I start my code with code I ganked from someone else's (namely, Tim's first posting)....I never use that method of going through the selection set, and I know that he does, I dunno why I didn't catch that.  :oops:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension Text - Dtext or Mtext
« Reply #36 on: January 20, 2006, 11:51:30 PM »
No problem.

Looking ay the code.
You could go directly to the substitution with chr.

Code: [Select]
(defun c:FixDimText (/ ss Ent obj txt pos code new)
  (if (setq ss (ssget "x" '((0 . "DIMENSION")(-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
    (while (setq Ent (ssname ss 0))
      (setq obj (vlax-ename->vla-object ent)
    txt (vla-get-textoverride obj))
      (if (wcmatch txt "*%%###*")
(progn
  (setq pos (vl-string-search "%%" txt))
  (setq new (vl-string-subst (chr (atoi (substr txt (+ 3 pos) 3)))
                                     (substr txt (+ 1 pos) 5) txt))
  (vla-put-textoverride obj new)
  )
)
        (ssdel ent ss)
      )
    )
  (princ)
)
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.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Dimension Text - Dtext or Mtext
« Reply #37 on: January 21, 2006, 02:13:00 AM »
Can't you use Unicodes?

%%130 -> \U+0082
I was thinking of something like this:
Code: [Select]
(defun c:FixDimText (/ ss Ent obj txt pos code new dec2hex)
(defun dec2hex (value / num n1 n2 L)
(setq num (atoi value))
(setq L '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"))
(setq n2 (- num (* (setq n1 (/ num 16)) 16)))
(setq value (strcat (nth n1 L)(nth n2 L)))
)

(if (setq ss (ssget "x" '((0 . "DIMENSION")(-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
(while (setq Ent (ssname ss 0))
(setq obj (vlax-ename->vla-object ent)
txt (vla-get-textoverride obj))
(if (wcmatch txt "*%%###*")
  (progn
(setq pos (vl-string-search "%%" txt))
(setq new (vl-string-subst (strcat "\\U+00" (dec2hex (substr txt (+ 3 pos) 3)))
                           (substr txt (1+ pos) 5) txt))
(vla-put-textoverride obj new)
  )
)
(ssdel ent ss)
)
)
(princ)
)
(Not tested)
Vault Professional 2023     +     AEC Collection

deegeecees

  • Guest
Re: Dimension Text - Dtext or Mtext
« Reply #38 on: January 21, 2006, 10:46:56 AM »
Quote
Well this is as far as I got, fighting the flu, so maybe tomorrow.
Did not know how to get the actual rotation of the dimension line.

I hope you didn't sneeze on the code I copied.  :-D Get better Mr. B.

Actually you guys ROCK! I didn't expect a call to arms such as this. I've got TONS of work to do, no time right now to test these, so it'll be on the back burner 'til Monday or possibly later today. Thankyou for the help.

deegeecees

  • Guest
Re: Dimension Text - Dtext or Mtext
« Reply #39 on: January 23, 2006, 04:27:28 PM »
Can't you use Unicodes?

%%130 -> \U+0082

These seem to work, how do I get the conversions?

deegeecees

  • Guest
Re: Dimension Text - Dtext or Mtext
« Reply #40 on: January 23, 2006, 04:32:21 PM »
Just to throw out another idea......

Why not just change the "%%XXX" to be the actual symbol? To get MTEXT to display the character defined as 202, in the editor hold down the ALT key while typing 0202 on the numeric keypad. This works in lisp, too. Just set up a (cond) based on the value of "%%XXX" and set it to the corresponding ASCII value......it will display differently based on which font is used, just as it does now.....and there's no messing with exploding blocks and getting a TEXT object to appear exactly as the MTEXT object did.

Aw heck, here's my stab at it...note that I do not have a drawing to test this on.....so as MP would say: YMMV ;-)

Code: [Select]
(defun c:FixDimText (/ ss Ent obj txt pos code new)
  (if (setq ss (ssget "x" '((0 . "DIMENSION")(-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
    (while (setq Ent (ssname ss 0))
      (setq obj (vlax-ename->vla-object ent)
    txt (vla-get-textoverride obj))
      (if (wcmatch txt "*%%###*")
(progn
  (setq pos (vl-string-search "%%" txt))
  (setq code (atoi (substr (substr txt (+ 3 pos)) 1 3)))
  (cond ((= code 202)(setq val "Ê"))
((= code 203)(setq val "Ë"))
((= code 204)(setq val "Ì"))
((= code 205)(setq val "Í"))
((= code 206)(setq val "Î"))
((= code 207)(setq val "Ï"))
((= code 208)(setq val "Ð"))
((= code 209)(setq val "Ñ"))
((= code 210)(setq val "Ò"))
((= code 211)(setq val "Ó"))
((= code 212)(setq val "Ô"))
((= code 213)(setq val "Õ"))
((= code 214)(setq val "Ö"))
((= code 215)(setq val "×"))
((= code 216)(setq val "Ø"))
)
  (setq new (vl-string-subst val (strcat "%%" (itoa code)) txt))
  (vla-put-textoverride obj new)
  )
)
 (ssdel ent ss) ; CAB added
      )
    )
  (princ)
  )

This worked like a charm! Thanks again everybody.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Dimension Text - Dtext or Mtext
« Reply #41 on: January 23, 2006, 08:30:32 PM »
Can't you use Unicodes?

%%130 -> \U+0082

These seem to work, how do I get the conversions?
Convert the decimal value to hexadecimal.

Tip: Use CALC (windows calculator on scientific) to convert on the fly.
Vault Professional 2023     +     AEC Collection