Author Topic: Fraction equivalent chart  (Read 8872 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fraction equivalent chart
« Reply #15 on: January 30, 2008, 11:57:20 AM »
See if this is what you are looking for.
Code: [Select]
(defun c:Test (/ Sel DimEntData DimDist tempStr LowDist HighDist DistOpt Ang)
   
    (defun FindNextSixteenth (StValue GoHigher)
        (while
            (not
                (equal
                    (rem
                        (setq StValue
                            (
                                (eval (if GoHigher + -))
                                StValue
                                (/ 1. 256)
                            )
                        )
                        (/ 1. 16)
                    )
                    0.0
                )
            )
        )
        StValue
    )
    ;--------------------------------------------------------
    (if
        (and
            (setq Sel (entsel "\n Select dimension: "))
            (setq DimEntData (entget (car Sel)))
            (= (cdr (assoc 0 DimEntData)) "DIMENSION")
            (setq DimDist
                (if (= (setq tempStr (cdr (assoc 1 DimEntData))) "")
                    (cdr (assoc 42 DimEntData))
                    (distof tempStr)
                )
            )
            (setq LowDist (FindNextSixteenth DimDist nil))
            (setq HighDist (FindNextSixteenth DimDist T))
            (not (initget "High Low"))
            (setq DistOpt
                (cond
                   (
                        (getkword
                            (strcat "\n Which way to go [High/Low] from "
                                (rtos DimDist 4 16)
                                " (High = "
                                (rtos HighDist 4 4)
                                ", Low = "
                                (rtos LowDist 4 4)
                                "): "
                            )
                        )
                    )
                    (T nil)
                )
            )
            (setq Ang (getangle "\n Enter angle to stretch at: "))
        )
        (command
            "_.stretch"
            (ssget)
            ""
            '(0. 0. 0.)
            (strcat
                "@"
                (rtos
                    (abs
                        (-
                            (if (= DistOpt "High")
                                HighDist
                                LowDist
                            )
                            DimDist
                        )
                    )
                    2
                    16
                )
                "<"
                (angtos Ang 2 16)
            )
        )
    )
    (princ)
)
Tim

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

Please think about donating if this post helped you.

Kate M

  • Guest
Re: Fraction equivalent chart
« Reply #16 on: January 30, 2008, 01:25:08 PM »
Dan, when I run into those situations I use object snap tracking, rather than a straight move/stretch.

Because you realize that you're still limited to 1/256 precision, right? I ran into something the other day with dimensions of 300.0099999 -- doesn't get caught by fractions, but was still off enough to prevent me from trimming properly.

t-bear

  • Guest
Re: Fraction equivalent chart
« Reply #17 on: January 30, 2008, 02:18:21 PM »
I have had the same problem Kate...it's a real pain with 3D objects!  We draft to 8 decimal points here in an attempt to control that.

Back on topic...I think what Dan is looking for is a chart that gives him the 8 digit equivelant of all 256 divisions of an inch.  Autocad will give you  13/32" which is actually 104/256".  He's hunting a chart in all/256"....right, Dan?  He wants to be able to stretch/move/whatever in 256ths of an inch....

Of course, I've been wrong before.....once....no, twice....LOL

ELOQUINTET

  • Guest
Re: Fraction equivalent chart
« Reply #18 on: January 30, 2008, 02:53:13 PM »
yeeeeeah baby tim you pretty much nailed it buddy. The only thing I was thinking about is could the angle be built in and there be 2 routines, one for stretching horizontally and another for stretching vertically? These would be the only 2 angles I would be stretching, I think.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fraction equivalent chart
« Reply #19 on: January 30, 2008, 03:02:21 PM »
yeeeeeah baby tim you pretty much nailed it buddy. The only thing I was thinking about is could the angle be built in and there be 2 routines, one for stretching horizontally and another for stretching vertically? These would be the only 2 angles I would be stretching, I think.
Yes it could be changed to do that, but I can't get to it right now, w**k.  If you issue it by two commands, then getting the angle to stretch is easier.  All you would have to do is see which value is large for dxf codes 10 (start point) and 13 (end point), because if you are stretching it lower, then it will move them closer, so you know the angles.
Tim

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

Please think about donating if this post helped you.

ELOQUINTET

  • Guest
Re: Fraction equivalent chart
« Reply #20 on: January 30, 2008, 04:01:13 PM »
hmmm strange. The routine worked fine when i tried it out but now when i run it i get to select dimension and when i select the dimension it totally freezes up my pc. i haven't been able to get it to do anything now. i'm trying to figure out what is going on here???

M-dub

  • Guest
Re: Fraction equivalent chart
« Reply #21 on: January 30, 2008, 04:14:25 PM »
Back on topic...I think what Dan is looking for is a chart that gives him the 8 digit equivelant of all 256 divisions of an inch.  Autocad will give you  13/32" which is actually 104/256".  He's hunting a chart in all/256"....right, Dan?  He wants to be able to stretch/move/whatever in 256ths of an inch....


If that's the case, (maybe it is, maybe it isn't) I made this in about 2 minutes.

It's there for the taking, anyway.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fraction equivalent chart
« Reply #22 on: January 30, 2008, 04:54:54 PM »
hmmm strange. The routine worked fine when i tried it out but now when i run it i get to select dimension and when i select the dimension it totally freezes up my pc. i haven't been able to get it to do anything now. i'm trying to figure out what is going on here???
The only thing that I can think of is a situation that Kate described, as there is no point in the code which should freeze you comp.  I guess the code could check to make sure the first value given is divisible by 256, and if so proceed.  Did you try the esc button to exit the command?  I see no reason why that wouldn't work.

I was thinking that it wouldn't be easy to add in the angle part.  How would you know which way to stretch it?  You would have to get the points of the selection to see which way to stretch, which can be done, but I'm not sure how easy it would be to code.
Tim

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

Please think about donating if this post helped you.

ELOQUINTET

  • Guest
Re: Fraction equivalent chart
« Reply #23 on: January 30, 2008, 05:25:47 PM »
yes i can escape out of it tim. so you are saying it is probably trying to divide it by 256 and it cannot so it keeps trying and trying. the angle part is just a bonus but i asked as i'd thought we had it working. forget about the angle for now. mdub i'll look at your file and reply tomorrow as i'm about to leave. thanks guys

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fraction equivalent chart
« Reply #24 on: January 30, 2008, 05:36:50 PM »
See if this gives any notice on the dimension you selected.  Now it will prompt you if the dimension selected is not divisible by 1/256.

Edit: Added the selection set to the and statement.
Code: [Select]
(defun c:Test (/ Sel DimEntData DimDist tempStr LowDist HighDist DistOpt Ang ss)
   
    (defun FindNextSixteenth (StValue GoHigher)
        (while
            (not
                (equal
                    (rem
                        (setq StValue
                            (
                                (eval (if GoHigher + -))
                                StValue
                                (/ 1. 256)
                            )
                        )
                        (/ 1. 16)
                    )
                    0.0
                )
            )
        )
        StValue
    )
    ;--------------------------------------------------------
    (if
        (and
            (setq Sel (entsel "\n Select dimension: "))
            (setq DimEntData (entget (car Sel)))
            (= (cdr (assoc 0 DimEntData)) "DIMENSION")
            (setq DimDist
                (if (= (setq tempStr (cdr (assoc 1 DimEntData))) "")
                    (cdr (assoc 42 DimEntData))
                    (distof tempStr)
                )
            )
            (equal (rem DimDist (/ 1. 256)) 0.0)
            (setq LowDist (FindNextSixteenth DimDist nil))
            (setq HighDist (FindNextSixteenth DimDist T))
            (not (initget "High Low"))
            (setq DistOpt
                (cond
                   (
                        (getkword
                            (strcat "\n Which way to go [High/Low] from "
                                (rtos DimDist 4 16)
                                " (High = "
                                (rtos HighDist 4 4)
                                ", Low = "
                                (rtos LowDist 4 4)
                                "): "
                            )
                        )
                    )
                    (T nil)
                )
            )
            (setq Ang (getangle "\n Enter angle to stretch at: "))
            (setq ss (ssget))
        )
        (command
            "_.stretch"
            ss
            ""
            '(0. 0. 0.)
            (strcat
                "@"
                (rtos
                    (abs
                        (-
                            (if (= DistOpt "High")
                                HighDist
                                LowDist
                            )
                            DimDist
                        )
                    )
                    2
                    16
                )
                "<"
                (angtos Ang 2 16)
            )
        )
        (cond
            ((not ss) (prompt "\n No entities selected to stretch."))
            (Ang (prompt "\n No angle selected."))
            (DistOpt (prompt "\n No angle selected."))
            (HighDist (prompt "\n No new dimension value selected."))
            (DimDist (prompt "\n Dimension value selected is not divisible by 1/256."))
            (DimEntData (prompt "\n Entity selected was not a dimension."))
            ((not Sel) (prompt "\n No entity selected."))
        )
    )
    (princ)
)
« Last Edit: January 30, 2008, 05:42:15 PM by T.Willey »
Tim

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

Please think about donating if this post helped you.

ELOQUINTET

  • Guest
Re: Fraction equivalent chart
« Reply #25 on: January 30, 2008, 05:37:08 PM »
mdub that is very useful but i am having situations where my fractions in my dimensions are reading in /128" and /64ths of an inch so I guess I need several charts. How did you produce this in 2 minutes :kewl:

Josh Nieman

  • Guest
Re: Fraction equivalent chart
« Reply #26 on: January 30, 2008, 05:43:52 PM »
mdub that is very useful but i am having situations where my fractions in my dimensions are reading in /128" and /64ths of an inch so I guess I need several charts. How did you produce this in 2 minutes :kewl:

Probably using Excel and it's loverly formatting.

ELOQUINTET

  • Guest
Re: Fraction equivalent chart
« Reply #27 on: January 31, 2008, 08:57:54 AM »
ummm care to elaborate i'm a bit of a novice when it comes to excel.

ELOQUINTET

  • Guest
Re: Fraction equivalent chart
« Reply #28 on: January 31, 2008, 09:12:06 AM »
you know i was thinking about this last night and some of the input about it still rounding and the model not being completely accurate got me to thinking. I have this routine for drawing reference lines (sorry I don't know who wrote it). I had been using it to offset to the correct distance then stretch the model and erase it after. Here's some psuedo code of what it might do:

you pick the dimension
it would return the range and ask if you want to go high or low
it would ask you to pick the origin point
it would get the offset distance based on the answer high or low
it will ask you to pick a side to offset
then it will start the stretch command
it would be a bonus if it erased the reference line after

incorporating the reference line is the only way i could think of that would insure that the distance is true.
does this make sense and is this doable?

Code: [Select]
;;; DRAWS A LINE THEN ASKS WHICH SIDE TO OFFSET AND DISTANCE, REFERENCE LINE

(defun c:rl (/ usercmd en1 clay dist)
  ;; -------  Some Housekeeping   ------------------
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq clay (getvar 'clayer))
  (command "_.layer" "m" "0" "C" BLACK "" "")
  (setq useros (getvar "osmode"))
  (setvar "osmode" 175)
  (prompt "/nPick points, Enter when done.")
  ;; Draw the pline
  (command "PLINE") ;_ COMMAND
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (setq en1 (entlast))
  (initget 1)
  (setq pto (getpoint "\nSide to offset:"))
  (setq dist (getreal "\nEnter offset distance:"))
  (command "_.offset" dist en1 pto "")
  (entdel en1) ; remove the user drawn line

  ;;==========  Exit Sequence  ============
  (setvar "CMDECHO" usercmd)
  (setvar "clayer" clay)
  ;; Exit quietly
  (princ)

) ;_end of defun

M-dub

  • Guest
Re: Fraction equivalent chart
« Reply #29 on: January 31, 2008, 09:44:58 AM »
mdub that is very useful but i am having situations where my fractions in my dimensions are reading in /128" and /64ths of an inch so I guess I need several charts. How did you produce this in 2 minutes :kewl:

Probably using Excel and it's loverly formatting.

You got 'er, Josh.

The explaination will make it sound like a lot of work, but it's really very simple.

All I did was to put the number 1 in cell A1.  Put the cursor in cell A1, then right click & drag the tiny black square at the bottom right corner of it all the way down to cell A256, release the right mouse button and select "Fill Series".  You will then have them all filled out from 1 to 256.

Then, in cell B1, just put "256" and hit enter.  Again, place the cursor back on B1 and double click the tiny black square at the bottom right corner and excel should fill the number "256" all the way down to B256.  (The double click trick will fill whatever you have down to the last adjacent populated cell, if that makes sense)

In cell C1, type "=sum(a1/b1)" and hit enter.  Again, place the cursor back on C1 and double click the tiny black square at the bottom right corner and excel will perform the calculation all the way down, giving you the decimal equivelent.

Now, highlight cells C1 to C256 and hit Ctrl+C.  Place cursor in C1, right click and select Paste Special.  Check "Values" from the popup and hit Ok.

The method I used to get the fraction was to place the cursor in D1 and type "=CONCATENATE(a1,"/",b1)" and hit enter.  Again, place the cursor back on D1 and double click the tiny black square at the bottom right corner and excel will combine the strings from column A, then add the forward slash, followed by the string from column B.  Once that's done, highlight cells D1 to D256 and hit Ctrl+C.  Place cursor in D1, right click and select Paste Special.  Check "Values" from the popup and hit Ok.

Now you can delete columns A and B and you can arrange it however you want.  If you wanted a similar chart for other fractions (*/128, */64, etc.), just change the number 256 in the description above to whatever it is you're looking for and the rest of it still applies.

Clear as mud?