Arepo Posted March 15, 2018 Share Posted March 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted March 15, 2018 Share Posted March 15, 2018 Your example result shows them vertically stacked? Quote Link to comment Share on other sites More sharing options...
Arepo Posted March 15, 2018 Author Share Posted March 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 16, 2018 Share Posted March 16, 2018 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. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted March 16, 2018 Share Posted March 16, 2018 You do not need Lisp code for this. You can set up a dim style. DIMLUNIT=5 DIMFRAC=0 DIMPOST=""" Quote Link to comment Share on other sites More sharing options...
Arepo Posted March 16, 2018 Author Share Posted March 16, 2018 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 17, 2018 Share Posted March 17, 2018 As I said earlier what happens if you dont rtos the txt. The dimension style handles the way it displays the value. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted March 18, 2018 Share Posted March 18, 2018 @Arepo: Maybe I have misunderstood, but I think setting up a dimstyle would work. See the attached dwg. TestDimstyle.dwg Quote Link to comment Share on other sites More sharing options...
Arepo Posted March 20, 2018 Author Share Posted March 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted March 20, 2018 Share Posted March 20, 2018 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) ) Quote Link to comment Share on other sites More sharing options...
Arepo Posted March 21, 2018 Author Share Posted March 21, 2018 Thank you RonJonp, you put a lot of effort into this, I appreciate your help. It works nicely. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted March 21, 2018 Share Posted March 21, 2018 Thank you RonJonp, you put a lot of effort into this, I appreciate your help. It works nicely. Glad to help Quote Link to comment Share on other sites More sharing options...
Abrasive Posted April 14 Share Posted April 14 (edited) @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 April 14 by Abrasive Found additional information. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 14 Share Posted April 14 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 ? Quote Link to comment Share on other sites More sharing options...
Abrasive Posted April 14 Share Posted April 14 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! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 15 Share Posted April 15 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. Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 15 Share Posted April 15 search ;\S would that work? Assuming a font height change or something for the fraction in the dimension to give the ; character Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.