Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Define a global variable for the last entered bar diameter
- (setq lastBarDiameter nil)
- ;; Diameter and offset values
- (setq diameters '((3 . 0.375) (4 . 0.5) (5 . 0.625) (6 . 0.75)
- (7 . 0.875) (8 . 1.0) (9 . 1.270) (10 . 1.310)))
- ;; Function to create or select a layer based on diameter
- (defun ensureLayer (dia)
- (setq layerName (strcat "B" (rtos dia 2 0)))
- (setq layerColor (cond
- ((= dia 3) 10)
- ((= dia 4) 14)
- ((= dia 5) 30)
- ((= dia 6) 40)
- ((= dia 7) 50)
- ((= dia 8) 70)
- ((= dia 9) 99)
- ((= dia 10) 110)))
- (if (not (tblsearch "layer" layerName))
- (command "_.layer" "M" layerName "C" (itoa layerColor) "" "L" "CONTINUOUS" "" "p" "n" "" ""))
- (setvar "clayer" layerName)
- )
- ;; Function to prompt for bar diameter
- (defun getBarDiameter ()
- (setq dia (getreal (strcat "\nEnter bar diameter (last entered#: "
- (if lastBarDiameter (rtos lastBarDiameter 2 0) "None") "): ")))
- (if (not dia)
- (setq dia lastBarDiameter)) ; Use the last entered diameter if none entered
- (if (and dia (>= dia 3) (<= dia 10))
- (progn (setq lastBarDiameter dia) dia) ; Return valid diameter
- (progn (princ "\nInvalid diameter. Please enter a value between 3 and 10.") nil))
- )
- ;; DG: Draw circle with bar diameter, placing the circle's bottom exactly at the user-specified point
- (defun c:DG ()
- (if (setq dia (getBarDiameter)) ; Get bar diameter
- (progn
- (setq radius (/ (cdr (assoc dia diameters)) 2)) ; Calculate the radius
- (ensureLayer dia) ; Ensure the correct layer is set
- ;; Allow the user to specify multiple points for placing circles
- (while (setq basePt (getpoint "\nSpecify bottom point for the circle (or press Enter to finish):"))
- ;; Adjust the center point to be above the base point by the radius
- (setq centerPt (list (car basePt) (+ (cadr basePt) radius) (caddr basePt)))
- ;; Draw the circle with the calculated center point and radius
- (command "circle" centerPt radius)
- )
- (princ (strcat "\nCircles created on layer: " layerName))
- )
- )
- (setvar "clayer" "0-35") ; Reset to default layer
- (princ)
- )
- ;; DH: Offset objects with bar diameter
- (defun c:DH ()
- (if (setq dia (getBarDiameter))
- (progn
- (setq offsetValue (cdr (assoc dia diameters)))
- (if (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))))
- (progn
- (ensureLayer dia) ; Ensure the correct layer is set
- (while (setq p (getpoint (strcat "\nSpecify point for offset (Nominal Bar Dia: "
- (rtos offsetValue 2 3) "): ")))
- (command "_.offset" offsetValue ss "_non" p "")
- (setq e (entlast))
- (command "_.chprop" e "" "_layer" layerName "") ; Assign layer to new object
- (setq ss (ssadd e ss)) ; Add the new offset object to selection set
- )
- )
- (princ "\nNo valid objects selected for offset.")
- )
- )
- )
- (setvar "clayer" "0-35") ; Reset to default layer
- (princ)
- )
Advertisement
Add Comment
Please, Sign In to add comment