Author Topic: Add-Subtract Routine for Architectural/fractions  (Read 8973 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Add-Subtract Routine for Architectural/fractions
« on: February 06, 2009, 02:51:44 PM »
Using Acad2008 with Windows XP Pro
I have used a lisp routine that allows me to select an existing number (in text) and increase or decrease the value with a predetermined value automatically.

(2 becomes 3 by just selecting the text etc.)

Does anybody have anything similar that would work with fractions?

(2 15/32  to change to  1 7/32 by subtracting 1 1/4 etc)
Is this a long shot or what?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #1 on: February 06, 2009, 02:55:44 PM »
Is there anything else in the string?  If not, then it wouldn't be hard, but if so, then it will be a little harder.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #3 on: February 07, 2009, 01:20:14 PM »
Hello T
Nothing else is in the string.

Hello Cab
TxtInc doesn't seem to like fractions, but it's line of thinking is what I'm looking for.


Thanks guys

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #4 on: February 07, 2009, 08:42:06 PM »
This is not a very well tested version but I'll let you try it.
I started to add real number support some time back as well as fractions but never completed the task.

This is a quick release version that seems to be functioning properly with my limited testing.

<code removed. Too Buggy>
« Last Edit: February 08, 2009, 02:10:01 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #5 on: February 09, 2009, 12:01:14 PM »
The simplest way is to use ' distof ' on the string selected ( this will give you a real ), and to use ' getreal ' to get the number to either add or subtract.  Then just do ' rtos ' to the highest precision, and put that back as the string.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #6 on: February 10, 2009, 08:28:51 PM »
Here is another try.
Some testing but needs more.
My goal is to increment the first number within the string while maintaining the format type & precision found in the string.

This are my test strings:
Code: [Select]
  (setq lst      ;  String                          Value Returned   
         (list   
                "abc 10-1      "   ; Invalid Number       nil       
                "abc -10-1     "   ; Invalid Number       nil       
                "abc 3.5       "   ; type:  2             (3.5)     
                "abc 3 1/2     "   ; type:  2 ?5          (3.5)     
                "abc 3 1/2\"    "  ; type:  4             (3.5)     
                "abc 3 1/2'    "   ; type:  4             (42.0)     
                "abc 3-1/2'    "   ; type:  4             (42.0)     
                "abc 3'-1\"     "  ; type:  4             (37.0)     
                "abc 3'-1      "   ; type:  4             (37.0)     
                "abc 3' 1      "   ; type:  4             (37.0)     
                "abc 3' 1\"     "  ; type:  4             (37.0)     
                "abc 3' 1 1/2  "   ; type:  4             (37.5)     
                "abc 3'-1-1/2  "   ; type:  4             (37.5)     
                "abc 3' 1 1/2\" "  ; type:  4             (37.5)     
                "abc 3' 1.5    "   ; type:  4             (37.5)     
                "abc 3'.5     "    ; type   3             (36.5)     
                "abc 3' .5     "   ; type   3             (36.5)     <----<<
                "abc 3'0.5     "   ; type   3             (36.5)     <----<<
                "abc 3'-0.5     "  ; type   3             (36.5)     <----<<
                "abc 3' 0.5     "  ; type   3             (36.5)     <----<<
                "abc -10       "   ; type:  2             (-10.0)   
                "abc .5        "   ; type:  2             (0.5)     
                "abc 0.5       "   ; type:  2             (0.5)     
                "abc 5 -2      "   ; Invalid Number       (5.0 -2.0)
                "abc 1/2       "   ; type:  2 ?5          (0.5)     
                "abc 1/2\"      "  ; type:  4             (0.5)     
                "abc 9 1/2     "   ; type:  2 ?5          (9.5)     
                "abc 1.55E+01  "   ; type:  2             (15.5)     
                "abc 5 A       "   ; type:  6             (5.0)     
                "00000"            ; type:  2             (0.0)     
                "abc"              ;                       nil       
                "abc 3' -1\"     " ; Invalid Number       (36.0 -1.0)
                "abc 3'- 1\"     " ; Invalid Number       (36.0 1.0)
                "abc 3' .5     "   ; Invalid Number       (36.0 0.5)
                "abc 10-1      "   ; Invalid Number       nil       
                "abc -10-1     "   ; Invalid Number       nil       
                "abc 5A        "   ; Invalid Number       (5.0)     
                "This $5.00  is 75 cents short." ;        (5.0 75.0)
                "21'  8-1/5\""     ; too many spaces      (252.0 8.2)
                "15 cde22 35 21 abc 44"  ; (15.0 22.0 35.0 21.0 44.0)
                "abc22abc-10-1-5 def 99"; (22.0 -10.0 -1.0 -5.0 99.0)
         )
 )

<edeit: old code removed>
« Last Edit: February 11, 2009, 04:08:10 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #7 on: February 11, 2009, 02:34:48 PM »
Hey Cab
Thanks for all your hard work!

Routine is working very good
Except the result is in feet & inches

Example:
when adding 1 1/2 to 30 9/16, the  result is 2"-8 1/16".........should be 32 1/16

I looked through the code and I don't see where I need to change this.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #8 on: February 11, 2009, 02:40:40 PM »
Look for an ' rtos ' call.  That is what converts the real to a string.  If no calls to rtos, then let me know if Alan isn't able to help you sooner, and I will look at the code to see if I can find a way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #9 on: February 11, 2009, 03:10:16 PM »
Thanks for the response T.

I tried that and found:

 (setq numstr (rtos lastval 2 Prec))

In looking everything over, I'm not clear what to change.
Units are set correctly in my drawing.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #10 on: February 11, 2009, 03:33:06 PM »
It's not a simple fix because the code is not simple.
Looks like the 32 1/16 is an type 5  Fractional Number which I seldom use and didn't test. :)

Let me see what I can do to resolve that.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #11 on: February 11, 2009, 04:07:28 PM »
Another attempt :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #12 on: February 11, 2009, 04:48:45 PM »
You're not kiddin' the code is not simple! :?


Getting much better.

However in dealing with 32nds it rounds up to nearest 16th

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #13 on: February 11, 2009, 04:53:49 PM »
What is the string to be incremented?
What is the increment amount exactly as entered?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #14 on: February 11, 2009, 11:19:35 PM »
29 29/32 (exact string)incremented by 1 1/2 should = 31 13/32 (not 31 7/16)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #15 on: February 12, 2009, 01:24:18 AM »
Thanks, here is a quick fix.
I will clean up the routine tomorrow.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #16 on: February 12, 2009, 08:57:22 AM »
Thank you, your Lispness!

I bow before your mighty parenthesisesence!

Very intense routine and works great for my needs.


However, it would not change a whole number though.


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #17 on: February 12, 2009, 10:42:06 AM »
Thanks for your kind words.

When I fix one issue another crops up, but this version seems to be close.
Still have some issues but please report any you find.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #18 on: February 12, 2009, 01:55:37 PM »
At this stage of the routine:

Enter increment value: <1>1 1/2

I get this error:

Error: bad argument type: numberp: nilundo Current settings: Auto = On, Control
= All, Combine = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: end

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #19 on: February 12, 2009, 11:20:02 PM »
Well hang with me a little longer. I'll get this one nailed down yet.
Now you see why I was dragging my feet in adding support for fractions. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #20 on: February 13, 2009, 09:14:37 AM »
Hey Cab

You been working so hard on this.......I'm giving you the weekend off.

In the mean time, I get to shovel snow

M-dub

  • Guest
Re: Add-Subtract Routine for Architectural/fractions
« Reply #21 on: February 13, 2009, 09:28:52 AM »
So many fractions!!!  :|

Wouldn't this be easier if we were all in metric?!  ;) :evil:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Add-Subtract Routine for Architectural/fractions
« Reply #22 on: February 13, 2009, 09:30:30 AM »
united we stand, divided we fall!!

oh wait, wrong thread
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #23 on: February 13, 2009, 09:41:17 AM »
Metric is the way to go but I fear fractions will be with us for quite some time. :|
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

M-dub

  • Guest
Re: Add-Subtract Routine for Architectural/fractions
« Reply #24 on: February 13, 2009, 09:43:29 AM »
Metric is the way to go but I fear fractions will be with us for quite some time. :|

Couldn't agree more.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #25 on: February 13, 2009, 04:41:01 PM »
See if this works for you.  Seems to work on the two test strings here.  Will update all numbers found within the string.

Code: [Select]
(defun ParseStringDigit (String / cnt tempStr EndList LenStr cStr bIsDigit)
   
    (setq LenStr (strlen String))
    (setq cnt 2)
    (setq tempStr (substr String 1 1))
    (if (<= 48 (ascii tempStr) 57)
        (setq bIsDigit T)
    )
    (while (<= cnt LenStr)
        (setq cStr (substr String cnt 1))
        (setq cAscii (ascii cStr))
        (if bIsDigit
            (if
                (or
                    (<= 45 cAscii 57)
                    (equal cAscii 39)
                    (and
                        (equal cAscii 32)
                        (<= 45 (ascii (substr String (1+ cnt) 1)) 57)
                        (vl-string-search "/" String cnt)
                        (or
                            (not (vl-string-search " " String (+ 2 cnt)))
                            (<
                                (vl-string-search "/" String cnt)
                                (vl-string-search " " String (+ 2 cnt))
                            )
                        )
                    )
                )
                (setq tempStr (strcat tempStr cStr))
                (progn
                    (setq EndList
                        (cons
                            (if
                                (or
                                    (vl-string-search "." tempStr)
                                    (vl-string-search "/" tempStr)
                                    (vl-string-search "-" tempStr)
                                )
                                (progn
                                    (setq rtosType
                                        (cond
                                            ((vl-string-search "'" tempStr)
                                                4
                                            )
                                            ((vl-string-search "/" tempStr)
                                                3
                                            )
                                            (t 2)
                                        )
                                    )
                                    (list
                                        "Real"
                                        tempStr
                                        rtosType
                                        (if (equal rtosType 2)
                                            (if (setq tempPos (vl-string-search "." tempStr))
                                                (strlen (substr tempStr (+ 2 tempPos)))
                                                0
                                            )
                                            (if (setq tempPos (vl-string-search "/" tempStr))
                                                (WhatExponent (atoi (substr tempStr (+ 2 tempPos))) 2)
                                                0
                                            )
                                        )
                                    ) ;(distof tempStr 4)
                                )
                                (cons "Int" tempStr) ;(atoi tempStr)
                            )
                            EndList
                        )
                    )
                    (setq bIsDigit nil)
                    (setq tempStr cStr)
                )
            )
            (if (<= 48 cAscii 57)
                (progn
                    (setq EndList (cons tempStr EndList))
                    (setq bIsDigit T)
                    (setq tempStr cStr)
                )
                (setq tempStr (strcat tempStr cStr))
            )
        )
        (setq cnt (1+ cnt))
    )
    (reverse
        (cons
            (if (<= 48 cAscii 57)
                (if
                    (or
                        (vl-string-search "." tempStr)
                        (vl-string-search "/" tempStr)
                        (vl-string-search "-" tempStr)
                    )
                    (progn
                        (setq rtosType
                            (cond
                                ((vl-string-search "'" tempStr)
                                    4
                                )
                                ((vl-string-search "/" tempStr)
                                    5
                                )
                                (t 2)
                            )
                        )
                        (list
                            "Real"
                            tempStr
                            rtosType
                            (if (equal rtosType 2)
                                (if (setq tempPos (vl-string-search "." tempStr))
                                    (strlen (substr tempStr (+ 2 tempPos)))
                                    0
                                )
                                (if (setq tempPos (vl-string-search "/" tempStr))
                                    (WhatExponent (atoi (substr tempStr (+ 2 tempPos))) 2)
                                    0
                                )
                            )
                        ) ;(distof tempStr 4)
                    )
                    (cons "Int" tempStr) ;(atoi tempStr)
                )
                tempStr
            )
            EndList
        )
    )
)
(defun AddNumbersTo ( inList inNum )
   
    (mapcar
        '(lambda (x)
            (if (equal (type x) 'LIST)
                (if (= (car x) "Real")
                    (rtos (+ (distof (cadr x) 3) inNum) (caddr x) (cadddr x))
                    (atoi (+ (atoi (cdr x)) inNum))
                )
                x
            )
        )
        inList
    )
)
(defun WhatExponent ( num expNum / cnt tempNum )
   
    (setq cnt 1)
    (setq tempNum expNum)
    (while (not (equal num tempNum))
        (setq tempNum (* tempNum expNum))
        (setq cnt (1+ cnt))
    )
)
(defun c:Test (/ AddNum Sel Obj)
   
    (if
        (and
            (setq AddNum (getstring T "\n Enter number to add: "))
            (setq AddNum (distof AddNum))
            (not (equal AddNum 0))
            (setq Sel (entsel "\n Select entity to add to: "))
            (setq Obj (vlax-ename->vla-object (car Sel)))
        )
        (vla-put-TextString Obj (apply 'strcat (AddNumbersTo (ParseStringDigit (vla-get-TextString Obj)) AddNum)))
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #26 on: February 13, 2009, 05:05:44 PM »
Haven't tried all these but did get some errors.


abc 3.5..       
abc 3 1/2       
abc 3 1/2"
abc 3 1/2'       
abc 3'-1"
abc 3'-1         
abc 3' 1                   
abc 3' 1"
abc 3' 1 1/2               
abc 3'-1-1/2     
abc 3' 1 1/2"             
abc 3' 1.5                 
abc 3'.5         
abc 3'0.5       
abc 3'-0.5       
abc 3'-0.5"       
abc -10         
abc .5           
abc 0.5         
abc 1/2         
abc 1/2"       
abc 9 1/2       
abc 1.55E+01     
abc 5 A         
00000           
abc             
abc 3' -1
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #27 on: February 13, 2009, 05:07:58 PM »
Thanks, Tim

It's close.
Here's the test results

in adding 1 1/32

to 14 1/4 = 15 1/4
to 47 29/32 = 48 15/16
to 48 15/16 = 50

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #28 on: February 13, 2009, 05:37:38 PM »
Alan,

  It does error on ones that ' distof ' doesn't know what to do with.  There are so many combinations that could be wrong, that I don't really know how one could code for all occurances, unless the code is super huge, which I was not trying to do.   :wink:  I did test most of your list though.  I can go through it again, and have a better type of error handling.

Biscuits,

  The reason why yours didn't work is two fold.  One is that the code looks at the string that is current, and then detimenes what percision is needed.  So when the base number has a lower percision than the one being added to it, it doesn't recognize it.  And the second is the way that acad translates strings->reals and reals->strings.  This is a know issue.  I'm not quite sure how to get around it at the moment.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #29 on: February 13, 2009, 06:08:15 PM »
Here we go.  This one seems to be working better.  Let me know.

Alan,

  On your old list, these are the ones it couldn't do.  Not saying that it translated them right, but these are the ones it couldn't do at all.
Quote
Command: (foreach i lst (addnumbersto (parsestringdigit i 0) 1.5))(princ)

 Could not translate: 10-1 into a number.
 Could not translate: 10-1 into a number.
 Could not translate: 3'- into a number.
 Could not translate: 10-1 into a number.
 Could not translate: 10-1 into a number.
 Could not translate: 10-1-5 into a number.

Code: [Select]
(defun ParseStringDigit (String basePrec / cnt tempStr EndList LenStr cStr bIsDigit)
   
    (setq LenStr (strlen String))
    (setq cnt 2)
    (setq tempStr (substr String 1 1))
    (if (<= 48 (ascii tempStr) 57)
        (setq bIsDigit T)
    )
    (while (<= cnt LenStr)
        (setq cStr (substr String cnt 1))
        (setq cAscii (ascii cStr))
        (if bIsDigit
            (if
                (or
                    (<= 45 cAscii 57)
                    (equal cAscii 39)
                    (and
                        (equal cAscii 32)
                        (<= 45 (ascii (substr String (1+ cnt) 1)) 57)
                        (vl-string-search "/" String cnt)
                        (or
                            (not (vl-string-search " " String (+ 2 cnt)))
                            (<
                                (vl-string-search "/" String cnt)
                                (vl-string-search " " String (+ 2 cnt))
                            )
                        )
                    )
                )
                (setq tempStr (strcat tempStr cStr))
                (progn
                    (setq EndList
                        (cons
                            (if
                                (or
                                    (vl-string-search "." tempStr)
                                    (vl-string-search "/" tempStr)
                                    (vl-string-search "-" tempStr)
                                    (vl-string-search "'" tempStr)
                                )
                                (progn
                                    (setq rtosType
                                        (cond
                                            ((vl-string-search "'" tempStr)
                                                4
                                            )
                                            ((vl-string-search "/" tempStr)
                                                5
                                            )
                                            (t 2)
                                        )
                                    )
                                    (setq tempPrec
                                        (if (equal rtosType 2)
                                            (if (setq tempPos (vl-string-search "." tempStr))
                                                (strlen (substr tempStr (+ 2 tempPos)))
                                                0
                                            )
                                            (if (setq tempPos (vl-string-search "/" tempStr))
                                                (WhatExponent (atoi (substr tempStr (+ 2 tempPos))) 2)
                                                0
                                            )
                                        )
                                    )
                                    (list
                                        "Real"
                                        tempStr
                                        rtosType
                                        (if (> basePrec tempPrec)
                                            basePrec
                                            tempPrec
                                        )
                                    ) ;(distof tempStr 4)
                                )
                                (cons "Int" tempStr) ;(atoi tempStr)
                            )
                            EndList
                        )
                    )
                    (setq bIsDigit nil)
                    (setq tempStr cStr)
                )
            )
            (if (<= 48 cAscii 57)
                (progn
                    (setq EndList (cons tempStr EndList))
                    (setq bIsDigit T)
                    (setq tempStr cStr)
                )
                (setq tempStr (strcat tempStr cStr))
            )
        )
        (setq cnt (1+ cnt))
    )
    (reverse
        (cons
            (if (<= 48 cAscii 57)
                (if
                    (or
                        (vl-string-search "." tempStr)
                        (vl-string-search "/" tempStr)
                        (vl-string-search "-" tempStr)
                        (vl-string-search "'" tempStr)
                    )
                    (progn
                        (setq rtosType
                            (cond
                                ((vl-string-search "'" tempStr)
                                    4
                                )
                                ((vl-string-search "/" tempStr)
                                    5
                                )
                                (t 2)
                            )
                        )
                        (setq tempPrec
                            (if (equal rtosType 2)
                                (if (setq tempPos (vl-string-search "." tempStr))
                                    (strlen (substr tempStr (+ 2 tempPos)))
                                    0
                                )
                                (if (setq tempPos (vl-string-search "/" tempStr))
                                    (WhatExponent (atoi (substr tempStr (+ 2 tempPos))) 2)
                                    0
                                )
                            )
                        )
                        (list
                            "Real"
                            tempStr
                            rtosType
                            (if (> basePrec tempPrec)
                                basePrec
                                tempPrec
                            )
                        ) ;(distof tempStr 4)
                    )
                    (cons "Int" tempStr) ;(atoi tempStr)
                )
                tempStr
            )
            EndList
        )
    )
)
(defun AddNumbersTo ( inList inNum / testNum )
   
    (mapcar
        '(lambda (x)
            (if (equal (type x) 'LIST)
                (if (= (car x) "Real")
                    (if (setq testNum (distof (cadr x) 3))
                        (rtos (+ testNum inNum) (caddr x) (cadddr x))
                        (progn
                            (prompt (strcat "\n Could not translate: " (cadr x) " into a number."))
                            (cadr x)
                        )
                    )
                    (rtos (+ (atoi (cdr x)) inNum) 2 0)
                )
                x
            )
        )
        inList
    )
)
(defun WhatExponent ( num expNum / cnt tempNum )
   
    (setq cnt 1)
    (setq tempNum expNum)
    (while (< tempNum num)
        (setq tempNum (* tempNum expNum))
        (setq cnt (1+ cnt))
    )
    cnt
)
(defun c:Test (/ AddNum Sel Obj LowPrec)
   
    (if
        (and
            (setq AddNum (getstring T "\n Enter number to add: "))
            (setq LowPrec
                (cond
                    ((setq tempPos (vl-string-search "." tempStr))
                        (strlen (substr tempStr (+ 2 tempPos)))
                    )
                    ((setq tempPos (vl-string-search "/" tempStr))
                        (WhatExponent (atoi (substr tempStr (+ 2 tempPos))) 2)
                    )
                    (t 0)
                )
            )
            (setq AddNum (distof AddNum))
            (not (equal AddNum 0))
            (setq Sel (entsel "\n Select entity to add to: "))
            (setq Obj (vlax-ename->vla-object (car Sel)))
        )
        (vla-put-TextString Obj (apply 'strcat (AddNumbersTo (ParseStringDigit (vla-get-TextString Obj) LowPrec) AddNum)))
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #30 on: February 13, 2009, 06:34:33 PM »
Here you go Alan.  The return is in the square brackets.  I see there is some room for improvement.   :-D
Code: [Select]
(foreach i lst
    (PROMPT
        (STRCAT
            "\n"
            I
            " [ "
            (APPLY
                'STRCAT
                (addnumbersto
                    (parsestringdigit i 0)
                    1.
                )
            )
            " ]"
        )
    )
)(princ)
Code: [Select]
Could not translate: 10-1 into a number.
abc 10-1       [ abc 10-1       ]
 Could not translate: 10-1 into a number.
abc -10-1      [ abc -10-1      ]
abc 3.5        [ abc 4.5        ]
abc 3 1/2      [ abc 4 1/2      ]
abc 3 1/2"     [ abc 4 1/2"     ]
abc 3 1/2'     [ abc 3'-7"     ]
abc 3-1/2'     [ abc 3'-7"     ]
abc 3'-1"      [ abc 3'-2""      ]
abc 3'-1       [ abc 3'-2"       ]
abc 3' 1       [ abc 3'-1" 2       ]
abc 3' 1"      [ abc 3'-1" 2"      ]
abc 3' 1 1/2   [ abc 3'-2 1/2"   ]
abc 3'-1-1/2   [ abc 3'-2 1/2"   ]
abc 3' 1 1/2"  [ abc 3'-2 1/2""  ]
abc 3' 1.5     [ abc 3'-1" 2.5     ]
abc 3'.5      [ abc 3'-2"      ]
abc 3' .5      [ abc 3'-1" .6      ]
abc 3'0.5      [ abc 3'-2"      ]
abc 3'-0.5      [ abc 3'-2"      ]
abc 3' 0.5      [ abc 3'-1" 1.5      ]
abc -10        [ abc -11        ]
abc .5         [ abc .6         ]
abc 0.5        [ abc 1.5        ]
abc 5 -2       [ abc 6 -3       ]
abc 1/2        [ abc 1 1/2        ]
abc 1/2"       [ abc 1 1/2"       ]
abc 9 1/2      [ abc 10 1/2      ]
abc 1.55E+01   [ abc 2.55E+2   ]
abc 5 A        [ abc 6 A        ]
00000 [ 1 ]
abc [ abc ]
abc 3' -1"      [ abc 3'-1" -2"      ]
 Could not translate: 3'- into a number.
abc 3'- 1"      [ abc 3'- 2"      ]
abc 3' .5      [ abc 3'-1" .6      ]
 Could not translate: 10-1 into a number.
abc 10-1       [ abc 10-1       ]
 Could not translate: 10-1 into a number.
abc -10-1      [ abc -10-1      ]
abc 5A         [ abc 6A         ]
This $5.00  is 75 cents short. [ This $6.00  is 76 cents short. ]
21'  8-1/5" [ 21'-1"  9 1/4" ]
15 cde22 35 21 abc 44 [ 16 cde23 36 22 abc 45 ]
 Could not translate: 10-1-5 into a number.
abc22abc-10-1-5 def 99 [ abc23abc-10-1-5 def 100 ]
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #31 on: February 13, 2009, 06:51:53 PM »
All in all you did a pretty go job.

My routine is to do the following.
Locate the first valid number
Increment the number found by the desired amount.
Replace the found number with the new number with the matching format & precision.
As a bonus it should maintain leading and / or trailing zeros when applicable.

As you know I'm not there yet but I may have some time tomorrow to get back to it.
Biscuits gave me the weekend off.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add-Subtract Routine for Architectural/fractions
« Reply #32 on: February 13, 2009, 07:08:03 PM »
All in all you did a pretty go job.
Thanks Alan.

My routine is to do the following.
Locate the first valid number
Increment the number found by the desired amount.
Replace the found number with the new number with the matching format & precision.
As a bonus it should maintain leading and / or trailing zeros when applicable.
This kind of what mine does.  It takes the string and makes a list out of it.  It parses the string into a list of strings and lists ( if there are numbers within the string ).  The list then states if it is a real or an integer.  If it's a real, it tries to see what format it is in, and find out what precision it is.

The next function it gets passed to adds the number supplied to all numbers within the list.  It also passes what the precision of the number supplied is, so that if it has a greater precision, then it will use that precision instead of the one the number has in the main string.  And then it passes a list of strings back.  Here it also tests to see if it is in a format that the command can use, if not is passes the same string back, and prints to the command line that one of the numbers was not a defined number that the command could use.

I must admit that you put in a little more thought than I did.  And I never would have thought about leaving the leading zeros.

As you know I'm not there yet but I may have some time tomorrow to get back to it.
Biscuits gave me the weekend off.  8-)
Good idea to take the weekend off.  Have fun.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #33 on: February 14, 2009, 11:34:48 AM »
Just got another try between tennis and Valentine Lunch.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #34 on: February 17, 2009, 09:11:53 AM »
This is so close.

The only issue I found, is that it will not add any fractional value to a whole number

Example: 52 + 1 1/2 + 53

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #35 on: February 17, 2009, 09:44:37 AM »
Arggg :-P

 :roll:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #36 on: February 17, 2009, 12:15:54 PM »
How do you feel about Capt'n Morgan and coke with a lime twist?
It's time don't ya think?
I'm buying!

mixed numbers are OK

72 + 1 1/32 = 73.03125

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #37 on: February 17, 2009, 12:38:09 PM »
Aaaah!  Cubra Libra, my favorite, how did you know. :-o
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #38 on: February 17, 2009, 12:49:54 PM »
Me thinks it was the "Arggg"!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #39 on: February 17, 2009, 12:55:34 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Add-Subtract Routine for Architectural/fractions
« Reply #40 on: February 19, 2009, 02:01:25 PM »
I want to thank you guys for sharing all your hard work!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add-Subtract Routine for Architectural/fractions
« Reply #41 on: February 25, 2009, 07:19:35 PM »
You're welcome.

Here is another revision.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.