TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: V-Man on February 11, 2015, 08:02:15 AM

Title: Trouble - Need Assistance
Post by: V-Man on February 11, 2015, 08:02:15 AM
Taken from http://www.theswamp.org/index.php?topic=48753.0 (http://www.theswamp.org/index.php?topic=48753.0) , I am trying to put a little spin on this. We use wide flange beams for columns and they are nothing more than a closed lwpolyline (not a block). This routine does work and reports on each column the size of the column in the "X" and "Y" direction. Having the dimensions for the wide flange columns is great but it would be more powerful if it also reported the actual name of the column. For instance, W6x12 or w10x12 etc...

So basically for a W6x12 the dims are (X)4.0 and (Y)6.0
and a W10x12 the dims would be (X)4.0 and (Y)9.875

The routine already reports the (X) and (Y) dimensions of all columns in the drawing, I just want it to also add the name of the column based on the size. I do have the sizes of all of the wide flanged beams that we use. I am just having loads of issues trying to modify this to do what I want.

Code: [Select]
(defun c:CCS ( / mn mx peditaccept plinecnt pntnX pntxX ss)
  (vl-load-com)
  (command "-layer" "on" "Defpoints" "thaw" "Defpoints" "")
  (if
    (setq ss (ssget "_X" '((0 . "Arc,Line,lwpolyline")
 (8 . "S-COLS,A-WALL-SHEL-EXST"))))
    (progn
      (setq peditaccept (getvar 'peditaccept))
      (setvar 'peditaccept 1)
      (setvar 'peditaccept peditaccept)
    )
  )
  (setq plinecnt 0)
  (if (setq ss (ssget "_X" '((0 . "LWPOLYLINE")(8 . "S-COLS,A-WALL-SHEL-EXST"))))
    (repeat (sslength ss)
      (vla-getboundingbox (vlax-ename->vla-object (ssname ss plinecnt)) 'mn 'mx)
      (setq mn (vlax-safearray->list mn))
      (setq mx (vlax-safearray->list mx))
      (setq pntnX (nth 0 mn))  (setq pntnY (nth 1 mn))
      (setq pntxX (nth 0 mx))  (setq pntxY (nth 1 mx))
           (setq dvx (- pntxX pntnX));added
           (setq dvy (- pntxY pntnY));added
           (scheck);added
     ; (InsText (strcat "Size" " = "(rtos (- pntxX pntnX) 4 16) " x " (rtos (- pntxY pntnY) 4 16)) (list pntxX pntnY 0.0));original code
     (InsText (strcat "Size" " = "(rtos (- pntxX pntnX) 4 16) " x " (rtos (- pntxY pntnY) 4 16) " - " dvSize) (list pntxX pntnY 0.0));modified
      (setq plinecnt (1+ plinecnt))
    )
  )
);end defun
(defun InsText ( BlkName pt / )
  (entmakex
    (list
      (cons 0  "TEXT")
      (cons 8  "Defpoints")
      (cons 1  BlkName)
      (cons 10 Pt)
      (cons 40 5)
      (cons 41 0.8)
    )
  )
);end defun

The output currently for each column is as follows:

Size = 4" x 6"

Size = 4" x 9 7/8"

I would like it to be...
Size = 4" x 6" - W6x12

Size = 4" x 9 7/8" - W10x12

etc..

Here is a snippet of my column sizes..
Code: [Select]
(defun scheck ()
(if
    (and (= dvx 4.0) (= dvy 4.125)
    )
         (setq dvSize "W4x13")
         (setq dvSize "nil")
)
(if
    (and (= dvx 5.0) (= dvy 5.0)
    )
         (setq dvSize "W5x16")
         (setq dvSize "nil")
)
(if
    (and (= dvx 5.0) (= dvy 5.125)
    )
         (setq dvSize "W5x18.5")
         (setq dvSize "nil")
)
(if
    (and (= dvx 5.0) (= dvy 5.125)
    )
         (setq dvSize "W5x19")
         (setq dvSize "nil")
)
(if
    (and (= dvx 4.0) (= dvy 5.875)
    )
         (setq dvSize "W6x9")
         (setq dvSize "nil")
)
)

I hope that I am not asking too much. I am just stuck. Any guidance or help would be great.

Thanks,
Title: Re: Trouble - Need Assistance
Post by: kpblc on February 11, 2015, 08:33:05 AM
Use cond function. Or you can use associated lists - I think it will be more functionality.
Should i write code sample?
Title: Re: Trouble - Need Assistance
Post by: ronjonp on February 11, 2015, 08:38:48 AM
Something like this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ccs (/ instext scheck dvx dvy mn mx peditaccept plinecnt pntnx pntny pntxx pntxy ss)
  2.   (defun instext (text pt /)
  3.     (entmakex (list (cons 0 "TEXT")
  4.                     (cons 8 "Defpoints")
  5.                     (cons 1 text)
  6.                     (cons 10 pt)
  7.                     (cons 40 5)
  8.                     (cons 41 0.8)
  9.               )
  10.     )
  11.   )                                     ;end defun
  12.   (defun scheck (dvx dvy)
  13.     (cond ((and (= dvx 4.0) (= dvy 4.125)) "W4x13")
  14.           ((and (= dvx 5.0) (= dvy 5.0)) "W5x16")
  15.           ((and (= dvx 5.0) (= dvy 5.125)) "W5x18.5")
  16.           ((and (= dvx 5.0) (= dvy 5.125)) "W5x19")
  17.           ((and (= dvx 4.0) (= dvy 5.875)) "W6x9")
  18.           ("nil")
  19.     )
  20.   )
  21.   ;; (alert (scheck 5.0 5.0))
  22.   (command "-layer" "on" "Defpoints" "thaw" "Defpoints" "")
  23.   (if (setq ss (ssget "_X" '((0 . "Arc,Line,lwpolyline") (8 . "S-COLS,A-WALL-SHEL-EXST"))))
  24.     ;; What is going on here?
  25.     (progn (setq peditaccept (getvar 'peditaccept))
  26.            (setvar 'peditaccept 1)
  27.            (setvar 'peditaccept peditaccept)
  28.     )
  29.   )
  30.   (setq plinecnt 0)
  31.   (if (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "S-COLS,A-WALL-SHEL-EXST"))))
  32.     (repeat (sslength ss)
  33.       (vla-getboundingbox (vlax-ename->vla-object (ssname ss plinecnt)) 'mn 'mx)
  34.       (setq mn (vlax-safearray->list mn))
  35.       (setq mx (vlax-safearray->list mx))
  36.       (setq pntnx (car mn))
  37.       (setq pntny (cadr mn))
  38.       (setq pntxx (car mx))
  39.       (setq pntxy (cadr mx))
  40.       (setq dvx (- pntxx pntnx))        ;added
  41.       (setq dvy (- pntxy pntny))        ;added
  42.                                         ; (InsText (strcat "Size" " = "(rtos (- pntxX pntnX) 4 16) " x " (rtos (- pntxY pntnY) 4 16)) (list pntxX pntnY 0.0));original code
  43.       (instext (strcat "Size" " = " (rtos dvx 4 16) " x " (rtos dvy 4 16) " - " (scheck dvx dvy))
  44.                (list pntxx pntny 0.0)
  45.       )                                 ;modified
  46.       (setq plinecnt (1+ plinecnt))
  47.     )
  48.   )
  49.   (princ)
  50. )                                       ;end defun
  51.  
Title: Re: Trouble - Need Assistance
Post by: V-Man on February 11, 2015, 09:43:43 AM
Quote
Use cond function. Or you can use associated lists - I think it will be more functionality.
Should i write code sample?

A code sample would be great if possible.
Title: Re: Trouble - Need Assistance
Post by: kpblc on February 11, 2015, 10:01:33 AM
By cond function:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:css (/ adoc *error* fun_colname)
  3.  
  4.   (defun fun_colname (minp maxp / _l _h prec)
  5.     (setq _l   (apply (function -) (mapcar (function car) (list minp maxp)))
  6.           _h   (apply (function -) (mapcar (function cadr) (list minp maxp)))
  7.           prec 1e-6
  8.           ) ;_ end of setq
  9.     (strcat "Size = "
  10.             (rtos _l 4)
  11.             " x "
  12.             (rtos _h 4)
  13.             " - "
  14.             (cond
  15.               ((and (equal _l 4. prec) (equal _h 4.125 prec)) "W4x13")
  16.               ((and (equal _l 5. prec) (equal _h 5. prec)) "W5x16")
  17.               ((and (equal _l 5. prec) (equal _h 5.125 prec)) "W5x18.5")
  18.               ((and (equal _l 4. prec) (equal _h 5.875 prec)) "W5x19")
  19.               (t "* NOT DEFINED *")
  20.               ) ;_ end of cond
  21.             ) ;_ end of strcat
  22.     ) ;_ end of defun
  23.  
  24.   (defun *error* (msg)
  25.     (vla-endundomark adoc)
  26.     (princ msg)
  27.     (princ)
  28.     ) ;_ end of defun
  29.  
  30.   (foreach ent (mapcar (function vlax-ename->vla-object)
  31.                        ((lambda (/ selset item tab)
  32.                           (setq selset (ssget "_X" '((0 . "LWPOLYLINE") (8 . "S-COLS,A-WALL-SHEL-EXST"))))
  33.                           (repeat (setq tab  nil
  34.                                         item (sslength selset)
  35.                                         ) ;_ end setq
  36.                             (setq tab (cons (ssname selset (setq item (1- item))) tab))
  37.                             ) ;_ end of repeat
  38.                           ) ;_ end of lambda
  39.                         )
  40.                        ) ;_ end of mapcar
  41.     (entmakex (list '(0 . "TEXT")
  42.                     '(8 . "Defpoints")
  43.                     (cons 10 (list (car minp) (cadr minp) 0.))
  44.                     (cons 1 (fun_colname minp maxp)
  45.                     '(40 . 5)
  46.                     '(41 . 0.8)
  47.                     '(210 0. 0. 1.)
  48.                     ) ;_ end of list
  49.               ) ;_ end of entmakex
  50.     ) ;_ end of foreach
  51.   (vla-endundomark adoc)
  52.   (princ)
  53.   ) ;_ end of defun
Using associate list (as a sample. i can't test code):
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:css (/ adoc *error* fun_colname)
  3.  
  4.   (defun fun_colname (minp maxp / _l _h prec)
  5.     (setq _l   (apply (function -) (mapcar (function car) (list minp maxp)))
  6.           _h   (apply (function -) (mapcar (function cadr) (list minp maxp)))
  7.           prec 1e-6
  8.           ) ;_ end of setq
  9.     (strcat "Size = "
  10.             (rtos _l 4)
  11.             " x "
  12.             (rtos _h 4)
  13.             " - "
  14.             (cond
  15.               ((cdr (assoc (strcat (atoi (fix (* 1000 _l))) "x" (atoi (fix (* 1000 _h))))
  16.                            '(("4000x4120" . "W4x13")
  17.                              ("5000x5000" . "W5x16")
  18.                              ("5000x5125" . "W5x18.5")
  19.                              ("4000x5875" . "W5x19")
  20.                              )
  21.                            ) ;_ end of assoc
  22.                     ) ;_ end of cdr
  23.                )
  24.               (t "* NOT DEFINED *")
  25.               ) ;_ end of cond
  26.             ) ;_ end of strcat
  27.     ) ;_ end of defun
  28.  
  29.   (defun *error* (msg)
  30.     (vla-endundomark adoc)
  31.     (princ msg)
  32.     (princ)
  33.     ) ;_ end of defun
  34.  
  35.   (foreach ent (mapcar (function vlax-ename->vla-object)
  36.                        ((lambda (/ selset item tab)
  37.                           (setq selset (ssget "_X" '((0 . "LWPOLYLINE") (8 . "S-COLS,A-WALL-SHEL-EXST"))))
  38.                           (repeat (setq tab  nil
  39.                                         item (sslength selset)
  40.                                         ) ;_ end setq
  41.                             (setq tab (cons (ssname selset (setq item (1- item))) tab))
  42.                             ) ;_ end of repeat
  43.                           ) ;_ end of lambda
  44.                         )
  45.                        ) ;_ end of mapcar
  46.     (entmakex (list '(0 . "TEXT")
  47.                     '(8 . "Defpoints")
  48.                     (cons 10 (list (car minp) (cadr minp) 0.))
  49.                     (cons 1 (fun_colname minp maxp)
  50.                     '(40 . 5)
  51.                     '(41 . 0.8)
  52.                     '(210 0. 0. 1.)
  53.                     ) ;_ end of list
  54.               ) ;_ end of entmakex
  55.     ) ;_ end of foreach
  56.   (vla-endundomark adoc)
  57.   (princ)
  58.   ) ;_ end of defun
  59.  
Title: Re: Trouble - Need Assistance
Post by: ronjonp on February 11, 2015, 10:13:34 AM
Quote
Use cond function. Or you can use associated lists - I think it will be more functionality.
Should i write code sample?

A code sample would be great if possible.
Like THIS (http://www.theswamp.org/index.php?topic=48847.msg539666#msg539666) ? :)
Title: Re: Trouble - Need Assistance
Post by: V-Man on February 11, 2015, 12:00:13 PM
Thanks ronjonp. Your code works great and that's what I am using. I just wanted to see what code sample kpblc would come up with. I will studdy both approach's. Thanks again guys for the assistance.
Title: Re: Trouble - Need Assistance
Post by: CAB on February 11, 2015, 02:32:24 PM
FYI, Some what related topic:
http://www.theswamp.org/index.php?topic=47517.0