Author Topic: Testing some code  (Read 1544 times)

0 Members and 1 Guest are viewing this topic.

BKT

  • Newt
  • Posts: 27
Testing some code
« on: November 11, 2015, 12:54:07 AM »
Hello,

Say, I'm just checking to see if I can throw some code out here and have somebody with a newer version of AutoCAD give it a try.  I'm using BricsCAD (and an older version of intelliCAD), but I'd like to see if it works OK in ACAD.  Is this the proper forum, or is there another place I should use?

Thanks,
BKT

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: Testing some code
« Reply #1 on: November 11, 2015, 07:39:06 AM »
Sure bring it on!  At home today's a holiday in the US, but we usually would rather help someone with code than have to create it for them.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

BKT

  • Newt
  • Posts: 27
Re: Testing some code
« Reply #2 on: November 11, 2015, 09:32:51 AM »
Thanks, Tom!

Just wondering - I have the LISP and a DCL file.  Would it be better to attach these or use the "insert code" and put them both inline?
I could do both, I suppose...

Byron

ChrisCarlson

  • Guest
Re: Testing some code
« Reply #3 on: November 11, 2015, 10:03:53 AM »
Correct,

Use
[.code=cadlisp-7][/.code]

remove the .'s

BKT

  • Newt
  • Posts: 27
Re: Testing some code
« Reply #4 on: November 11, 2015, 11:02:33 AM »
I was going to add an image but can't seem to get it done.  Can you just paste or do you need to attach it?

Anyway, here's what it is.  This code is for flat pattern creation of simple one direction bends.  I draw the cross-section and dimension the segments of the cross-section between the bends and dimension the included angles.  That way I can work with the bend allowances.

Might seem kind of hokey but it works in BricsCAD and an older versions of intelliCAD...

Load the LISP and DCL and do these steps:

1. Select Gauge (11 through 22)
2. Select bend radius (0.125 or 0.156 - for Bantam 412 in small shop)
3. Enter number of bends
4. Enter width of the flat pattern
5. Select the dimensions starting from one end, entity, angle, entity, angle, etc.
6. Select a point to locate the flat pattern from its lower left corner

The flat pattern should have the bend lines shown as phantom lines.  The bottom will be the end you started your dimension selection from.

If somebody could check to see if this works OK in a newer version of AutoCAD I'd appreciate it.

(The code should work even if you just draw some lines as long as there are linear and angular dims.  Just won't be accurate...)

Thanks,
Byron


Code: [Select]
;; UBND.LSP - Program for creating a flat pattern from a simple 2D
;; cross section of a sheet metal profile in one direction only.
;; The cross section is dimensioned using linear dimensions created
;; by selecting the straight sections (single entities) between bends
;; and the angles between these straight sections.
;;
;; The bend radii were hard-coded for a Bantam 412 brake (0.156)
;; and a Harbor Freight 36" brake (0.125)
;;
;; (Started as FLAT.LSP  12/5/2102 - BKT)
;;
;; Added NON-90 included angle capability. - 11/25/2013
;; Added (assoc 70) = (32, 33, 160, 161, 162) to fix an
;; edited dimension problem. - 12/1/2013
;; Added association for Aligned Dimension (33) - 12/6/2014
;; Added code for null selections (errno 7) - 12/6/2014
;; Added code to set K-factor (kfac) using formula "(bendr/Thk)/16 + 0.25" - 9/5/2015
;;


(defun c:ubnd (/ a42 a70 b1 b2 bendr c clayold dcl_id ddiag ent1 ent2 Gau
                 ip kfac len1 len2 myItem myList olderr osm sStr1 w1 w2)

;; Error handler
  (setq olderr *error*)
  (defun *error* (msg)
    (if osm (setvar 'osmode osm))
    (if (or
          (= msg "Function cancelled")
          (= msg "quit / exit abort")
        )
      ;; Canceled or program aborted - exit quietly
      (princ)
      ;;otherwise report error message
      (princ (strcat "\nError: " msg))
    )
   (prompt "\n Program Terminated. No object selected.")
   (princ)
)

(setq osm (getvar "osmode"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)

(defun saveVars()

  ;; Get the selected item from list
  (setq sStr1(get_tile "myList"))

  ;; Make sure of selection
  (if(= sStr1 "")
    (setq myItem "Nothing")
    (setq myItem (nth (atoi sStr1) myList))
  )
)

  (setq myList (list "CRS 11 - 0.1196" "CRS 14 - 0.0747" "CRS 16 - 0.0598"
                "CRS 18 - 0.0478" "CRS 20 - 0.0359" "CRS 22 - 0.0299"))

  ;; Load dcl file
  (if (not (setq dcl_id (load_dialog "ubnd.dcl")))
    (progn
      (alert "The DCL file could not be loaded!")
      (exit)
    )

    ;; Else, the DCL file loaded
    (progn

      ;; Load the dialog definition inside the DCL file
      (if (not (new_dialog "ubnd" dcl_id))
        (progn
        (alert "The UBND definition file could not be loaded!")
          (exit)
        )

        (progn

          (start_list "myList" 3)
          (mapcar 'add_list myList)
          (end_list)

          (action_tile "rad1" "(setq bendr 0.125)")  ;;  Was 0.062 for HF brake
          (action_tile "rad2" "(setq bendr 0.156)")  ;;  Set for Bantam 412 brake
          (action_tile "b1" "(setq b1 $value)")
          (action_tile "w1" "(setq w1 $value)")

          ;; If an action event occurs
          (action_tile "accept" "(saveVars)(done_dialog 2)")
          (action_tile "cancel" "(done_dialog 1)")

          ;; Display the dialog box
          (setq ddiag (start_dialog))

          ;; Unload the dialog box
          (unload_dialog dcl_id)

          ;; Cancel button
          (if(= ddiag 1)
            (princ "\n UBND program canceled")
          )

          ;; OK button
          (if(= ddiag 2)
            (progn

                   (cond
                     ((= myItem "CRS 11 - 0.1196") (setq Gau 0.1196))
                     ((= myItem "CRS 14 - 0.0747") (setq Gau 0.0747))
                     ((= myItem "CRS 16 - 0.0598") (setq Gau 0.0598))
                     ((= myItem "CRS 18 - 0.0478") (setq Gau 0.0478))
                     ((= myItem "CRS 20 - 0.0359") (setq Gau 0.0359))
                     ((= myItem "CRS 22 - 0.0299") (setq Gau 0.0299))
                     (t nil)
                   ); end cond

                 (if (<= (atoi b1) 1)(setq b2 (+ (atoi b1) 2))(setq b2 (+ (* (atoi b1) 2) 1)))
                 (setq w2 (distof w1 2))

              (setq kfac (+ (/ bendr Gau 16) 0.25))
              (if (> kfac 0.5) (setq kfac 0.5))

              (alert "Pick Linear Dimensions and Included Angles From One End Of Part  \n   \n                         <<-- PICK IN ORDER -->>")

              (setq clayold (getvar "CLAYER"))

              (command "._LAYER" "N" "Xsec_dims" "")

                 (repeat b2
                   (while
                     (and
                       (not (setq ent1 (entsel "\nSelect Dimension: ")))
                       (= (getvar "errno") 7)
                     )
                     (princ "\n Nothing Selected -- Try Again...")
                   )
                 (setq a42 (cdr (assoc 42 (entget (car ent1))))
                       a70 (cdr (assoc 70 (entget (car ent1)))))
                 (if (or (= a70 34)(= a70 162)) (setq ent2 (* (- PI a42)(+ bendr (* kfac Gau)))))
                 (if (or (= a70 32)(= a70 160)(= a70 33)(= a70 161)) (setq ent2 a42))
                 (setq len1 (append len1 (list ent2)))
                 (command "._CHPROP" ent1 "" "LA" "Xsec_dims" "C" "RED" "")
                 )

              (setq n4 len1)

              (setq seglen (apply '+ len1))

              (command "._layer" "M" "FLATPAT" "C" "YELLOW" "" "")

              (setvar "osmode" osm)
              (setq ip (getpoint "\nInsert Flat Pattern <LOWER LEFT CORNER> : "))
              (setvar "osmode" 0)

              (command "rectangle" ip (strcat "@" w1 "," (rtos seglen)))

              (command "._line" ip (strcat "@" w1 "<0") "")

              (command "._chprop" (entlast) "" "LT" "PHANTOM2" "")

              (command "._copy" "L" "" ip (strcat "@" (rtos (+ (car len1) (/ (cadr len1) 2))) "<90"))

              (setq len1 (cdr len1))
              (setq len2 (/ (length len1) 2))

              (setq c 1)

              (while (< c len2)
                (command "._copy" "L" "" ip (strcat "@" (rtos (+ (/ (car len1) 2)(cadr len1)(/ (caddr len1) 2))) "<90"))
                (setq len1 (cdr (cdr len1)))
                (setq c (1+ c))
              )

              (command "._LAYER" "M" "FP_dims" "")
              (setq ss1 (ssget "_X" '((8 . "Xsec_dims"))))
              (command "._CHPROP" ss1 "" "LA" "Xsec_dims" "C" "ByLayer" "")

            )
          )
        )
      )
    )
  )

(setvar "osmode" osm)

(princ)

)

And DCL:

Code: [Select]
ubnd : dialog {

      label = "UNBEND Flat Sheet Pattern";
      : column {
        : boxed_row {
          : popup_list {
            key = "myList";
            label = "Select Gauge";
            width = 32;
          }
        }
      }


        : boxed_radio_row {
        label = "Bend Radius";
          : radio_row {
            : radio_button {
              key = "rad1";
              label = "0.125";
            }

            : radio_button {
              key = "rad2";
              label = "0.156";
            }
          }
        }

          : boxed_row {
            : edit_box {
              key = "b1";
              label = "Number of Bends:";
              edit_width = 2;
              value = "";
            }
          }


          : boxed_row {
            : edit_box {
              key = "w1";
              label = "Enter Part Width:";
              edit_width = 5;
              value = "";
            }
          }


            : boxed_row {
              : button {
                key = "accept";
                label = " OK ";
                is_default = true;
              }
              : button {
                key = "cancel";
                label = " Cancel ";
                is_default = false;
                is_cancel = true;
              }
            }

}