harimaddddy Posted September 7 Posted September 7 (edited) Hi brothers/Sisters, I create this code to create nominal diameter of a reinforcement, but while place the created circle it only center, I want it to place with bottom of the circle. Thanks in advance ;; Define a global variable for the last entered bar diameter (setq lastBarDiameter nil) (defun c:DG () ;; Initialize lastBarDiameter if it is nil (if (= nil lastBarDiameter) (setq lastBarDiameter 0.0)) ; Default value if no previous diameter is stored ;; Prompt for diameter input and allow pressing Enter to use last value (setq dia (getreal (strcat "\nEnter bar diameter (last entered: " (rtos lastBarDiameter 2 0) "): "))) ;; Check if the user pressed Enter (dia will be nil) (if (= dia nil) (setq dia lastBarDiameter) ; Use the last entered diameter if Enter is pressed ) ;; Validate and set the corresponding value (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))) ; List of diameters and values (setq n 0) ; Initialize n ;; Check for valid diameter and print corresponding message (foreach d diameters (if (= dia (car d)) (progn (setq n (cdr d)) (princ (strcat "\nYou entered a diameter of " (rtos (car d) 2 0) ", which corresponds to a value of " (rtos n 2 3) "."))))) ;; Only proceed if a valid diameter was entered (if (> n 0) (progn (setq pt (getpoint "\nSpecify the center point for the circle:")) ; Prompt for center point (setq radius (/ n 2)) ; Calculate the radius ;; Set the layer based on the bar diameter (cond ((= dia 3) (if (not (tblsearch "layer" "B3")) (command "LAYER" "M" "B3" "C" "10" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 4) (if (not (tblsearch "layer" "B4")) (command "LAYER" "M" "B4" "C" "14" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 5) (if (not (tblsearch "layer" "B5")) (command "LAYER" "M" "B5" "C" "30" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 6) (if (not (tblsearch "layer" "B6")) (command "LAYER" "M" "B6" "C" "40" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 7) (if (not (tblsearch "layer" "B7")) (command "LAYER" "M" "B7" "C" "50" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 8) (if (not (tblsearch "layer" "B8")) (command "LAYER" "M" "B8" "C" "70" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 9) (if (not (tblsearch "layer" "B9")) (command "LAYER" "M" "B9" "C" "99" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 10) (if (not (tblsearch "layer" "B10")) (command "LAYER" "M" "B10" "C" "110" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ) ;; Draw the circle at the specified center point (command "circle" pt radius) ;; Store the last entered bar diameter (setq lastBarDiameter dia) ; Store the last diameter value ;; Print the stored value (princ (strcat "\nLast entered bar diameter: " (rtos lastBarDiameter 2 0))) ; Use rtos for real display ) (princ "\nInvalid diameter. Please enter a value between 3 and 10.") ) ;; Set the current layer to 0-35 (or any default layer you want) (setvar "clayer" "0-35") ;; Clean exit (princ) ) Edited September 7 by SLW210 Added Code Tags!! Quote
SLW210 Posted September 7 Posted September 7 I moved your thread to the AutoLISP, Visual LISP & DCL Forum, please post in the most appropriate forum. Please use code tags for your code. (the <> in the editor tool bar) Quote
BIGAL Posted September 7 Posted September 7 (edited) This is my attempt at your task. Remembers last dia used. Adds circle matching bottom Quadrant point. (defun c:DG ( / diameters ans radius pt ) (setq diameters (list "Choose diameter" "3/8" "1/2" "5/8" "3/4" "7/8" "1" "1 1/4" "1 3/8" )) ; List of diameters (if (not AH:Butts)(load "Multi radio buttons.lsp")) ; loads the program if not loaded already (if (= lastBarDiameter nil)(setq lastBarDiameter 1)) ; this is needed to set default button (setq ans (ah:butts lastBarDiameter "V" diameters)) (setq lastBarDiameter but) ;; Store the last entered bar diameter ;; Set the layer based on the bar diameter (cond ((= but 1) (setq radius 0.375)(if (not (tblsearch "layer" "B3")) (command "LAYER" "M" "B3" "C" "10" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 2) (setq radius 0.5)(if (not (tblsearch "layer" "B4")) (command "LAYER" "M" "B4" "C" "14" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 3) (setq radius 0.625)(if (not (tblsearch "layer" "B5")) (command "LAYER" "M" "B5" "C" "30" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 4) (setq radius 0.75)(if (not (tblsearch "layer" "B6")) (command "LAYER" "M" "B6" "C" "40" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 5) (setq radius 0.875)(if (not (tblsearch "layer" "B7")) (command "LAYER" "M" "B7" "C" "50" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 6) (setq radius 1.0)(if (not (tblsearch "layer" "B8")) (command "LAYER" "M" "B8" "C" "70" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 7) (setq radius 1.25)(if (not (tblsearch "layer" "B9")) (command "LAYER" "M" "B9" "C" "99" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= but 8) (setq radius 1.375)(if (not (tblsearch "layer" "B10")) (command "LAYER" "M" "B10" "C" "110" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ) (setq radius (/ radius 2.0)) ;; Draw the circle at the specified point (setq pt (getpoint "\nSpecify the bottom point for the circle:")) ; Prompt for bottom point (setq pt (mapcar '+ pt (list 0.0 radius 0.0))) (command "circle" "_non" pt radius) ;; Set the current layer to 0-35 (or any default layer you want) ;(setvar "clayer" "0-35") ;; Clean exit (princ) ) Make sure you save Multi radio buttons in a support path or add the full path to the (load "Multi... Multi radio buttons.lsp Edited September 7 by BIGAL 1 Quote
Saxlle Posted September 8 Posted September 8 Hi, I did a little update in your code and put a comments ("THIS LINE HAS BEEN ADDED", .......). I hope is that what you want. ;; Define a global variable for the last entered bar diameter (setq lastBarDiameter nil) (defun c:DG () ;; "THIS LINE HAS BEEN ADDED", you need to localized a variables (setq osm (getvar "osmode")) ;; "THIS LINE HAS BEEN ADDED", get the values of "object snap" (setvar "osmode" 0) ;; "THIS LINE HAS BEEN ADDED", set the value to be 0 or turned off (setq old_layer (getvar "clayer")) ;; "THIS LINE HAS BEEN ADDED", get a previous name of layer ;; Initialize lastBarDiameter if it is nil (if (= nil lastBarDiameter) (setq lastBarDiameter 0.0)) ; Default value if no previous diameter is stored ;; Prompt for diameter input and allow pressing Enter to use last value (setq dia (getreal (strcat "\nEnter bar diameter (last entered: " (rtos lastBarDiameter 2 0) "): "))) ;; Check if the user pressed Enter (dia will be nil) (if (= dia nil) (setq dia lastBarDiameter) ; Use the last entered diameter if Enter is pressed ) ;; Validate and set the corresponding value (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))) ; List of diameters and values (setq n 0) ; Initialize n ;; Check for valid diameter and print corresponding message (foreach d diameters (if (= dia (car d)) (progn (setq n (cdr d)) (princ (strcat "\nYou entered a diameter of " (rtos (car d) 2 0) ", which corresponds to a value of " (rtos n 2 3) "."))))) ;; Only proceed if a valid diameter was entered (if (> n 0) (progn (setq pt (getpoint "\nSpecify the center point for the circle:")) ; Prompt for center point (setq radius (/ n 2)) ; Calculate the radius ;; Set the layer based on the bar diameter (cond ((= dia 3) (if (not (tblsearch "layer" "B3")) (command "LAYER" "M" "B3" "C" "10" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 4) (if (not (tblsearch "layer" "B4")) (command "LAYER" "M" "B4" "C" "14" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 5) (if (not (tblsearch "layer" "B5")) (command "LAYER" "M" "B5" "C" "30" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 6) (if (not (tblsearch "layer" "B6")) (command "LAYER" "M" "B6" "C" "40" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 7) (if (not (tblsearch "layer" "B7")) (command "LAYER" "M" "B7" "C" "50" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 8) (if (not (tblsearch "layer" "B8")) (command "LAYER" "M" "B8" "C" "70" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 9) (if (not (tblsearch "layer" "B9")) (command "LAYER" "M" "B9" "C" "99" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 10) (if (not (tblsearch "layer" "B10")) (command "LAYER" "M" "B10" "C" "110" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ) ;; Draw the circle at the specified center point (command "circle" pt radius) (setq ang_270 4.71) ;; "THIS LINE HAS BEEN ADDED", define a default angle of 270 degrees, whic are in radians 4.71 (setq npt (polar pt ang_270 radius)) ;; "THIS LINE HAS BEEN ADDED", get a new point (npt) from the center point of the circle to the bottom of the circle (command "._move" (entlast) "" npt pt) ;; "THIS LINE HAS BEEN ADDED", displacement a circle from a bottom to the center of the circle (setvar "osmode" osm) ;; "THIS LINE HAS BEEN ADDED", restore the "object snap" ;; Store the last entered bar diameter (setq lastBarDiameter dia) ; Store the last diameter value ;; Print the stored value (princ (strcat "\nLast entered bar diameter: " (rtos lastBarDiameter 2 0))) ; Use rtos for real display ) (princ "\nInvalid diameter. Please enter a value between 3 and 10.") ) ;; Set the current layer to 0-35 (or any default layer you want) ;; (setvar "clayer" "0-35") (setvar "clayer" old_layer) ;; "THIS LINE HAS BEEN ADDED", restore the old layer after creating a circle ;; Clean exit (princ) ) Quote
harimaddddy Posted September 8 Author Posted September 8 6 hours ago, Saxlle said: Hi, I did a little update in your code and put a comments ("THIS LINE HAS BEEN ADDED", .......). I hope is that what you want. ;; Define a global variable for the last entered bar diameter (setq lastBarDiameter nil) (defun c:DG () ;; "THIS LINE HAS BEEN ADDED", you need to localized a variables (setq osm (getvar "osmode")) ;; "THIS LINE HAS BEEN ADDED", get the values of "object snap" (setvar "osmode" 0) ;; "THIS LINE HAS BEEN ADDED", set the value to be 0 or turned off (setq old_layer (getvar "clayer")) ;; "THIS LINE HAS BEEN ADDED", get a previous name of layer ;; Initialize lastBarDiameter if it is nil (if (= nil lastBarDiameter) (setq lastBarDiameter 0.0)) ; Default value if no previous diameter is stored ;; Prompt for diameter input and allow pressing Enter to use last value (setq dia (getreal (strcat "\nEnter bar diameter (last entered: " (rtos lastBarDiameter 2 0) "): "))) ;; Check if the user pressed Enter (dia will be nil) (if (= dia nil) (setq dia lastBarDiameter) ; Use the last entered diameter if Enter is pressed ) ;; Validate and set the corresponding value (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))) ; List of diameters and values (setq n 0) ; Initialize n ;; Check for valid diameter and print corresponding message (foreach d diameters (if (= dia (car d)) (progn (setq n (cdr d)) (princ (strcat "\nYou entered a diameter of " (rtos (car d) 2 0) ", which corresponds to a value of " (rtos n 2 3) "."))))) ;; Only proceed if a valid diameter was entered (if (> n 0) (progn (setq pt (getpoint "\nSpecify the center point for the circle:")) ; Prompt for center point (setq radius (/ n 2)) ; Calculate the radius ;; Set the layer based on the bar diameter (cond ((= dia 3) (if (not (tblsearch "layer" "B3")) (command "LAYER" "M" "B3" "C" "10" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 4) (if (not (tblsearch "layer" "B4")) (command "LAYER" "M" "B4" "C" "14" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 5) (if (not (tblsearch "layer" "B5")) (command "LAYER" "M" "B5" "C" "30" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 6) (if (not (tblsearch "layer" "B6")) (command "LAYER" "M" "B6" "C" "40" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 7) (if (not (tblsearch "layer" "B7")) (command "LAYER" "M" "B7" "C" "50" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 8) (if (not (tblsearch "layer" "B8")) (command "LAYER" "M" "B8" "C" "70" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 9) (if (not (tblsearch "layer" "B9")) (command "LAYER" "M" "B9" "C" "99" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ((= dia 10) (if (not (tblsearch "layer" "B10")) (command "LAYER" "M" "B10" "C" "110" "" "L" "CONTINUOUS" "" "p" "n" "" ""))) ) ;; Draw the circle at the specified center point (command "circle" pt radius) (setq ang_270 4.71) ;; "THIS LINE HAS BEEN ADDED", define a default angle of 270 degrees, whic are in radians 4.71 (setq npt (polar pt ang_270 radius)) ;; "THIS LINE HAS BEEN ADDED", get a new point (npt) from the center point of the circle to the bottom of the circle (command "._move" (entlast) "" npt pt) ;; "THIS LINE HAS BEEN ADDED", displacement a circle from a bottom to the center of the circle (setvar "osmode" osm) ;; "THIS LINE HAS BEEN ADDED", restore the "object snap" ;; Store the last entered bar diameter (setq lastBarDiameter dia) ; Store the last diameter value ;; Print the stored value (princ (strcat "\nLast entered bar diameter: " (rtos lastBarDiameter 2 0))) ; Use rtos for real display ) (princ "\nInvalid diameter. Please enter a value between 3 and 10.") ) ;; Set the current layer to 0-35 (or any default layer you want) ;; (setvar "clayer" "0-35") (setvar "clayer" old_layer) ;; "THIS LINE HAS BEEN ADDED", restore the old layer after creating a circle ;; Clean exit (princ) ) This code works exactly what i needed sir, thanks... if i use this command a little zoom out then circle would place with center, but it can manageable when i zoom in near to the objects Quote
Saxlle Posted September 8 Posted September 8 Your welcome If i understand correctly, you have a problem with "object snap", doesn't apear a "quadrant" when you specifying center point of circle to be on "LINE, POLYLINE, ..." entitie. So, you need just to change a position of this line of code: (setvar "osmode" 0), to be somewhere after this line of code: (setq pt (getpoint "\nSpecify the center point for the circle:")) and before this line of code: (command "circle" pt radius) inside of "if" statement. Quote
BIGAL Posted September 9 Posted September 9 @harimaddddy did you try my code ? Does what you want. Yes must download Multi getvals.lsp as well. Quote
harimaddddy Posted September 14 Author Posted September 14 @BIGAL Yeah i tried it, the menu bar idea is working fine, but for work follow i prefer use to keyboard only, thanks a lot i learnt a new thing. Quote
harimaddddy Posted October 6 Author Posted October 6 ;; 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 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) ) Thanks everyone currently I made some modifications and works well Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.