+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Senior Member
    Using
    AutoCAD 2015
    Join Date
    Jan 2015
    Posts
    126

    Default Draw lines and circles with some rules

    Registered forum members do not see this ad.

    Hi guys!

    I've wrote this lisp in order to draw these circles + lines in a fasted way.

    As you can see it doesn't work very good with the vertical edge of 30cm, but it works if I put 60cm..



    The program asks me the following:
    1. number of lines
    2. number of circles for each line
    3. 2 points where to draw them
    4. side of the line I've just draw with the 2 points

    Code:
    (defun C:pu (/ linea)
      (setq n1 (getint "\nQuante legature? ") ;how many lines
            n2 (getint "\nQuante file? ")) ; how many circles for each line
      
      
      (command "_Line" pause pause "")
      (setq linea (entlast))
      ;(command "_divide" linea (* 2 n1)) 
      
      (setq p1 (cdr (assoc 10 (entget linea)))
          p2 (cdr (assoc 11 (entget linea)))
            dist (/ (distance p1 p2) (* 2 n1)))
      (entdel linea)
      (setq ref (getpoint))
    
      (setq passo 0.16
            dist1 0.08
            n 0
            j 1
            )
      
        
    
      (IF (> (nth 0 p1) (nth 0 p2))
             (setq swap p2
                   p2 p1
                   p1 swap)
        )
      (IF (> (nth 1 p1) (nth 1 p2))
             (setq swap p2
                   p2 p1
                   p1 swap)
        )
      
    ;Horizzontal
      (COND ((= (fix (nth 1 p1)) (fix (nth 1 p2)))
    (IF (< (nth 1 ref) (nth 1 p1))
             (setq passo (* passo -1)
              dist1 (* dist1 -1)
              )
      )
             
         
    
           (while (< n  n1 )
             (setq i 1)
                
             
             (Entmake (list (cons 0 "CIRCLE")
                          (cons 8 "SCHÖCK_BOLE")
                          (cons 10 (list (+ (nth 0 p1) (* j dist)) (+ (nth 1 p1) dist1) (nth 2 p1)))
                          (cons 40 0.035)
                          (cons 62 3)
                          )
                        )
                      
             
        (while (< i n2)
        
              (Entmake (list (cons 0 "CIRCLE")
                          (cons 8 "SCHÖCK_BOLE")
                          (cons 10 (list (+ (nth 0 p1) (* j dist)) (+ (nth 1 p1) dist1 (* i passo)) (nth 2 p1)))
                          (cons 40 0.035)
                          (cons 62 3)
                          )
                        )
              (setq i (+ i 1))
              )
             
             (entmake (list (cons 0 "LINE")
                            (Cons 8 "SCHÖCK_BOLE")
                            (cons 10 (list (+ (nth 0 p1) (* j dist)) (+ (nth 1 p1) dist1) (nth 2 p1)))
                            (cons 11 (list (+ (nth 0 p1) (* j dist)) (+ (nth 1 p1) dist1 (* (- i 1) passo)) (nth 2 p1)))
                            (cons 62 3)
                            )
                      )
             (setq j (+ j 2)
                   n (+ n 1))
             )
             
             
    
               
                          
             )
            
            ;VERTICAL
            ((= (fix (nth 0 p1)) (fix (nth 0 p2)))
        (IF (< (nth 0 ref) (nth 0 p1))
             (setq passo (* passo -1)
              dist1 (* dist1 -1)
              )
      )
    
             (while (< n  n1 )
             (setq i 1)
                
             
             (Entmake (list (cons 0 "CIRCLE")
                          (cons 8 "SCHÖCK_BOLE")
                          (cons 10 (list  (+ (nth 0 p1) dist1) (+ (nth 1 p1) (* j dist)) (nth 2 p1)))
                          (cons 40 0.035)
                          (cons 62 3)
                          )
                        )
             
        (while (< i n2)
        
              (Entmake (list (cons 0 "CIRCLE")
                          (cons 8 "SCHÖCK_BOLE")
                          (cons 10 (list  (+ (nth 0 p1) dist1 (* i passo)) (+ (nth 1 p1) (* j dist)) (nth 2 p1)))
                          (cons 40 0.035)
                          (cons 62 3)
                          )
                        )
              (setq i (+ i 1))
              )
             
             (entmake (list (cons 0 "LINE")
                            (Cons 8 "SCHÖCK_BOLE")
                            (cons 10 (list  (+ (nth 0 p1) dist1) (+ (nth 1 p1) (* j dist)) (nth 2 p1)))
                            (cons 11 (list  (+ (nth 0 p1) dist1 (* (- i 1) passo)) (+ (nth 1 p1) (* j dist)) (nth 2 p1)))
                            (cons 62 3)
                            )
                      )
             (setq j (+ j 2)
                   n (+ n 1))
             )
    
    
             
             )
            )
      )
    How can I handle non vertical/horizontal lines?

    How can I draw in the corner as well?



    Thanks!

    Dennis
    Attached Images
    Last edited by MastroLube; 8th Feb 2018 at 01:36 pm.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,460

    Default

    Use the polar function to calculate the position of points, and the angle function to calculate the angle between two given points.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,171

    Default

    One suggestion in your code you repeat the entmake multiple times this could exist maybe twice line,circle as you can use a defun that you pass the variables to, this is a standard type of thing in programming to not write bits of code repeatedly.

    Code:
    (defun ML:Makeline (lay pt1 pt2 /  )
        (entmake (list (cons 0 "LINE")
           (Cons 8 Lay)
           (cons 10 pt1)
           (cons 11 pt2)
           (cons 62 3)
        )
    )
    )
     
    ; put at start
    (setq clay "SCHÖCK_BOLE")
     
    ; example
    (setq p1 (list  (+ (nth 0 p1) dist1) (+ (nth 1 p1) (* j dist)) (nth 2 p1)))
    (setq p2 (list (+ (nth 0 p1) (* j dist)) (+ (nth 1 p1) dist1 (* (- i 1) passo)) (nth 2 p1)))
    (ML:Makeline clay p1 p2)
    A man who never made mistakes never made anything

  4. #4
    Senior Member
    Using
    AutoCAD 2015
    Join Date
    Jan 2015
    Posts
    126

    Default

    Registered forum members do not see this ad.

    Thank you guys for your help!
    Yes I should learn to code a little bit better my code looks always like a mess..

    I'll try to fix it!

    See you soon!
    Dennis

    Dennis

Similar Threads

  1. Replies: 0
    Last Post: 15th Jul 2011, 08:30 pm
  2. Draw A Line With 2 Circles
    By JONTHEPOPE in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 29th Aug 2008, 06:10 pm
  3. Need to Draw Circles at all endpoints of and object
    By MikeP in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 13th Jun 2008, 03:20 pm
  4. Going in circles trying to draw an arc in 3D
    By Gerhard van Eeden in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 5th Jun 2008, 05:38 pm
  5. draw circles through points
    By motee-z in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 12th Jul 2006, 05:50 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts