Jump to content

How can I convert the fractional value in an mtext to equivalent decimal values, for all the selected mtext with VisualLISP. I searched around whole of the internet from past 2-3 days but not found a solution.


Recommended Posts

Posted

My collogues used to alter drawings when some order came of a size that can be made just by changing some 4-5 dimensions (Sometimes many more though). Due to time constraints they just used to change the dimension manually (Dimension Override) and quickly release the drawings, most of those dimensions are in fractions. Now we've decided to convert all those drawings to represent actual scales. 

I want those overridden fractions texts to be converted to equivalent decimals so as I do not have to check each fractions value in the fraction table, my goal of creating scaled drawing will become much faster this way.

Posted

Hello friend, can you upload a dwg with an example of what you want?

Posted

Distof will take a string, typically assumed to be a length, and convert it to a decimal number (you can set it to do decimals, fractions, etc). So you can have some code that goes through each mtext object, rip the number from it (which will be in the form of a string) and apply distof to it. Then if you want to convert it back to a string rtos should be of use.

 

 

  • Agree 1
Posted (edited)

This will convert any dim that has text overridden with distof.

 

--edit

updated code to store the old override (undo command?) in the suffix also adds text above the dim of the old dimoverride

Note this command should be a temp fix

--edit

didn't account for dims at different angles.

 

(defun C:DIM-Convert (/ ss dim obj old dist off hgt pt)
  (if (setq ss (ssget '((0 . "DIMENSION"))))
    (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq obj (vlax-ename->vla-object dim))
      (if (eq (setq old (vlax-get obj 'TextOverride)) "")
        (progn)
        (progn
          (setq dist (distof old))
          (vla-put-textoverride obj dist)
          (vla-put-textsuffix obj old) ;store old overide
          ;(setq off (* (setq hgt (vlax-get obj 'TextHeight)) 1.5))          
          ;(setq pt (vlax-get obj 'TextPosition))
          ;(setq pt (list (car pt) (+ (cadr pt) off)))
          ;(entmake (list '(0 . "TEXT")(cons 10  pt)(cons 11  pt)(cons 40 hgt)(cons 1 old)'(072 . 4)))
        )
      )
    )
  )
  (princ)
)

 

 

Edited by mhupp
Code Updated
  • Like 2
Posted

@mhupp Really thanks for your time and support.

Yes the code you provided works flawlessly. But it applies on all dimensions whereas I want to make it to work only the selected dimensions.

Could you please modify it to work that way, also if I were able to set the precision digits it would be a life saver. Because currently it clutters the whole display with 

13-14 decimal digits.

 

 

Posted

will now only update the dimensions selected.

will now ask for precision of decimal places  with a default of [3]

will now create a text above the dimension of the old fractional dimension red in color with the correct offset and angle

 

(defun C:DIM-Convert (/ ss dim obj old dist off hgt pt)
  (or (setq x (getint "\nSet Dimension Precision [3]")) (setq x 3)) ;3 change to defualt percision you want
  (if (setq ss (ssget '((0 . "DIMENSION"))))
    (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq obj (vlax-ename->vla-object dim))
      (if (eq (setq old (vlax-get obj 'TextOverride)) "")
        (progn)
        (progn
          (setq dist (distof old))
          (vla-put-textoverride obj (rtos dist 2 x)) ;you can just hard code precision here by changing the x to # or decimal places
          (vla-put-textsuffix obj old) ;store old overide
          (setq off (* (setq hgt (vlax-get obj 'TextHeight)) 1.5))          
          (setq pt (vlax-get obj 'TextPosition))
          (setq pt (polar pt (+ (setq ang (vla-get-textrotation obj)) (/ pi 2)) off))
          (entmake (list '(0 . "TEXT")(cons 10  pt)(cons 11  pt)(cons 40 hgt)(cons 50 ang)'(62 . 1)(cons 1 old)'(072 . 4)))
        )
      )
    )
  )
  (princ)
)

 

  • Like 1
Posted
1 hour ago, mhupp said:

will now only update the dimensions selected.

will now ask for precision of decimal places  with a default of [3]

will now create a text above the dimension of the old fractional dimension red in color with the correct offset and angle

 

(defun C:DIM-Convert (/ ss dim obj old dist off hgt pt)
  (or (setq x (getint "\nSet Dimension Precision [3]")) (setq x 3)) ;3 change to defualt percision you want
  (if (setq ss (ssget '((0 . "DIMENSION"))))
    (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq obj (vlax-ename->vla-object dim))
      (if (eq (setq old (vlax-get obj 'TextOverride)) "")
        (progn)
        (progn
          (setq dist (distof old))
          (vla-put-textoverride obj (rtos dist 2 x)) ;you can just hard code precision here by changing the x to # or decimal places
          (vla-put-textsuffix obj old) ;store old overide
          (setq off (* (setq hgt (vlax-get obj 'TextHeight)) 1.5))          
          (setq pt (vlax-get obj 'TextPosition))
          (setq pt (polar pt (+ (setq ang (vla-get-textrotation obj)) (/ pi 2)) off))
          (entmake (list '(0 . "TEXT")(cons 10  pt)(cons 11  pt)(cons 40 hgt)(cons 50 ang)'(62 . 1)(cons 1 old)'(072 . 4)))
        )
      )
    )
  )
  (princ)
)

 

Everything works perfectly.

Now I will become hero in my office haha.

Jokes aside thanks again for being so generous with your time and skills.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...