Harimaddy

Bar offset

Sep 13th, 2024
2,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; Define a global variable for the last entered bar diameter
  2. (setq lastBarDiameter nil)
  3.  
  4. ;; Diameter and offset values
  5. (setq diameters '((3 . 0.375) (4 . 0.5) (5 . 0.625) (6 . 0.75)
  6.                   (7 . 0.875) (8 . 1.0) (9 . 1.270) (10 . 1.310)))
  7.  
  8. ;; Function to create or select a layer based on diameter
  9. (defun ensureLayer (dia)
  10.   (setq layerName (strcat "B" (rtos dia 2 0)))
  11.   (setq layerColor (cond
  12.                      ((= dia 3) 10)
  13.                      ((= dia 4) 14)
  14.                      ((= dia 5) 30)
  15.                      ((= dia 6) 40)
  16.                      ((= dia 7) 50)
  17.                      ((= dia 8) 70)
  18.                      ((= dia 9) 99)
  19.                      ((= dia 10) 110)))
  20.   (if (not (tblsearch "layer" layerName))
  21.     (command "_.layer" "M" layerName "C" (itoa layerColor) "" "L" "CONTINUOUS" "" "p" "n" "" ""))
  22.   (setvar "clayer" layerName)
  23. )
  24.  
  25. ;; Function to prompt for bar diameter
  26. (defun getBarDiameter ()
  27.   (setq dia (getreal (strcat "\nEnter bar diameter (last entered#: "
  28.                              (if lastBarDiameter (rtos lastBarDiameter 2 0) "None") "): ")))
  29.   (if (not dia)
  30.     (setq dia lastBarDiameter)) ; Use the last entered diameter if none entered
  31.   (if (and dia (>= dia 3) (<= dia 10))
  32.     (progn (setq lastBarDiameter dia) dia) ; Return valid diameter
  33.     (progn (princ "\nInvalid diameter. Please enter a value between 3 and 10.") nil))
  34. )
  35.  
  36. ;; DG: Draw circle with bar diameter, placing the circle's bottom exactly at the user-specified point
  37. (defun c:DG ()
  38.   (if (setq dia (getBarDiameter))  ; Get bar diameter
  39.     (progn
  40.       (setq radius (/ (cdr (assoc dia diameters)) 2))  ; Calculate the radius
  41.       (ensureLayer dia)  ; Ensure the correct layer is set
  42.  
  43.       ;; Allow the user to specify multiple points for placing circles
  44.       (while (setq basePt (getpoint "\nSpecify bottom point for the circle (or press Enter to finish):"))
  45.         ;; Adjust the center point to be above the base point by the radius
  46.         (setq centerPt (list (car basePt) (+ (cadr basePt) radius) (caddr basePt)))
  47.  
  48.         ;; Draw the circle with the calculated center point and radius
  49.         (command "circle" centerPt radius)
  50.       )
  51.      
  52.       (princ (strcat "\nCircles created on layer: " layerName))
  53.     )
  54.   )
  55.   (setvar "clayer" "0-35")  ; Reset to default layer
  56.   (princ)
  57. )
  58.  
  59.  
  60. ;; DH: Offset objects with bar diameter
  61. (defun c:DH ()
  62.   (if (setq dia (getBarDiameter))
  63.     (progn
  64.       (setq offsetValue (cdr (assoc dia diameters)))
  65.       (if (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
  66.         (progn
  67.           (ensureLayer dia)  ; Ensure the correct layer is set
  68.           (while (setq p (getpoint (strcat "\nSpecify point for offset (Nominal Bar Dia: "
  69.                                            (rtos offsetValue 2 3) "): ")))
  70.             (command "_.offset" offsetValue ss "_non" p "")
  71.             (setq e (entlast))
  72.             (command "_.chprop" e "" "_layer" layerName "")  ; Assign layer to new object
  73.             (setq ss (ssadd e ss))  ; Add the new offset object to selection set
  74.           )
  75.         )
  76.         (princ "\nNo valid objects selected for offset.")
  77.       )
  78.     )
  79.   )
  80.   (setvar "clayer" "0-35")  ; Reset to default layer
  81.   (princ)
  82. )
Advertisement
Add Comment
Please, Sign In to add comment