+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    Oct 2009
    Posts
    171

    Default another question...

    Registered forum members do not see this ad.

    I know I have alot of questions, hopefully i will be able to contribute soon as well.

    I wrote the following lisp

    Code:
    (defun C:CN ()
      (setq CRosmod (getvar "osmode"))
      (setq CRcecho  (getvar "cmdecho"))
      
    ------------------------------------------------------------------------   
      (defun *error* (msg)                ;;;error handler
           (if CRcecho (setvar "cmdecho" CRcecho))    ;;;resets echo,osnap if you cancel/quit
           (if CRosmod (setvar "osmode" CRosmod))
           (princ msg)
           (princ))
    ------------------------------------------------------------------------  
        (setq CBP (getpoint "\nSpecify base point: "))
          (setq CL1 (getdist "\nSpecify width of channel: "))
          (setq CL2 (getdist "\nSpecify size of legs: "))
          (setq CW1 (getdist "\nSpecify thickness <0.125>: "))
          (if (= CW1 nil) (setq CW1 0.125))
             (setq P2 (list (+ (car CBP) CL1) (cadr CBP)))
             (setq P3 (list (car P2) (+ (cadr CBP) CL2)))
             (setq P4 (list (- (car P2) CW1) (cadr P3)))
             (setq P5 (list (car P4) (- (cadr P3) (- CL2 CW1))))
             (setq P6 (list (- (car P4) (- CL1 (* CW1 2))) (cadr P5)))
             (setq P7 (list (car P6) (+ (cadr P5) (- CL2 CW1))))
             (setq P8 (list (- (car P6) CW1) (cadr P7)))
          (setvar "osmode" 0)
           (setvar "cmdecho" 0)
          (command "_.pline" CBP P2 P3 P4 P5 P6 P7 P8 "close")
          (setvar "cmdecho" CRcecho)
        (setvar "osmode" CRosmod)
      (princ)
      )
    This is a lisp to draw a U-Channel of any size and thickness. if you notice I highlighted a line in red. That line is used for the size of both legs of the channel. Sometimes one of the legs is longer than the other. So I'd like a 2nd line for the 2nd leg. However I would like that line to store the length of the first leg as a default size so you can just press enter if they are the same. So the line might read as follows

    "Specify size of first leg <maybe a previous size used>: "
    "Specify size of second leg <size of first leg>: " i can just press enter

    I can't put the variable in the <> because it will just print the variable name. I hope this makes sense, any help is greatly appreciated.

  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
    15,708
    Lee Mac Programming

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

    Just another Swamper

  3. #3
    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
    15,708

    Default

    This is how I would approach it:

    Code:
    (setq CL2 (getdist "\nSpecify Size of Leg 1: "))
    
    (setq CL3 (cond ((getdist (strcat "\nSpecify Size of Leg 2 <" (rtos CL2) "> : ")))
                    (CL2)))
    Also, I would advise you to either use IF statements or the initget function in your code, to allow for null user input
    Lee Mac Programming

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

    Just another Swamper

  4. #4
    Super Member mdbdesign's Avatar
    Computer Details
    mdbdesign's Computer Details
    Operating System:
    XP PRO
    Computer:
    Homemade
    Motherboard:
    GIGABYTE G31M-ES2L
    CPU:
    INTEL CORE 2-QUAD-Q6600@2.4GHz
    RAM:
    4 GB
    Graphics:
    NVIDIA GeForce 9800 gt 1gb
    Primary Storage:
    WESTERN DIGITAL 500GB
    Monitor:
    2 - 21" COMPACQ
    Discipline
    Mechanical
    mdbdesign's Discipline Details
    Occupation
    Designing Engineer in Engineering Department
    Discipline
    Mechanical
    Details
    Pressure tanks Oil processing & storage equip. Steel mill equip. Telecom towers & equip. Wind turbine towers Power plant structures etc.
    Using
    AutoCAD 2012
    Join Date
    Jan 2007
    Location
    Courtice, Ontario, Canada
    Posts
    749

    Default

    And little info:
    Specify Size of Leg 1(@ base point):
    will be handy.
    Edit:
    What about channel rotation?

  5. #5
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,925

    Default

    Just to expand a little on what the others said and to clean up the code:

    Code:
    (defun C:CN (/ CRcecho CROsmod CRplwid CBP CL1 CL2 CW1
                   P2 P3 P4 P5 P6 P7 P8)
    
      (setq CRosmod (getvar "osmode"))
      (setq CRcecho (getvar "cmdecho"))
      (setq CRplwid (getvar "PLINEWID"))
    
    ;------------------------------------------------------------------------
      (setq *error*
         (lambda (msg)
           (setvar "cmdecho" CRcecho)
           (setvar "osmode" CRosmod)
           (princ msg)
           (princ)))
    
    ;------------------------------------------------------------------------
      (initget 1)
      (setq CBP (getpoint "\nSpecify base point: "))
    
      (initget 7)
      (setq CL1 (getdist "\nSpecify width of channel: "))
    
      (initget 7)
      (setq CL2 (getdist "\nSpecify size of legs: "))
    
      (initget 6)
      (setq CW1 (getdist "\nSpecify thickness <0.125>: "))
      (if (not CW1)
          (setq CW1 0.125))
    
      (setq P2 (list (+ (car CBP) CL1)  (cadr CBP))
            P3 (list (car P2)           (+ (cadr CBP) CL2))
            P4 (list (- (car P2) CW1)   (cadr P3))
            P5 (list (car P4)           (- (cadr P3) (- CL2 CW1)))
            P6 (list (- (car P4)        (- CL1 (* CW1 2))) (cadr P5))
            P7 (list (car P6)           (+ (cadr P5) (- CL2 CW1)))
            P8 (list (- (car P6) CW1)   (cadr P7)))
    
      (setvar "osmode" 0)
      (setvar "cmdecho" 0)
      (setvar "PLINEWID" 0)
    
      (command "_.PLINE" CBP P2 P3 P4 P5 P6 P7 P8 "_Close")
    
      (setvar "cmdecho" CRcecho)
      (setvar "osmode" CRosmod)
      (setvar "PLINEWID" CRplwid)
      (prin1))

    -David
    R12 (Dos) - A2K

  6. #6
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    Oct 2009
    Posts
    171

    Default

    1) Thanks for all the great help. I"m looking into that post by lee mac, thanks
    2) I don't know what you mean by "Specify Size of Leg 1(@ base point):". And I was planing another line in the lisp to rotate the channel after it's drawn. I was thinking something along the lines of
    (command "_.rotate" "L" "" CBP pause)

    3) lol yeah that code does look alot cleaner and easier to read. I guess I need to learn to to keep my lisp's neat. And thanks for that PLINEWID line. I didn't think of that but I can see how that can mess up my channel. I personally rarely use plines with thickness but to make this a lisp for everyone it's a great thought.

  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
    15,708

    Default

    I prefer to use "polar", so here is another way to approach things:

    Code:
    (defun C:CN (/ SysVars OldVals CBP CL1 CL2 CL3 CW1
                   P2 P3 P4 P5 P6 P7 P8)
    
      (setq SysVars '("CMDECHO" "OSMODE" "PLINEWID")
            OldVals  (mapcar 'getvar SysVars))
    ;------------------------------------------------------------------------  
      (setq *error*
         (lambda (msg)
           (mapcar 'setvar SysVars OldVals)
           (princ msg)
           (princ)))
    ;------------------------------------------------------------------------  
      (initget 1)
      (setq CBP (getpoint "\nSpecify base point: "))
    
      (initget 7)
      (setq CL1 (getdist CBP "\nSpecify width of channel: "))
    
      (initget 7)
      (setq CL2 (getdist "\nSpecify size of Leg 1: " CBP))
    
      (initget 6)
      (setq CL3
        (cond ((getdist CBP (strcat "\nSpecify Size of Leg 2 <" (rtos CL2) "> : ")))
              (CL2)))
    
      (initget 6)  
      (setq CW1 (cond ((getdist "\nSpecify thickness <0.125>: ")) (0.125)))
    
      (setq P2 (polar CBP          0 CL1)
            P3 (polar P2  (* 0.5 pi) CL3)
            p4 (polar P3         pi  CW1)
            p5 (polar p4  (* 1.5 pi) (- CL3 CW1))
            p6 (polar p5         pi  (- CL1 (* 2. CW1)))
            p7 (polar p6  (* 0.5 pi) (- CL2 CW1))
            p8 (polar p7         pi  CW1))
    
      (mapcar 'setvar SysVars '(0 0 0))
    
      (command "_.PLINE" CBP P2 P3 P4 P5 P6 P7 P8 "_Close")
    
      (mapcar 'setvar SysVars OldVals)
      (prin1))
    I have set the SysVars using a different method also.

    (Used some of your code David )

    Lee
    Lee Mac Programming

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

    Just another Swamper

  8. #8
    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
    15,708

    Default

    Quote Originally Posted by guitarguy1685 View Post
    2) I don't know what you mean by "Specify Size of Leg 1(@ base point):".
    GetDist (and GetPoint) can accept a point argument, in addition to the string. (see VLIDE help files).

    Example in above code.

    Quote Originally Posted by guitarguy1685 View Post
    And I was planing another line in the lisp to rotate the channel after it's drawn. I was thinking something along the lines of
    (command "_.rotate" "L" "" CBP pause)
    I would use (entlast) to capture the polyline entity, or using entmakex:

    Code:
    (defun C:CN (/ CBP CL1 CL2 CL3 CW1 P2 P3 P4 P5 P6 P7 P8 POLY PTLST)
      
      (setq *error* (lambda (msg) (princ msg) (princ)))
      
      (initget 1)
      (setq CBP (getpoint "\nSpecify base point: "))
    
      (initget 7)
      (setq CL1 (getdist CBP "\nSpecify width of channel: "))
    
      (initget 7)
      (setq CL2 (getdist "\nSpecify size of Leg 1: " CBP))
    
      (initget 6)
      (setq CL3
        (cond ((getdist CBP (strcat "\nSpecify Size of Leg 2 <" (rtos CL2) "> : ")))
              (CL2)))
    
      (initget 6)  
      (setq CW1 (cond ((getdist "\nSpecify thickness <0.125>: ")) (0.125)))
    
      (setq ptLst
        (list CBP      
          (setq P2 (polar CBP        0  CL1))
          (setq P3 (polar P2 (* 0.5 pi) CL3))
          (setq p4 (polar P3        pi  CW1))
          (setq p5 (polar p4 (* 1.5 pi) (- CL3 CW1)))
          (setq p6 (polar p5        pi (- CL1 (* 2. CW1))))
          (setq p7 (polar p6 (* 0.5 pi) (- CL2 CW1)))
          (setq p8 (polar p7        pi  CW1))))
    
      (setq poly (entmakex
                   (append (list (cons 0   "LWPOLYLINE")
                                 (cons 100 "AcDbEntity")
                                 (cons 100 "AcDbPolyline")
                                 (cons 90 8)
                                 (cons 70 1))
                           (mapcar (function (lambda (x) (cons 10 x))) ptLst))))
    
      (command "_.rotate" poly "" CBP pause)
               
      (prin1))
    Notice that you needn't change the Sys Vars such as OSMODE with entmakex, and you can add DXF group codes to change layer/width etc.

    Quote Originally Posted by guitarguy1685 View Post
    3) lol yeah that code does look alot cleaner and easier to read. I guess I need to learn to to keep my lisp's neat.
    For a quick format, you can click on the formatting button in the Visual LISP Editor

    Hope this all helps, and if you have any trouble understanding anything me or David has posted, don't hesitate to ask

    Lee
    Lee Mac Programming

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

    Just another Swamper

  9. #9
    Super Member mdbdesign's Avatar
    Computer Details
    mdbdesign's Computer Details
    Operating System:
    XP PRO
    Computer:
    Homemade
    Motherboard:
    GIGABYTE G31M-ES2L
    CPU:
    INTEL CORE 2-QUAD-Q6600@2.4GHz
    RAM:
    4 GB
    Graphics:
    NVIDIA GeForce 9800 gt 1gb
    Primary Storage:
    WESTERN DIGITAL 500GB
    Monitor:
    2 - 21" COMPACQ
    Discipline
    Mechanical
    mdbdesign's Discipline Details
    Occupation
    Designing Engineer in Engineering Department
    Discipline
    Mechanical
    Details
    Pressure tanks Oil processing & storage equip. Steel mill equip. Telecom towers & equip. Wind turbine towers Power plant structures etc.
    Using
    AutoCAD 2012
    Join Date
    Jan 2007
    Location
    Courtice, Ontario, Canada
    Posts
    749

    Smile

    Quote Originally Posted by guitarguy1685 View Post
    2) I don't know what you mean by "Specify Size of Leg 1(@ base point):
    Just where will be located leg #1?
    Lets keep in mind someone will use your code and it be easy to know if leg #1 is going to be close to base point or on opposed side.

  10. #10
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    Oct 2009
    Posts
    171

    Default

    Registered forum members do not see this ad.

    thanx lee, a few questions

    1) I noticed you used cond instead of if? what is the advantage of cond over if? I thought cond was if there were more than 2 expressions

    2) I noticed you used (prin1) instead of (princ), what's the difference here?

    3) I'm not familiar with using Polar coords, what's the advantage over Cartesian coords?

Similar Threads

  1. UCS Question
    By magic-chef in forum AutoCAD 3D Modelling & Rendering
    Replies: 5
    Last Post: 13th Aug 2008, 04:20 pm
  2. command line up arrow question, and grip edit distance question
    By Rebel in forum AutoCAD Drawing Management & Output
    Replies: 7
    Last Post: 2nd Jun 2008, 03:15 pm
  3. Question
    By primoz in forum Feedback
    Replies: 1
    Last Post: 17th Apr 2006, 01:45 am
  4. a PDF question...
    By StykFacE in forum AutoCAD General
    Replies: 4
    Last Post: 12th Apr 2006, 04:20 pm
  5. Okay okay, another question
    By StykFacE in forum AutoCAD General
    Replies: 12
    Last Post: 11th Apr 2006, 03:43 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