+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Junior Member
    Computer Details
    Movieangel's Computer Details
    Operating System:
    Windows 7
    Computer:
    Alienware
    Discipline
    Architectural
    Movieangel's Discipline Details
    Occupation
    CAD Drafter/Designer
    Discipline
    Architectural
    Using
    AutoCAD 2012
    Join Date
    May 2011
    Location
    St. Louis
    Posts
    14

    Default Help with Stud.LSP

    Registered forum members do not see this ad.

    So I have tried to modify a batt insulation lsp originally created by David Sides to draw studs. You would think this would be easy because all I need are 45 degree lines, but I am having some trouble. I have gotten it to work for Horizontal walls and it is ok for vertical walls a bit glitchy but not horrible. Walls at an angle on the otherhand are horrible. Any advice?


    Code:
     
    ;; 
    STUD.LSP
    ;;
    ;;==========================================================
    (setq 
    xos (getvar "osmode"))
    (setvar "osmode" 0)
    (defun SSV 
    (savelist)
     (mapcar
      '(lambda 
    (sysvar)
       (list sysvar (getvar 
    sysvar))
      )
     savelist)
    )
    (setq lista '("aunits" 
    "auprec" "blipmode" "cmdecho" 
     
                           "orthomode"))
    ;;=========================================================
    (defun 
    RSV (savelist)
     (mapcar
      '(lambda 
    (sysvar)
       (setvar (car sysvar)(cadr 
    sysvar))
       (car 
    sysvar)
      )
     savelist)
    )
    ;;==========================================================
    (defun 
    HI ()
     (setq olderr *error*)
     (defun *error* 
    (errstr)
      (print errstr)(princ)
      (setq lista (RSV 
    lista))
      (setq *error* 
    olderr)
      (princ)
     )
     (setq lista (SSV 
    lista))
     (setvar "aunits" 3)
     (setvar "auprec" 
    8)
     (setvar "blipmode" 0)
     (setvar "cmdecho" 0)
     (setvar 
    "orthomode" 0)
     (prompt "\nArchitectural studs. ")
     (prompt 
    "\nBy Alison Baillargeon. July 12, 2011. 
    ")
     (princ)
    )
    ;;============================================================
    (defun 
    BYE ()
     (setq lista (RSV lista))
     (setq *error* 
    olderr)(princ)
     (princ "\nProcessing complete. 
    ")
     (princ)
    )
    ;;============================================================
    (defun 
    c:STUD (/ A ANG1 ANG2 ANG3 LEN1 LEN2 PT1 PT2 PT3 PT4 PT5 THK1 THK2 THK3 
    THK4)
     (HI)
     (setq PT1 (getpoint "\nEnter start point... 
    ")
        PT2 (getpoint PT1 "\nEnter end point. 
    ")
        THK1(getreal "\nEnter wall thickness. 
    ")
        THK2(* THK1 
    THK1)
        THK3(+ THK2 
    THK2)
        THK4(sqrt 
    THK3)
        LEN1(distance PT1 
    PT2)
        LEN2(/ LEN1 
    THK1)
        ANG1(angle PT1 
    PT2)
        ANG2(+ ANG1 
    0.7854)
        ANG3(+ ANG1 
    5.4977)
        a 0
     )
     (while (< a 
    LEN2)
      (if (= a 
    0)
       (progn
        (setq PT3 (polar PT1 
    ANG2 THK4)
         PT4 (polar PT3 ANG3 
    THK4)
         PT5 (polar PT4 ANG2 
    THK4)
           A 
    0.5
        )
        (command ".pline" 
    PT1 "w" 0.0 0.0 PT3 PT4)
       )
     
     
       (progn
        (setq PT3 
    PT5
         PT4 (polar PT3 ANG3 
    THK4)
         PT5 (polar PT4 ANG2 
    THK4))
        (command PT3 
    PT4)
        (setq a (+ a 
    2))
       )
      )
     )
     (command 
    "")
     (command ".break" "l" PT4 (polar PT4 ANG1 
    THK4))
            (BYE)
     (setvar 
    "osmode" xos)
     (princ)
    )
    Last edited by Movieangel; 14th Jul 2011 at 10:16 pm.

  2. #2
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,733

    Default

    Please read the CODE POSTING GUIDELINES and edit your post.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  3. #3
    Junior Member
    Computer Details
    Movieangel's Computer Details
    Operating System:
    Windows 7
    Computer:
    Alienware
    Discipline
    Architectural
    Movieangel's Discipline Details
    Occupation
    CAD Drafter/Designer
    Discipline
    Architectural
    Using
    AutoCAD 2012
    Join Date
    May 2011
    Location
    St. Louis
    Posts
    14

    Default

    I think I almost got it. My lisp works just as I would expect to create studs (after a whole day of trial and error as I am a newbie to Lisps) but it only works the first time after it has been loaded. In order for it to do what I expect after the first time, I have to type APPLOAD and reload it again. If I don't, it goes crazy. I am guessing it does not reset syetem variables and such, but I don't know how to fix it. Any help would be appreciated.

    Code:
     
    ;; STUD.LSP
    ;;
    ;;==========================================================
    (setq 
    xos (getvar "osmode"))
    (setvar "osmode" 0)
    (defun SSV 
    (savelist)
     (mapcar
      '(lambda 
    (sysvar)
       (list sysvar (getvar 
    sysvar))
      )
     savelist)
    )
    (setq lista '("aunits" 
    "auprec" "blipmode" "cmdecho" 
     
                           "orthomode"))
    ;;=========================================================
    (defun 
    RSV (savelist)
     (mapcar
      '(lambda 
    (sysvar)
       (setvar (car sysvar)(cadr 
    sysvar))
       (car 
    sysvar)
      )
     savelist)
    )
    ;;==========================================================
    (defun 
    HI ()
     (setq olderr *error*)
     (defun *error* 
    (errstr)
      (print errstr)(princ)
      (setq lista (RSV 
    lista))
      (setq *error* 
    olderr)
      (princ)
     )
     (setq lista (SSV 
    lista))
     (setvar "aunits" 3)
     (setvar "auprec" 
    8)
     (setvar "blipmode" 0)
     (setvar "cmdecho" 0)
     (setvar 
    "orthomode" 0)
     (prompt "\nArchitectural studs. ")
     (prompt 
    "\nBy Alison Baillargeon. July 12, 2011. 
    ")
     (princ)
    )
    ;;============================================================
    (defun 
    BYE ()
     (setq lista (RSV lista))
     (setq *error* 
    olderr)(princ)
     (princ "\nProcessing complete. 
    ")
     (princ)
    )
    ;;============================================================
    (defun 
    c:STUD (/ A ANG1 ANG2 ANG3 LEN1 LEN2 PT1 PT2 PT3 PT4 PT5 THK1 THK2 THK3 
    THK4)
     (HI)
     (setq PT1 (getpoint "\nEnter start point... 
    ")
        PT2 (getpoint PT1 "\nEnter end point. 
    ")
        THK1(getreal "\nEnter wall thickness. 
    ")
        THK2(* THK1 
    THK1)
        THK3(+ THK2 
    THK2)
        THK4(sqrt 
    THK3)
        LEN1(distance PT1 
    PT2)
        LEN2(/ LEN1 
    THK1)
        ANG1(angle PT1 
    PT2)
        ANG2(+ ANG1 
    0.7854)
        ANG3(+ ANG1 
    5.4977)
        a 0
     )
     (while (< a 
    LEN2)
      (if (= a 
    0)
       (progn
        (setq PT3 (polar PT1 
    ANG2 THK4)
         PT4 (polar PT3 ANG3 
    THK4)
         PT5 (polar PT4 ANG2 
    THK4)
           A 
    0.5
        )
        (command ".pline" 
    PT1 "w" 0.0 0.0 PT3 PT4)
       )
     
     
       (progn
        (setq PT3 
    PT5
         PT4 (polar PT3 ANG3 
    THK4)
         PT5 (polar PT4 ANG2 
    THK4))
        (command PT3 
    PT4)
        (setq a (+ a 
    2))
       )
      )
     )
     (command 
    "")
     (command ".break" "l" PT4 (polar PT4 ANG1 
    THK4))
            (BYE)
     (setvar 
    "osmode" xos)
     (princ)
    )

  4. #4
    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,322

    Default

    The following code uses a change in coordinate frame to make the calculation of the 'stud' points more succinct, however the drawback for this crafty shortcut lies in the fact that the trans function uses the arbitrary axis algorithm to define a coordinate frame from the supplied normal vector, and so this code will only work in UCS for which the UCS plane is parallel to the WCS plane.

    Code:
    (defun c:stud ( / p1 p2 n l s ) ;; © Lee Mac 2011
      (if
        (and
          (setq p1 (getpoint "\nSpecify Start Point: "))
          (setq p2 (getpoint "\nSpecify End Point: " p1))
          (progn (initget 6)
            (setq *w
              (cond
                (
                  (getdist p1
                    (strcat "\nSpecify Wall Thickness"
                      (if *w (strcat " <" (rtos *w) ">: ") ": ")
                    )
                  )
                )
                ( *w )
              )
            )
          )
        )
        (progn
          (setq n (mapcar '- (trans p2 1 0) (trans p1 1 0))
                l (list (trans p1 1 n))
                s -1
          )
          (repeat (fix (/ (distance p1 p2) *w))
            (setq l (cons (list (+ (* (setq s (- s)) *w) (caar l)) (cadar l) (+ *w (caddar l))) l))
          )
          (entmakex
            (append
              (list
                (cons 0 "LWPOLYLINE")
                (cons 100 "AcDbEntity")
                (cons 100 "AcDbPolyline")
                (cons 90 (length l))
                (cons 70 0)
              )
              (mapcar '(lambda ( p ) (cons 10 (trans p n 0))) l)
            )
          )
        )
      )
      (princ)
    )
    The alternative approach, using polar may look something like this, and would work in all UCS/Views:

    Code:
    (defun c:stud ( / p1 p2 a n l s ) ;; © Lee Mac 2011
      (if
        (and
          (setq p1 (getpoint "\nSpecify Start Point: "))
          (setq p2 (getpoint "\nSpecify End Point: " p1))
          (progn (initget 6)
            (setq *w
              (cond
                (
                  (getdist p1
                    (strcat "\nSpecify Wall Thickness"
                      (if *w (strcat " <" (rtos *w) ">: ") ": ")
                    )
                  )
                )
                ( *w )
              )
            )
          )
        )
        (progn
          (setq n (trans '(0. 0. 1.) 1 0 t)
                a (angle p1 p2)
                l (list p1)
                s -1
          )
          (repeat (fix (/ (distance p1 p2) *w))
            (setq l (cons (polar (polar (car l) a *w) (+ a (* (setq s (- s)) (/ pi 2.))) *w) l))
          )
          (entmakex
            (append
              (list
                (cons 0 "LWPOLYLINE")
                (cons 100 "AcDbEntity")
                (cons 100 "AcDbPolyline")
                (cons 90 (length l))
                (cons 70 0)
                (cons 210 n)
              )
              (mapcar '(lambda ( p ) (cons 10 (trans p 1 n))) l)
            )
          )
        )
      )
      (princ)
    )
    Last edited by Lee Mac; 15th Jul 2011 at 12:18 am.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  5. #5
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,733

    Default

    I have deleted your other thread regarding the reloading of your LISP, because you have also asked in this thread and received a response.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  6. #6
    Junior Member
    Computer Details
    Movieangel's Computer Details
    Operating System:
    Windows 7
    Computer:
    Alienware
    Discipline
    Architectural
    Movieangel's Discipline Details
    Occupation
    CAD Drafter/Designer
    Discipline
    Architectural
    Using
    AutoCAD 2012
    Join Date
    May 2011
    Location
    St. Louis
    Posts
    14

    Default Awesome

    Wow Lee Mac. Thanks so much for the code. I worked all day on mine, no kidding, over 8 hours, and it was still glitchy and yours is totally different but works perfectly. I wish I could understand lisps a bit better so this kind of stuff wouldn't take me forever, but I do really appreciate your help and maybe I can disect your code to figure out how it actually works to make future attempts a bit easier. Both work great. I will only be using this on floor plans so the UCS should not have any issues. Are there any advantages of one over the other? Thanks again. Really Really appreciate it.

  7. #7
    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,322

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Movieangel View Post
    Wow Lee Mac. Thanks so much for the code. I worked all day on mine, no kidding, over 8 hours, and it was still glitchy and yours is totally different but works perfectly. I wish I could understand lisps a bit better so this kind of stuff wouldn't take me forever, but I do really appreciate your help and maybe I can disect your code to figure out how it actually works to make future attempts a bit easier.
    You're very welcome

    To be honest, its mostly practice coupled with a lot of reading - almost everything I know about LISP I have learnt from the Visual LISP IDE Help Documentation and these (and other) forums.

    Quote Originally Posted by Movieangel View Post
    Both work great. I will only be using this on floor plans so the UCS should not have any issues. Are there any advantages of one over the other? Thanks again. Really Really appreciate it.
    The first code was demonstrating an alternative approach to the usual methods, I define a coordinate frame such that the points may be calculated at zero rotation, then transformed back to WCS when creating the LWPolyline. This allows for easier coordinate manipulation, but has some drawbacks. I was mainly experimenting with other ways to approach the problem, the second code is far more practical.

    The second code would be a better base for a beginner to learn from since it uses a more intuitive approach, calculating the points of the LWPolyline using the polar function.

    If you have any questions about any of the code I have posted I would be happy to provide some clarification.

    Lee
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. Metal stud DB rotate issue
    By beardking in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 7th Jun 2010, 06:51 pm

Tags for this Thread

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