+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 29
  1. #1
    Junior Member
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Mar 2018
    Posts
    17

    Default Lisp to automatically draw rectangles where it intersects with specific points

    Registered forum members do not see this ad.

    Hi there folks, i work in a company that manufactures models for buildings.
    And i work specific in the drawing sector, where i use AutoCad to draw the pieces for the models.

    In our line of work we constantly have to draw "maps" to the people who take the pieces and put them all together to form the model

    I have already developed several lisp routines to ease my work, and now i'm currently trying to ease (a lot) the making of these maps.

    so what i need right now is:
    1) a way to sort points in a list of points, so that they will be in order from the closest to the furthest in relation to a base point
    2) the amount of points will always be different so, how can i store these points in succession? (like point1 being the closest and point10 being the furthest if there are 10 points in the list)
    3) before sorting the points (or after) remove the points that are too close from each other (like, if point2 is 0.02 units distant from point3, disregard point3)

    and all of this is to be able to automatically detect the position of windows and doors in the middle of a wall and mark them in the map without having to manually find them

    here's my code so far (it asks for the espessure of the material used in the model, the number of the wall in the map, and the height of the text to place the number of the wall in the map)

    P.S i'm a very amateur programmer, if so
    Code:
    (defun c:md ()
    (setq layercorrente (getvar 'clayer))
    (defun dtr (a) (* Pi (/ a 180.0)))
    (defun rtd (b) (* b (/ 180.0 Pi)))
    (setvar "OSNAPCOORD" 1)
    (setq esp (getdist "\nDigite a espessura da parede <enter = ultima espessura>: "))
    (if (= esp nil) (setq esp esptemp))
    (setq esptemp esp)
    (setq altura_texto (getdist "\nInsira a altura do texto <enter = ultima altura>:"))
      (cond 
        ((and (= altura_texto nil) (= altura_textotemp nil)) (setq altura_texto esp)
        )
        ((and (= altura_texto nil) (/= altura_textotemp nil)) (setq altura_texto altura_textotemp)
        )
      )
    (setq numero (getint "Indique o numero da próxima parede <enter = ultimo numero de parede>:"))
      (cond
        ((and (= numero nil) (= numero_old nil))
        (setq numero 1)
        )
        ((and (= numero nil) (/= numero_old nil))
        (setq numero numero_old)
        )
      )
    (setq numero_old numero)
    (setq texto (itoa numero))
    (command "_-style" "loks" "txt" altura_texto "1" "" "" "" "")
    (setq rotation 0)
    (setq ponto1 (getpoint "\nInsira o primeiro ponto de inserção da parede levando em conta o sentido anti-horário:"))
    (setq ponto2 (getpoint "\nInsira o segundo ponto de inserção:"))
    (setq comprimento (distance ponto1 ponto2))
    (setq ang1 (angle ponto1 ponto2))
    (setq ang2 (rtd ang1))
    (setq ang3 (+ ang2 90.0))
    (if (>= ang3 360.0) (setq ang3 (- ang3 360)))
    (setq ang4 (+ ang2 270.0))
    (if (>= ang4 360.0) (setq ang4 (- ang4 360)))
    (setq ponto3 (polar ponto2 (dtr ang3) esp))
    (setq ponto4 (polar ponto1 (dtr ang3) esp))
    (setq pontoref (polar ponto1 ang1 (/ comprimento 2)))
    (cond
      ((<= 0 ang4 105) (setq pontotxt (polar pontoref (dtr ang4) (* 1.5 altura_texto)))
      )
      ((and (< 105 ang4 255) (<= 0 numero 9)) (setq pontotxt (polar pontoref (dtr ang4) (* 2 altura_texto)))
      )
      ((and (< 105 ang4 255) (<= 10 numero 99)) (setq pontotxt (polar pontoref (dtr ang4) (* 2.5 altura_texto)))
      )
      ((and (< 105 ang4 255) (<= 100 numero)) (setq pontotxt (polar pontoref (dtr ang4) (* 3.4 altura_texto)))
      )
      ((<= 255 ang4 300) (setq pontotxt (polar pontoref (dtr ang4) (* 2 altura_texto)))
      )
      ((< 300 ang4 360) (setq pontotxt (polar pontoref (dtr ang4) (* 1.5 altura_texto)))
      )
    )
    (defun c:mapadeparedes ()
    (setvar 'clayer layercorrente)
    (command "pline" ponto1 ponto2 ponto3 ponto4 "c")
    (command "LAYER" "M" "-TEXTO_DECORADO" "C" "42" "" "")
    (command "text" pontotxt rotation texto)
    (setvar 'clayer layercorrente)
    )
    (c:mapadeparedes)
    (while (/= ponto1 nil)
    (setq ponto1 (getpoint "\nInsira o primeiro ponto de inserção da parede levando em conta o sentido anti-horário:"))
      (cond
        ((/= ponto1 nil)
    (setq ponto2 (getpoint "\nInsira o segundo ponto de inserção:"))
    (setq comprimento (distance ponto1 ponto2))
    (setq ang1 (angle ponto1 ponto2))
    (setq ang2 (rtd ang1))
    (setq ang3 (+ ang2 90.0))
    (if (>= ang3 360.0) (setq ang3 (- ang3 360)))
    (setq ang4 (+ ang2 270.0))
    (if (>= ang4 360.0) (setq ang4 (- ang4 360)))
    (setq ponto3 (polar ponto2 (dtr ang3) esp))
    (setq ponto4 (polar ponto1 (dtr ang3) esp))
    (setq pontoref (polar ponto1 ang1 (/ comprimento 2)))
    (cond
      ((<= 0 ang4 105) (setq pontotxt (polar pontoref (dtr ang4) (* 1.5 altura_texto)))
      )
      ((and (< 105 ang4 255) (<= 0 numero 9)) (setq pontotxt (polar pontoref (dtr ang4) (* 2 altura_texto)))
      )
      ((and (< 105 ang4 255) (<= 10 numero 99)) (setq pontotxt (polar pontoref (dtr ang4) (* 2.5 altura_texto)))
      )
      ((and (< 105 ang4 255) (<= 100 numero)) (setq pontotxt (polar pontoref (dtr ang4) (* 3.4 altura_texto)))
      )
      ((<= 255 ang4 300) (setq pontotxt (polar pontoref (dtr ang4) (* 2 altura_texto)))
      )
      ((< 300 ang4 360) (setq pontotxt (polar pontoref (dtr ang4) (* 1.5 altura_texto)))
      )
    )
    (setq numero (+ numero 1))
    (setq texto (itoa numero))
    (c:mapadeparedes)
        )
      )
    )
    (setq numero_old (+ numero 1))
    )
    (princ "\nDIGITE MD PARA DESENHAR O MAPA DE PAREDES DE DECORADO MAIS FACILMENTE.")
    (princ)

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,261

    Default

    Hi,

    Simple example of sorting a list of points relative to a certain point:
    Code:
    (setq org '(0. 0. 0.)
          pts '((9. 8. 0.) (7. 6. 0.) (1. 2. 0.) (3. 4. 0.))
          )
    
    (vl-sort pts '(lambda (a b) (< (distance org a) (distance org b))))

  3. #3
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,489

    Default

    Solution for step #3 (Lee Mac's LM:UniqueFuzz subfunction).

    Performed attempt anyway (without looking at his code) and ended up with:
    Code:
    ; _$ (UQpL 0.01 '(1.0 1.1 2.0 2.01 2.2)) >> (1.0 1.1 2.0 2.2)
    ; _$ (UQpL 0.15 '(1.0 1.1 2.0 2.01 2.2)) >> (1.0 2.0 2.2)
    (defun UQpL ( fuzz pL )
      ((lambda (f) (f pL fuzz))
        (lambda (pL fuzz / v)
          (if pL 
            (cons 
              (setq v (car pL))
              (f ((lambda (pL) (vl-remove-if (function (lambda (x) (equal v x fuzz))) pL)) (cdr pL)) fuzz)
            )
          )
        )
      )
    ); defun UQpL
    Not sure will it be faster, since the tail recursion stores 'v' and doesn't try to access the car of the point list within the vl-remove-if.

    Doing the same with a straight recursion - thats quite an achievement demonstrated by Lee.

  4. #4
    Junior Member
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Mar 2018
    Posts
    17

    Default

    thanks for both Tharwhat and Grrr u guys helped a lot!
    In the end i only used Tharwhat's solution, because i solved the other problems by reaching the same goal by means of alternative methods.
    Nevertheless, more knowledge is never enough, so thanks again =)

    Now my routine is almost complete, the only ting i would really need is a more effective way to verify if a specified layer is contained within a selection set

    Right now i'm isolating the specified layer and if the selection set is empty, this means a return nil, otherwise T, but it consumes a lot o time because this process is repeated many times
    So, is there a way to find if there is at least one object, of a specified layer within a selection set?

  5. #5
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    948

    Default

    Here's the most direct way:
    Code:
    (ssget '((8 . "yourlayername")))
    Or if you already have items selected and converted to a list of enames:
    Code:
    (vl-some '(lambda (x) (wcmatch (cdr (assoc 8 (entget x))) "LAYERNAME")) listofenames)

  6. #6
    Junior Member
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Mar 2018
    Posts
    17

    Default

    Quote Originally Posted by ronjonp View Post
    Here's the most direct way:
    Code:
    (ssget '((8 . "yourlayername")))
    Or if you already have items selected and converted to a list of enames:
    Code:
    (vl-some '(lambda (x) (wcmatch (cdr (assoc 8 (entget x))) "LAYERNAME")) listofenames)
    thanks ronjop!
    For the specific case the first code is enough, but the latter will also be quite useful! =)

    I'll just leave the topic opened for the case that anything comes up again, but i think that for now i'm set!

    (P.S i have posted my code earlier, if anyone could analyze it to verify if i'm "coding right", like... if there's a more effective way to do the same thing i'm already doing, the code is a bit extense, but if anyone have a little free time i would appreciate it)

  7. #7
    Junior Member
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Mar 2018
    Posts
    17

    Default

    Hi there folks, in trying to continue to improve my lisp routine i'm wondering if there's a way i can determine a pattern of objects to be found, and then quantify them in a selection set... like... i determine i want to find 2 vertical lines, measuring 0.1, and 0.1 distant from each other in X, then i select a bunch of objects and want the code to return to me teh amount of objects found in these patters i specified earlier in thgis selection

  8. #8
    Junior Member
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Mar 2018
    Posts
    17

    Default

    P.S i want to specify the pattern also by selection set, not by numeric parameters

  9. #9
    Junior Member
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Mar 2018
    Posts
    17

    Default

    it 's not possible?

  10. #10
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    948

    Default

    Registered forum members do not see this ad.

    Post a drawing of your example selection set .. I'm lost on what you're trying to do.

Similar Threads

  1. Draw a circle tan to a line and intersects a point. Radius unkown.
    By guitarguy1685 in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 8
    Last Post: 2nd Aug 2016, 08:20 am
  2. get intersection points and draw rectangles
    By jasonle215 in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 11th Aug 2015, 09:43 am
  3. Lisp to draw circles and rectangles from values in a .CSV file
    By CADINATOR in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 6th Feb 2015, 03:53 am
  4. Drawing Rectangles to specific dimensions
    By ADAM'S_APPLE in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 30th Oct 2012, 06:09 pm
  5. automatically expand rectangles (polyline)
    By Tarkin in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 8
    Last Post: 12th Dec 2010, 10:56 pm

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