Jump to content

Inches dimension to Feet conversion Lisp


structo

Recommended Posts

Hi friends,

 

i have dimension text as 59" and so on. i want to convert as 4'-11"rule is above 18" dimension text should be convert as feet. any possibilities by quick lisp?

Rule is:

 

find text with inches(") symbol text and divided by "12". then replace with "Feet-Inch" text. like a 4'-11" instead of 59".( if more than 18" text value)

 

Thank you.

inches to feets.dwg

Edited by structo
Link to comment
Share on other sites

 

Hi friend,

thank you for responding. yes i tried your idea already. but not success full. please observe sample drawing. there is one dimension style. in this style contains different text was included. please have a look. in this dimension style not a original dimension. there is edited text. so difficult to change each text.

 

Thank you.

d1.JPG

d2.JPG

Link to comment
Share on other sites

You just need to set up the dimstyle to do what you want it to do.

 

I have created a new dimstyle which I based upon the existing Dimsyle 1, and I adjusted the dimscale linear in the dimstyle definition, so that you would not need to OVERRIDE all your dimensions. I removed all of the OVERRIDES in the linework on the right, and selected all of the dimensions and changed their dimstyle in the QUICK PROPERTIES to Dimstyle 1 Fixed.

 

I am not sure why you didn't draw this at 1:1 in Modelspace, as is the accepted industry norm.

Typically working with Autocad one draws anything and everything, in Modelspace, at life size (1:1), unlike conventional drafting on a sheet of paper, where that very quickly becomes out of the question.

 

If you SCALED this drawing by a factor of .02, everything would be the right size, in which case you would then be able to remove the .02 scale factor which I applied to the dimstyle as highlighted in yellow on the screenshot of the Quick Properties Tab. :|

 

I just scaled the object in your drawing by a factor of .02, and adjusted the dimension style to reflect that change, as highlighted in yellow, the dim scale linear is no longer 0.02, but is now 1, as shown in the last screenshot.

 

I hope this helps you.

try this fixed dim style.jpg

inches to feet.dwg

dim fixed 2.jpg

dim fix 3 after scaling.jpg

Edited by Dadgad
Link to comment
Share on other sites

hi,

thank you for reply. those drawing was developed by one program. that's why i want to change by automate procedure for lot of drawings.

 

thank you.

Link to comment
Share on other sites

Because the Dimension Text has been OVERRIDDEN, that could be quite difficult, not to mention the fact that the scales are not as would be expected.

I am pretty good with Dimensions, but know nothing about lisp, good luck with finding an automated way to sort them out. :)

 

Would all of the drawings be scaled like this one was, at fifty times larger than lifesize (50:1)?

The answer to that, could be an important one.

Link to comment
Share on other sites

Yes friend,

 

i need to find text with inches(") symbol text and divided by "12". then replace with "Feet-Inch" text. like a 4'-11" instead of 59".( if more than 18" text value)

 

Thank you.

Link to comment
Share on other sites

I agree with Dadgad's comments. But, having said that, this should work:

(defun c:Test ( / doc ovr ss)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (if (setq ss (ssget "_X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
   (vlax-for obj (setq ss (vla-get-activeselectionset doc))
     (setq ovr (vla-get-textoverride obj))
     (if
       (and
         (wcmatch ovr "*\"")
         (not (wcmatch ovr "*[~\"0-9]*,*\"*?"))
         (< 18 (atoi ovr))
       )
       (vla-put-textoverride 
         obj 
         (strcat 
           (itoa (/ (atoi ovr) 12)) 
           "'-" 
           (itoa (rem (atoi ovr) 12))
           "\""
         )
       )
     )
   )
   (vla-delete ss)
 )
 (vla-endundomark doc)
 (princ)
)

Link to comment
Share on other sites

Thanks. :)

 

Here is a slightly modified version. Same functionality but wcmatch is used only once. ;)

(defun c:Test ( / doc ovr ss)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (if (setq ss (ssget "_X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
   (vlax-for obj (setq ss (vla-get-activeselectionset doc))
     (setq ovr (vla-get-textoverride obj))
     (if
       (and
         (not (wcmatch ovr "*[~\"0-9]*,*[~\"],*\"*?"))
         (< 18 (atoi ovr))
       )
       (vla-put-textoverride 
         obj 
         (strcat 
           (itoa (/ (atoi ovr) 12)) 
           "'-" 
           (itoa (rem (atoi ovr) 12))
           "\""
         )
       )
     )
   )
   (vla-delete ss)
 )
 (vla-endundomark doc)
 (princ)
)

Link to comment
Share on other sites

The following is untested, but perhaps offers an alternative:

(defun c:test ( / g i s v x )
   (if (setq s (ssget "_X" '((0 . "DIMENSION") (1 . "*#\"") (1 . "~*\"*?") (1 . "~*[~\"0-9]*"))))
       (repeat (setq i (sslength s))
           (if (< 18 (setq x (entget (ssname s (setq i (1- i))))
                           g (assoc 1 x)
                           v (atoi (cdr g))
                     )
               )
               (entmod (subst (cons 1 (strcat (itoa (/ v 12)) "'-" (itoa (rem v 12)) "\"")) g x))
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

@structo:

I am pleased to see that my code functions exactly as intended: :D

1.

As per your request it only changes dimension texts. Normal text entities are not affected.

2.

Only dimension texts that consist of one or more digits and end in a double quote are changed.

 

So in your drawing dimensions with these overrides are not changed:

"33-2B-A8 \\X~@ 7\" A/C"

"74\"\\X = ="

Also this normal text is not changed:

"66\" both sides"

 

I hope you understand the logic here.

Link to comment
Share on other sites

@structo:

For your new drawing this should work:

(defun ConvStr (str i / j num sub)
 (if (setq i (vl-string-position 34 str i))
   (progn
     (setq j i)
     (while (and (/= j 0) (wcmatch (substr str j 1) "#"))
       (setq j (1- j))
     )
     (if (< 18 (setq num (atoi (substr str (1+ j) (- i j)))))
       (ConvStr
         (strcat
           (setq sub (strcat (substr str 1 j) (itoa (/ num 12)) "'-"  (itoa (rem num 12))))
           (substr str (1+ i))
         )
         (1+ (strlen sub))
       )
       (ConvStr str (1+ i))
     )
   )
   str
 )
)

(defun c:ConvAll ( / doc ss)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (if (setq ss (ssget "_X" '((0 . "DIMENSION,*TEXT") (1 . "*#*\"*"))))
   (progn
     (vlax-for obj (setq ss (vla-get-activeselectionset doc))
       (if (vl-position (vla-get-objectname obj) '("AcDbText" "AcDbMText"))
         (vla-put-textstring obj (ConvStr (vla-get-textstring obj) 0))
         (vla-put-textoverride obj (ConvStr (vla-get-textoverride obj) 0))
       )
     )
     (vla-delete ss)
   )
 )
 (vla-endundomark doc)
 (princ)
)

Link to comment
Share on other sites

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...