Jump to content

Dimension Text Format


Arepo

Recommended Posts

TxtFormat.pdf

 

Can anyone help me format some dimension text through LISP?

I would like to get the text formatted as horizontally stacked fractions w/ no space between inches and fractions. E.g. (setq txt 3.08203) (rtos txt 4 5) gets me 3 3/32", but I want it formatted as 3 followed by 3/32" horizontally stacked & no space between them.

Thank you.

Link to comment
Share on other sites

I'm trying to get the text formatted as shown in pdf attached, I guess AutoCAD calls it horizontally stacked, but I think it can be called vertically as well, basically I want it as inches (no feet) followed by inch fractions stacked on top of each other, followed by " (inch sign), no spaces anywhere.

Link to comment
Share on other sites

This is two seperate things dimensions and text if you rtos the dim value then its a string not a dimension any more, so would need to use I think mtext, thank god for metric.

 

If its a dimension may be able to do as dimension style but would possibly reflect true dimension length.

Link to comment
Share on other sites

Thanks, but I already had variables set this way and it won't work. This text overrides the true dimension text and is shown in ft & in and diagonal fractions, but my other dimensions are inches only and horizontal fractions.

Link to comment
Share on other sites

Setting up a dimstyle works, but the problem is that the text extracted from obj definition (42 . 3.03975) is shown as 3.03975 (in this case), formatted in decimal inches. So when I paste it in a different place it loses its format shown in dimstyle. I was trying to extract the text from dimension obj, keep its format shown there or manipulate 3.03975 in a way that shows fractional inches & paste it somewhere else. I was basically trying to get a function whose input would be 3.0975 and output formatted as horiz. fractional inch, if there is such a thing. Thanks for your help, anyway.

Link to comment
Share on other sites

Reverse engineering formatted MTEXT I came up with this:

(defun c:foo (/ i n s)
 (if (setq i (getdist "\nEnter distance: "))
   (progn (setq s (rtos i 4 5))
   (setq s (cond ((setq n (vl-string-search " " s))
		  (substr (rtos 500.03975 4 5) 1 5)
		  (strcat "\\A1;"
			  (substr s 1 n)
			  "{\\H0.7x;\\S"
			  (vl-string-right-trim "\"" (substr s (+ 2 n)))
			  ";}\""
		  )
		 )
		 (s)
	   )
   )
   (entmake (list '(0 . "MTEXT")
		  '(100 . "AcDbEntity")
		  '(67 . 0)
		  '(8 . "MTEXT")
		  '(100 . "AcDbMText")
		  (cons 10 (getvar 'viewctr))
		  (cons 40 (/ (getvar 'viewsize) 16.))
		  '(41 . 0.0)
		  '(46 . 0.0)
		  '(71 . 5)
		  '(72 . 1)
		  (cons 1 s)
		  '(7 . "ROMANS")
		  '(11 1.0 0.0 0.0)
	    )
   )
   )
 )
 (princ)
)

Link to comment
Share on other sites

  • 6 years later...

@ronjonp could your routine be reversed?

 

I have a routine that returns a formatted string when I select it:

{\A1;93{\H0.7x;\S5#8;}}

I would like to return the decimal value...

would return 93.625 ( 93 + 5/8 )

I have tried a bunch of things but can't get it.

Thank you for any help!

 

edit:

I found @CAB 's routine that does a beautiful job, of returning unformatted..

I tried adding to it but only succeeded in thoroughly butchering it...lol

If possible Could we get it to return the real number? 

{\A1;93{\H0.7x;\S5#8;}}

would return 93.625  ( 93 + 5/8 )

There will not always be a fractional part...

 

Thank you again for any help

Edited by Abrasive
Found additional information.
Link to comment
Share on other sites

Fairly straight forward. Just use lee-mac Unformat, download from his web site.

 


(setq obj (vlax-ename->vla-object (car (entsel "\nSelect a object "))))
(setq str (lM:unformat (vlax-get obj 'textstring) T))

This will return "93 5/8" so can pull out the 93 and the 5/8 and add them to make a decimal value. 

 

Do you know about Lisp ?

Link to comment
Share on other sites

Thanks Alan!

That one works nice too.

Some of my text strings don't have a space in between the integer and the fraction so:

{\A1;88{\H0.7x;\S1#8;}}

comes through as: "881/8", but I need "88 1/8" or better yet 88.125

If I could get it to separate at the whole number and the fraction I could probably do the rest..."probably"...lol

Thanks for your help...again!

 

Link to comment
Share on other sites

Ok so you can use wcmatch looking at the string without the strip mtext as 1st step and check does it have a \S, second step look for # then you can use substr to read the 1#8.

 

So need to make some 1/8 13/16 1/16 etc to test. 

 

Tricky bit is if you do a dim like "Size 3 3/8" so need to make sure find correct \S.

 

Will have  a think. 

Link to comment
Share on other sites

search ;\S would that work? Assuming a font height change or something for the fraction in the dimension to give the ; character

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