+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
  1. #1
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    104

    Default Road alignment drafting problem using lisp routine

    Registered forum members do not see this ad.

    I have a list given below:
    (setq l '((0.0 (298.546 228.499 0.0)) (20.0 (316.873 236.508 0.0)) (40.0 (335.2 244.516
    0.0)) (60.0 (353.526 252.524 0.0)) (76.7565 (368.881 259.234 0.0)) (80.0
    (371.853 260.533 0.0)) (100.0 (390.094 268.732 0.0)) (120.0 (407.932 277.769
    0.0)) (126.756 (413.792 281.131 0.0)) (140.0 (425.028 288.076)) (140.0 (441.616
    299.307)) (160.0 (457.594 311.333)) (180.0 (472.95 324.142)) (200.0 (487.648
    337.704)) (220.0 (501.649 351.982)) (240.0 (514.919 366.943)) (260.0 (527.424
    382.54)) (280.0 (539.135 398.759)) (300.0 (550.02 415.535)) (320.0 (560.053
    432.834)) (320.916 (560.492 433.63)) (340.0 (568.86 450.673 0.0)) (360.0
    (576.592 469.116 0.0)) (370.916 (580.594 479.272 0.0))))
    When it is loaded and run with the code below the line segents drawn are not as expected. What seems to be the problem

    (setq p1(cadr (car l)))
    (while (/= l nil)
    (setq l(cdr l))
    (setq p2(cadr (car l)))
    (command "line" p1 p2 "")
    (setq p1 p2)
    )
    Last edited by aloy; 24th Jun 2012 at 05:34 am. Reason: As advised

  2. #2
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x86
    CPU:
    Pentium(R) Dual-Core CPU E5500 @ 2.80GHz
    RAM:
    4 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    ThinkVision 22"
    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
    9,134

    Default

    aloy,

    Please read the CODE POSTING GUIDELINES and edit your post.

    I moved this thread to the AutoLISP, Visual LISP & DCL forum.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  3. #3
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,007

    Default

    I suspect that is an interference with current Osnap mode – please adjust you code as below and see if help:
    Code:
     (command "_line" "_NON" p1 "_NON" p2 "")
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

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

    Default

    Welcome to CADTutor

    Object Snap may be affecting your use of the Line command, causing points to jump to the nearest osnap point. To avoid this, use "_non" to ignore Object Snap when supplying points.

    Here are some alternatives to your code:

    Code:
    (while (cadr l)
        (command "_.line" "_non" (cadar l) "_non" (cadadr l) "")
        (setq l (cdr l))
    )
    Code:
    (mapcar '(lambda ( a b ) (command "_.line" "_non" (cadr a) "_non" (cadr b) "")) l (cdr l))
    Edit: Added "" to Line Command - thanks pBe!
    Last edited by Lee Mac; 23rd Jun 2012 at 12:47 pm.
    Lee Mac Programming

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

    Just another Swamper

  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,926

    Default

    I'd tried to clean up your code a bit:

    Code:
    (defun c:test (/ l p1 p2)
    
    (setq l '(
      (0.0 (298.546 228.499 0.0)) 
      (20.0 (316.873 236.508 0.0)) 
      (40.0 (335.2 244.516 0.0)) 
      (60.0 (353.526 252.524 0.0)) 
      (76.7565 (368.881 259.234 0.0)) 
      (80.0 (371.853 260.533 0.0)) 
      (100.0 (390.094 268.732 0.0)) 
      (120.0 (407.932 277.769 0.0)) 
      (126.756 (413.792 281.131 0.0)) 
      (140.0 (425.028 288.076))   
      (140.0 (441.616 299.307) ) 
      (160.0 (457.594 311.333)) 
      (180.0 (472.95 324.142)) 
      (200.0 (487.648 337.704)) 
      (220.0 (501.649 351.982)) 
      (240.0 (514.919 366.943)) 
      (260.0 (527.424 382.54)) 
      (280.0 (539.135 398.759)) 
      (300.0 (550.02 415.535)) 
      (320.0 (560.053 432.834)) 
      (320.916 (560.492 433.63)) 
      (340.0 (568.86 450.673 0.0)) 
      (360.0 (576.592 469.116 0.0)) 
      (370.916 (580.594 479.272 0.0))))
    
      (while (> (length l) 1)
             (setq p1 (cadr (car l)))
             (setq p2 (cadr (cadr l))) 
             (command "line" p1 p2 "") 
             (setq l (cdr l)))
    (prin1))
    See if that helps. -David
    R12 (Dos) - A2K

  6. #6
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    104

    Default

    Quote Originally Posted by SLW210 View Post
    aloy,

    Please read the CODE POSTING GUIDELINES and edit your post.

    I moved this thread to the AutoLISP, Visual LISP & DCL forum.

    Thanks for the advice. The codes used to generate the horizonal alignment which includes straight sections, spirals and circular curves which was developed over 20 year ago using AutoCAD v. 1.2 is also mine. These programs were used to generate verticle alignments, long sections, cross sections and earthworks calculations. Some highways were built using them. Since I moved to other areas of civil engineering I did not have the opportunity to further develop them. My attempt now is to develop programmes to design the geomatric elements according to Uk's TD 9, TD 22 etc. interactively on a topo plan in Autocad. In this connection, I have already received help in this forum and I am gratful for that.
    Aloy

  7. #7
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    104

    Default

    Hi David,
    Thaks for the reply. However it did not work. From the replies in this forum, I realised that the problem is due to the object snap being on during the exection. My code given in the posting works when the object snap is off.
    Redards,
    Aloysius. H

  8. #8
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    104

    Default

    Hi Lee Mac,
    Thanks for the reply. However the code did not work. I remember using lambda fuctions more than twenty years ago when I was developing a routine for earthworks calculations. It was very useful and there were no internet then. I had to do reseach work in British council Library to 'discover' them.
    My code in the posting works when object snap is off.
    Regards,
    Aloysius. H

  9. #9
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    104

    Default

    Hi Mircea,
    Thanks for the help. It worked when using the code sugested by you. It also works with the code in my posting when object snap is off.
    Regards,
    Aloysius.H

  10. #10
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,007

    Default

    Registered forum members do not see this ad.

    Inputting "_NON" before supplying points is in fact overriding the current Osnap settings with None mode; is equivalent with setting Osnap to Off, but you don't need to pay attention to manage it manually (set Off before running the routine, restoring it later).
    Alternatively, when the code is more complex, to don’t have to pay attention to add the "_NON" each time is required, you can retain current Osnap value (system variable OSMODE), disable it, run your code and restore it with the previous value before exit.
    Code:
    (setq myOsm (getvar "OSMODE"))
    (setvar "OSMODE" 0)
    ;;; code
    (setvar "OSMODE" myOsm)
    An advanced solution that isn't affected by current Osnap is to directly add or modify the entities into drawing's database - please check the ENT* functions family.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

Similar Threads

  1. road x-section lisp problem
    By cadamrao in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 1st Sep 2012, 09:29 am
  2. Looking to a lisp routine to solve my problem...
    By javid in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 2nd Sep 2010, 01:57 pm
  3. lisp routine problem
    By rab in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 30th Jan 2006, 10:24 am
  4. DText alignment routine
    By Fantomas in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 28th Jan 2005, 07:12 pm
  5. Problem with rotation in lisp routine.
    By Cadastrophic in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 3rd Nov 2004, 08:14 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