Jump to content

Create circle and place it bottom


harimaddddy

Recommended Posts

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 by SLW210
Added Code Tags!!
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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...

image.png.dc77a29b20afe251e6701e96351c14d2.pngMulti radio buttons.lsp

 

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

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)
)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...