AutoLISP code to count number of circles with Radius

Discuss and upload any tools here for other members to use.
Post Reply
syedmeesamali
I have made <0 posts
I have made <0 posts
Posts: 4
Joined: Tue Sep 01, 2015 1:06 pm
Full Name: syed meesam ali
Company Details: CCL Gulf
Company Position Title: Project Engineer
Country: UAE
Skype Name: syedmeesamali
Linkedin Profile: Yes
Location: Dubai

AutoLISP code to count number of circles with Radius

Post by syedmeesamali »

Hi All,
I found one nice piece of code which was of immense help to me so wanted to share with all of you.
This AutoLISP code basically counts the number of circles of particular radius in selected area of drawing.
Procedure is as follows:
1. Type "Appload" in command window
2. A dialog box will pop-up where you can select the file containing below code and press "Load" button
3. Once the code is loaded in AutoCAD you can then press the command "RADCT"
4. It will prompt for radius input and you can input value for radius e.g. 40
5. Then select the objects in drawing containing circles (objects shouldn't be blocks rather individual objects (or blocks in exploded mode))
6. It will give you dialog box saying number of circles found

Regards
Syed Meesam Ali
Project Engineer, CCL
+971 555314269

syedmeesamali
I have made <0 posts
I have made <0 posts
Posts: 4
Joined: Tue Sep 01, 2015 1:06 pm
Full Name: syed meesam ali
Company Details: CCL Gulf
Company Position Title: Project Engineer
Country: UAE
Skype Name: syedmeesamali
Linkedin Profile: Yes
Location: Dubai

Re: AutoLISP code to count number of circles with Radius

Post by syedmeesamali »

Sorry I forgot the code. Here is the code below:

Code: Select all

(defun C:RADCT (/ rad ss count) 
    (setq rad (getdist "\nRadius to count: ") 
              ss (ssget (list '(0 . "CIRCLE")(cons 40 rad))) 
              count (sslength ss) 
    ) 
    (alert (strcat (itoa count) " " (rtos rad) " radius circles found.")) 
    (princ) 
)
Syed Meesam Ali
Project Engineer, CCL
+971 555314269

zoltan
V.I.P Member
V.I.P Member
Posts: 145
Joined: Mon Jun 17, 2013 5:02 pm
Full Name: Zoltan Ferenczy
Company Details: ClearEdge3D
Company Position Title: Industry Strategist
Country: USA
Linkedin Profile: Yes

Re: AutoLISP code to count number of circles with Radius

Post by zoltan »

You can also do this with the QSELECT command.
props.JPG
Select.JPG
You do not have the required permissions to view the files attached to this post.

syedmeesamali
I have made <0 posts
I have made <0 posts
Posts: 4
Joined: Tue Sep 01, 2015 1:06 pm
Full Name: syed meesam ali
Company Details: CCL Gulf
Company Position Title: Project Engineer
Country: UAE
Skype Name: syedmeesamali
Linkedin Profile: Yes
Location: Dubai

Re: AutoLISP code to count number of circles with Radius

Post by syedmeesamali »

Thanks a lot zoltan.
Actually my real problem was to count and get the details of various circles in the drawing. I could count them eventually using LISP and your method is one nice easy one but get their names was another issue. Eventually I used this beautiful piece of code to export all the names and then save them in excel after sorting for required info.
Sharing this so that if somebody faces similar problem then can easily get the solution.

Code: Select all

;TEXTOUT.LSP By: Jeffery P. Sanders
;This program gets text from an AutoCAD drawing and writes it to a text file.

;define program - listing your variable names here 
; resets them to nil after the program finishes    
(defun C:TEXTOUT(/ lts ernote filen fil eset en enlist cntr)

  ;turn echo off
  (setvar "cmdecho" 0)

  ;get ltscale (Note: ltscale should always equal dimscale)
  (setq lts(getvar "ltscale"))

  ;set the exit note to successful
  (setq ernote "\n....TextOut Complete.")

  ;use dialog box to set file name / the 1 allows
  ;the user to type in a new file name
  ;the "txt" sets the default to be "*.txt"
  (setq filen
    (getfiled "Type or Select Text File Name" "" "txt" 1)
  )

  ;open file to write
  (if (setq fil(open filen "w"))

    ;progn necessary for multiple statements inside an if statement
    (progn

      ;if ssget returns a valid selection set
      (if (setq eset(ssget))

        ;progn necessary for multiple statements inside an if statement
        (progn

          ;set the entity counter to zero [the first entity in a set is zero]
          (setq cntr 0)

          ;step through each entity in the selection set
          (while (< cntr (sslength eset))

            ;get the entity name indexed by cntr
            (setq en(ssname eset cntr))

            ;get the DXF group codes for the entity
            (setq enlist(entget en))

            ;check the group code 0 to see if entity type = TEXT
            (if(= "TEXT" (cdr(assoc 0 enlist)))

              ;progn necessary for multiple statements inside an if statement
              (progn

                ;get the text string from the entity's DXF Group Code 1
                (setq str(cdr(assoc 1 enlist)))

                ;print the string to the command line
                (princ (strcat "\nOutput To File: " str))

                ;print the string to the file
                (princ (strcat "\n" str) fil)

              ) ;close the if progn

            ) ;close the if statement

            ;increment the counter to get the next entity
            (setq cntr(+ cntr 1)) 

          ) ;close the while loop

          ;close the text file
          (close fil) 

        ) ;close the if progn

        ;set the exit note as an error
        (setq ernote "\nError - No Entities Selected.")

      ) ; close the if statement

    ) ;close the if progn

    ;set the exit note to be an error
    (setq ernote (strcat "\nError - Could not create File: " filen))

  ) ;close the if statement

  ;turn the command echo back on
  (setvar "cmdecho" 1)

  ;print the exit note to the command line
  (princ ernote)

  ;clear the command line
  (princ "\n ")

  ;supress last echo
  (princ)

) ;close the program
Syed Meesam Ali
Project Engineer, CCL
+971 555314269

User avatar
anonimou
V.I.P Member
V.I.P Member
Posts: 212
Joined: Fri Dec 14, 2007 1:45 pm
Full Name: Delio Pontes
Company Details: Williamson Technical Services Limited
Company Position Title: Engineering Surveyor
Country: United Kingdom
Linkedin Profile: Yes
Location: United Kingdom
Contact:

Re: AutoLISP code to count number of circles with Radius

Post by anonimou »

You have also "Cadtools"
http://www.glamsen.se/CadTools.htm

You will find a option to export all circles to excel with layer name, Coordinates, and radius.

zoltan
V.I.P Member
V.I.P Member
Posts: 145
Joined: Mon Jun 17, 2013 5:02 pm
Full Name: Zoltan Ferenczy
Company Details: ClearEdge3D
Company Position Title: Industry Strategist
Country: USA
Linkedin Profile: Yes

Re: AutoLISP code to count number of circles with Radius

Post by zoltan »

AutoCAD can do this natively as well using the DATAEXTRACTION command. You can extract any properties of any object type, sort the data, and then insert it into the drawing as a table or export to xls, mdb, csv, or txt.

Post Reply

Return to “AutoLisp, Dynamo, VBA, Python & .Net Tools”