Text and Change Dimension Text

Text and Change Dimension Text

k005
Advisor Advisor
407 Views
6 Replies
Message 1 of 7

Text and Change Dimension Text

k005
Advisor
Advisor

Hello friends;


How can we design this code to include normal texts and modified dimension texts?


Thanks in advance to the helpful friend.

 

 

 

(defun c:ymAlan (/ dg1 dg2 dg3 brl txtObj)
  (setvar "dimzin" 0)

  (defun get-dimension (ent)
    (if (setq obj (vlax-ename->vla-object ent))
        (if (or (vl-catch-all-error-p (vla-get-textoverride obj))
                (not (equal (vla-get-textoverride obj) "")))
            (/ (vla-get-textoverride obj) 100.0)
            (/ (vla-get-measurement obj) 100.0))))

  (setq msp (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq txtH (getvar "Textsize"))

  (setq ent1 (car (entsel "\nÜst.ölçü seçiniz >")))
  (setq ent2 (car (entsel "\nAlt.ölçü seçiniz >")))
  (setq ent3 (car (entsel "\nYükseklik seçiniz >")))
  (setq pt (getpoint "\nNereye Yazılsın >"))

  (setq dg1 (get-dimension ent1))
  (setq dg2 (get-dimension ent2))
  (setq dg3 (get-dimension ent3))

  (setq brl (strcat "İstinat orta kısım Alan : ((" (rtos dg1 2 2) " + " (rtos dg2 2 2) ") / 2) x " (rtos dg3 2 2) " = "))

  (setq txtObj (vla-addtext msp brl (vlax-3d-point pt) txtH))
  (dos_clipboard brl)

  (princ)
)

 

 

 

0 Likes
Accepted solutions (2)
408 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

Does that actually work?  This:

  (/ (vla-get-textoverride obj) 100.0)

surely gives an error, since a text override is a text string, not a number that the divide function can use.

 

I think what you want to do should be possible by using the DXF code 1 entry in entity data, rather than the "textoverride"  VLA property which would be applicable only to Dimensions.  The 1 entry is used for Text, short Mtext, and Dimension text overrides.  Something like this [untested]:

 

  (defun get-dimension (ent)
    (setq
      edata (entget ent)
      etxt (cdr (assoc 1 edata)); [M]Text content or Dimension text override
    )
    (/
      (if (= etxt ""); Dimension without text override?
        (cdr (assoc 42 edata)); then -- use measured value
        (distof etxt); else -- use numerical equivalent of text override
      ); if
      100
    ); /
  ); defun

 

 

Kent Cooper, AIA
Message 3 of 7

k005
Advisor
Advisor

Yes. This is a part of the code you sent... namely the Text part. and it worked beautifully.


However, if the selection is a dimension text, then it did not make any calculations...

 

What I mean is that the code below must be combined with the code you sent.

 

  (defun get-dimension (ent)
    (if (setq obj (vlax-ename->vla-object ent))
        (if (= (vla-get-textoverride obj) "")
            (/ (vla-get-measurement obj) 100.0)
            (/ (vla-get-textoverride obj) 100.0))))

 

0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant

@k005 wrote:

....

However, if the selection is a dimension text, then it did not make any calculations...

....


That may be because I had an error in line 7 -- I had it testing "ext" instead of "etxt".  Now corrected -- try again.

Kent Cooper, AIA
0 Likes
Message 5 of 7

k005
Advisor
Advisor

Thank you very much. Ok.

 

* However, if the numbers in the text are separated by commas, then it gives an error. It's okay if it's dotted...

 

 

For the TEXT..

example :

 

81,65 .... error

81.65 ... OK

 

So it would be great if a change function could be added. Make the comma a period. Just to make the calculations properly. Otherwise, there is no need to change the numbers...

 

 

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

Change line 9 to say:

(distof (vl-string-subst "." "," etxt))

Kent Cooper, AIA
Message 7 of 7

k005
Advisor
Advisor

In one word, it was Super.! 🤗   Thanks a lot @Kent1Cooper

0 Likes