Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Extract attributes in numerical order

isrsol702
Enthusiast

Extract attributes in numerical order

isrsol702
Enthusiast
Enthusiast

Hello Everyone,

 

I need help extracting fractional number in numerical order. as reference, we use a number plus this symbol ~ followed by one of these numbers or symbols "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" " "/" "\"" "q" "w" "e" "r" "t" to denote 1/16" increments. E.g 5~1 = 5 1/16" or 5~2 = 5 1/8" and so on, Thank you for your help. (I'm not an expert on lisp routines, I just self taught enough to do small tweaks)

 

here is the actual lisp

 

(defun c:chairbom ()
   

(setq scalelist '(192.0 128.0 96.0 72.0 48.0 36.0 24.0 16.0 12.0 8.0 1270.0 2540.0 3810.0 5080.0 6350.0 7620.0 8890.0 10160.0 11430.0 12700.0))
   ;PROGRAM TO READ ATTRIBUTE FILE (C:\ACADWIN\PT\CHAIRBOM.TXT)
   ;AND TO WRITE A CHAIR BILL-OF-MATERIALS BACK TO DRAWING
(setvar "CMDECHO" 0)

;EXTRACT ATTRIBUTES
(setvar "FILEDIA" 0)
(command "attext" "" "c:\\apps\\PT_CAD\\bom\\chairtem.txt"
         "c:\\chairbom.txt")
(prompt "Please wait for processing of attributes")(terpri)
(setvar "FILEDIA" 1)
(prompt "Please wait")(terpri)

(setq a (open "c:\\chairbom.txt" "r"))
(setq charlist
   '("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "~" "/" "\"" "q" "w" "e" "r" "t"))
(setq scale (getvar "dimscale"))
(if (not (member scale scalelist))
   (progn
      (setq scale (getreal "Enter scale factor - 96 for 1/8\", 128 for 3/32\", 192 for 1/16\" [SCALE FACTOR X 25.4 FOR METRIC]: "))
      (setvar "dimscale" scale)
   )
)
(if (= (cdr (assoc '40 (tblsearch "style" (getvar "textstyle")))) 0.0)
   (command "style" "ROMANS" "ROMANS.shx,SPECIAL.shx" (/ (getvar "dimscale") 8.0) 0.9 0 "N" "N" "N")  
)
(setq chrhts '())
(setq alist '())
(listatt)
(close a)
(setq sp (getpoint "Pick starting point for chair schedule: "))
(printatt (length slist) 0 sp)
(setvar "CMDECHO" 1)
(if (/= omo nil)
   (setvar "osmode" omo)
)
)

(defun listatt ()
   (while (setq l (read-line a))  
      (setq cl (proline l 1 nil nil ""))
      (setq lastc (substr (car cl) (strlen (car cl)) 1))

;;;;;;;;;;;  REVISION TO PROGRAM ON 2/22/99 TO HANDLE NO QUANTITY CALLOUT IN MULT. CHAIR BLOCK ;;;;;;;
;;;;;;;;;;    AND TO CONSOLIDATE CALLOUTS W/ AND W/O INCH MARKS ;;;;;;;

      (if (/= lastc "\"")
          (progn
             (setq htinch (strcat (car cl) "\""))
             (setq cl (list htinch (cadr cl)))
          )
      )
      (if (= (cadr cl) 0)             ;IF QUANTITY IS 0 THEN CHAIR CALLOUT QUANTITY IS TWO
          (setq cl (subst 2 0 cl))
      )
     ;;;;;;; END REVISION ;;;;;;;;;

      (if (not (member (car cl) chrhts))
          (progn
             (setq chrhts (cons (car cl) chrhts))
             (setq alist (cons cl alist))
          )
          (progn
             (setq old (assoc (car cl) alist))
             (setq new (append old (cdr cl)))
             (setq alist (subst new old alist))
          )
      )
   )
   (setq slist '())
   (foreach x alist
      (setq slist (cons (list (car x) (apply '+ (cdr x))) slist)))
)

(defun proline (l cn 2f h n / hnl cc )
   (setq cc (substr l cn 1))  
   (cond ((= cn (1+ (strlen l)))
          (setq hnl (list h (atoi n)))
         )
         ((and (member cc charlist) (not 2f))
          (if (= h nil)
              (setq h cc)
              (setq h (strcat h cc))
          )
          (proline l (1+ cn) nil h n)
         )
         ((= cc ",") (proline l (1+ cn) T h n))
         ((and (member cc charlist) 2f)
          (if (= n "")
              (setq n cc)
              (setq n (strcat n cc))
          )
          (proline l (1+ cn) T h n)
         )
         (T (proline l (1+ cn) 2f h n))
   )
)
(defun printatt (n i sp)
   (setq l (car (nth i slist)))
   (command "text" sp 0 l)
   (setq l (itoa (cadr (nth i slist))))
   (setq np (list (+ (car sp) (* scale 0.75)) (cadr sp)))
   (command "text" np 0 l)
   (setq sp (list (car sp) (- (cadr sp) (/ scale 3))))
   (setq i (1+ i))
   (if (< i n) (printatt n i sp))
)

0 Likes
Reply
Accepted solutions (1)
1,255 Views
8 Replies
Replies (8)

pbejse
Mentor
Mentor

@isrsol702 wrote:

 

I need help extracting fractional number in numerical order. as reference, we use a number plus this symbol ~...

 


I get what you mean by extracting, but not clear about numerical order, can you explain more about the latter isrsol702 

0 Likes

isrsol702
Enthusiast
Enthusiast

Hi pbejse

 

when I run this lisp, it will spit all the numbers but it will not do it in numerical order E.g.

 

1

1 1/4"

1 1/2"

1 3/4"

2

2 1/4"

 

see the pic attached. the row of numbers on the left are the symbols we use as a short cut to enter fractional numbers. the row of numbers on the right are the numbers who's fonts were corrected to show the fraction number properly.

 

Also, just to be clear,  in each row you can see two sets of number E.g.  3~4 1497 = 3 1/4" 1497

 

3 1/4" refers to the chair size

1497 refers to the number of chairs needed for that size.

 

Thank you for your help

0 Likes

pbejse
Mentor
Mentor

@isrsol702 wrote:

Hi pbejse

 

when I run this lisp, it will spit all the numbers but it will not do it in numerical order E.g.

 

1

1 1/4"

1 1/2"

1 3/4"

2

2 1/4"

 


Pardon my ignorance on fractions, so what it the correct order the of the above list?

 

 

0 Likes

isrsol702
Enthusiast
Enthusiast

When I run the lisp, it will produce a list of chairs, much like in the picture I attached on my last reply, the list is created in a scramble fashion. I would like for the lisp to produce the list with the chair sizes in numerical order.

 

E.g. This is how the lisp will produce the chair list

 

5 1/4"

6 1/2"

3 3/4"

2 1/2"

and so on

 

I need them to come in the following order

2 1/2"

3 3/4"

5 1/4"

6 1/2"

and so on

0 Likes

pbejse
Mentor
Mentor

@isrsol702 wrote:

When I run the lisp, it will produce a list of chairs, much like in the picture I attached on my last reply, the list is created in a scramble fashion. I would like for the lisp to produce the list with the chair sizes in numerical order.

 

E.g. This is how the lisp will produce the chair list

 

5 1/4"

6 1/2"

3 3/4"

2 1/2"

and so on

 

I need them to come in the following order

2 1/2"

3 3/4"

5 1/4"

6 1/2"

and so on


It looks & sounds easy, It's just that the code you posted is confusing the bejesus out of me. Smiley Very Happy

 

To simplify, give me the fraction equivalent of this list and its order.

 

 

(setq charlist '("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "~" "/" "\"" "q" "w" "e" "r" "t"))

This way there'll be no need for a new code, variable slist will be sorted before it comes out of listatt function

 

 

 Hang on, isn't  acad_strlsort function enough for your requirements?

 

or one of the two

 

(foreach x (vl-sort alist '(lambda (a b) (< (Car a)(car b))))
      (setq slist (cons (list (car x) (apply '+ (cdr x))) slist)))


(foreach x (vl-sort alist '(lambda (a b) (> (Car a)(car b))))
(setq slist (cons (list (car x) (apply '+ (cdr x))) slist)))

 

0 Likes

isrsol702
Enthusiast
Enthusiast
(setq charlist '("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "~" "/" "\"" "q" "w" "e" "r" "t")

1 = 1/16

2 = 1/8

3 = 3/16

4 = 1/4

5 = 5/16

6 = 3/8

7 = 7/16

8 = 1/2

9 = 9/16

10 = 5/8

q = 11/16

w = 3/4

r = 7/8

t = 15/16

 

may be those code you gave me will work, but where exactly in the lisp routine would I insert them to try them.

 

 

0 Likes

pbejse
Mentor
Mentor

isrsol702 wrote:

......may be those code you gave me will work, but where exactly in the lisp routine would I insert them to try them.  


Unfortunately, it's not going to give the correct order, I just tried it. Don't worry, I'll modify your code if you don't get a solution by tomorrow morning, But  I'm sure it will be sorted by then Smiley Very Happy You're in good hands here.

 

And that list you just posted will help a lot, I can see it now.

 

 

Hang in there... any minute now.... Smiley Happy 

 

signing-off

0 Likes

pbejse
Mentor
Mentor
Accepted solution
Not really sure without running your code,  assuming alist variable look something like this

 

'(("1 1/16" 12 36 854 695)
              ("2 1/8" 23 85 854 3 15)
              ("2 3/16" 23 85 854 3 15)
              ("1/4" 23 85 854 3 15)
              ("5/16" 23 85 854 3 15)
              ("3/8" 23 85 854 3 15)
              ("7/16" 23 85 854 3 15)
              ("1/2" 23 85 854 3 15)
              ("1 9/16" 23 85 854 3 15)
              ("5/8" 23 85 854 3 15)
              ("5 11/16" 23 85 854 3 15)
              ("3/4" 23 85 854 3 15)
              ("7/8" 23 85 854 3 15)
              ("15/16" 23 85 854 3 15)
              )

 

Then this should work

 

(defun listatt ()
   (while (setq l (read-line a))  
      (setq cl (proline l 1 nil nil ""))

.......... (setq slist '()) (foreach x (vl-sort alist '(lambda (a b) (> (distof (Car a)) (distof (car b))))) (setq slist (cons (list (car x) (apply '+ (cdr x))) slist)) ) )

 

if not, we may need to modify  your codes' conversion from ~4  to fraction format the way distoff can understand.

HTH

 

0 Likes