+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Senior Member
    Computer Details
    DVDM's Computer Details
    Operating System:
    Win 7 Pro 64-bit
    Computer:
    Dell Precision T5400
    CPU:
    2.5Ghz Xeon Quad core
    RAM:
    8 Gb
    Graphics:
    NVIDIA Quadro FX 570
    Primary Storage:
    80Gb 10K rpm
    Monitor:
    Samsung SyncMaster 2253BW
    Using
    AutoCAD 2010
    Join Date
    Sep 2008
    Posts
    111

    Default Some help tidying up LISP

    Registered forum members do not see this ad.

    Hi all,

    I've recently been asked to fix up some of our lisp routines that have been in use at my work for the past 10+ years. Problem is, my lisp knowledge is fairly limited, and while I've been able to touch up quite a few routines by trying to make sense of the code along with some trail and error, I've now come across a routine that no amount of tinkering on my behalf can fix.

    It's a routine that creates a material list by asking the user for the number of columns (default 1), and number of rows (default 20), then constructs a table consisting of a header block (matlhd), a material disciption line block(matlitem), and a total mass block (matltot).

    The problem occurs when you want to create a single line material list, it returns an error because of the way the table is constructed using an array. An array of 1 isn't an array obviously. That leaves you with an incomplete table without the total mass block.

    I need to find a way to bypass the section of code where it creates an array for the rows when the user wants just one row, but I'm now lost as to how. If I remove this code, it actually works perfect for a 1 row table, but no longer works for multiline tables.


    It has to be simple for someone with some more in depth lisp knowledge, so I thought I'd try my luck over here, as this forum has helped me on many previous occasions.

    This is the code: (it's a 12 y/o file, and unfortunately there are no credits in the file)

    Code:
     
    (apply '(lambda (/ b c d dx dy cmd att lay col row pt1 ptx pty pt2 sel)
    (princ "\nInsert Material List")
    (setq cmd (getvar "cmdecho"))
    (setq att (getvar "attdia"))
    (setvar "cmdecho" 0)
    (setvar "attdia" 0)
    (setq lay (getvar "clayer"))
    (setvar "clayer" "0")
    (setq b (getvar "dimscale"))
    (setq c (getvar "tilemode"))
    (if (= c 1 )(setq d b)(setq d 1))
    (setq col (getint "\nNumber of columns<1>: "))
    (if (null col)(setq col 1))
    (setq row (getint "\nNumber of rows<20>: "))
    (if (null row)(setq row 20))
    (setq pt1 (getpoint "\nInsertion point..."))
    (setq ptx (car pt1))
    (setq pty (cadr pt1))
    (setq dx (* d -200))
    (setq dy (* d -7))
    (setq pt2 (list (+ ptx dx)(+ pty dy)))
    (command "insert" "matlhd" pt1 d d "0")
    (setq sel (ssget "L"))
    (if (/= col 1)
    (command "array" sel "" "r" 1 col dx)
    )
    (command "insert" "matlitem" pt2 d d "0")
    (setq sel (ssget "L"))
     
    ;The next 4 lines I want to bypass when number of rows is 1
     
    (if (= col 1)
    (command "array" sel "" "r" row 1 dy)
    (command "array" sel "" "r" row col dy dx)
    )
    (setq pt3 (list ptx (+ pty (* d (* -7 (+ 1 row))))))
    (command "insert" "matltot" pt3 d d "0")
    (setvar "cmdecho" cmd)
    (setvar "clayer" lay)
    (setvar "attdia" att)
    (princ)
    )
    '()
    )
    Thanks for reading

  2. #2
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    Try this:

    Code:
    ;The next 4 lines I want to bypass when number of rows is 1
    (if (/= row 1)
       (if (= col 1)
          (command "array" sel "" "r" row 1 dy)
          (command "array" sel "" "r" row col dy dx)
       )
    )

  3. #3
    Senior Member
    Computer Details
    DVDM's Computer Details
    Operating System:
    Win 7 Pro 64-bit
    Computer:
    Dell Precision T5400
    CPU:
    2.5Ghz Xeon Quad core
    RAM:
    8 Gb
    Graphics:
    NVIDIA Quadro FX 570
    Primary Storage:
    80Gb 10K rpm
    Monitor:
    Samsung SyncMaster 2253BW
    Using
    AutoCAD 2010
    Join Date
    Sep 2008
    Posts
    111

    Default

    Thanks Carl, that works great.
    I had previously made several attempts to insert a 'if (/= row 1)' line somewhere in the code, but I guess I got the placement wrong.

  4. #4
    Senior Member
    Computer Details
    DVDM's Computer Details
    Operating System:
    Win 7 Pro 64-bit
    Computer:
    Dell Precision T5400
    CPU:
    2.5Ghz Xeon Quad core
    RAM:
    8 Gb
    Graphics:
    NVIDIA Quadro FX 570
    Primary Storage:
    80Gb 10K rpm
    Monitor:
    Samsung SyncMaster 2253BW
    Using
    AutoCAD 2010
    Join Date
    Sep 2008
    Posts
    111

    Default

    Registered forum members do not see this ad.

    *duplicate entry removed*

Similar Threads

  1. Running a lisp in another lisp??
    By neekcotrack in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 26th Aug 2008, 04:02 am
  2. Lisp Call Lisp Problem
    By neekcotrack in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 23rd Aug 2008, 12:56 pm
  3. problem, trying to running a list of lisp from within a lisp
    By twind2000 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 20th Aug 2007, 04:27 pm
  4. calling another lisp from within my lisp
    By thalon in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 22nd Feb 2006, 09: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