+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    104

    Default Drawing road alignment

    Registered forum members do not see this ad.

    I have a routine drawing road alignment which needs relaoding every 100m. due to the line on the text. It is as follows:
    Code:
     
    (setq p1 (cadr (car l)))
    (setq ch(car (car l)))
    (setq w 8)
    (while 
    (/= l nil)
      (setq l (cdr l))
      (setq p2 (cadr (car 
    l)))
      (setq p1xl (polar p1 (+ (angle p1 p2) (/ pi 2)) 1.5))
      (setq p1xr (polar p1 (- (angle p1 p2) (/ pi 2)) 1.5))
      (setq p1sl 
    (polar p1 (+ (angle p1 p2) (/ pi 2)) w))
      (setq p1sr (polar p1 (- 
    (angle p1 p2) (/ pi 2)) w))
      (setq p2sl (polar p2 (+ (angle p1 p2) (/ 
    pi 2)) w))
      (setq p2sr (polar p2 (- (angle p1 p2) (/ pi 2)) 
    w))
      (command "line" "_NON" p1 "_NON" p2 "")
      (if (= (rem ch 
    20) 0)   (command "line" "_NON" p1xl "_NON" p1xr ""))
      (if (= 
    (rem ch 100) 0) (command "text" p1xr 4 (* (-(angle p1xl p1xr) (* 2 pi)) (/ 180 
    pi)) (substr (rtos ch) 1 6) ""))
      (command "line" "_NON" p1sl "_NON" 
    p2sl "")
      (command "line" "_NON" p1sr "_NON" p2sr "")
      (setq 
    p1 p2)
      (setq ch(car (car l)))
    )
    If that line is commented off the rest works fine. What seems to be the problem. Grateful for any help.
    Aloy
    Last edited by aloy; 17th Aug 2012 at 02:52 pm.

  2. #2
    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,008

    Default

    I believe that you forgot to mark the trouble-maker code line. Which is the one that should be commented for the routine to work properly?

    Also, if you post only an excerpt from your code, is better to add some lines to initiate variables - in above code, one must guess what value store the l variable.
    Regards,
    Mircea

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

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

    Default

    Thanks MSasu,
    Here is the variable I:
    Code:
    (setq l '((0.0 (-108.124 81.3947 0.0)) (20.0 (-88.6807 86.0816 0.0)) (40.0 
    (-69.2377 
    90.7684 0.0)) (60.0 (-49.7946 95.4553 0.0)) (80.0 (-30.3515 
    100.142 0.0)) 
    (100.0 (-10.9085 104.829 0.0)) (120.0 (8.53462 109.516 0.0)) 
    (140.0 (27.9777 
    114.203 0.0)) (160.0 (47.4208 118.89 0.0)) (180.0 (66.8638 
    123.577 0.0)) (200.0 
    (86.3069 128.264 0.0)) (220.0 (105.75 132.951 0.0)) 
    (240.0 (125.193 137.637 
    0.0)) (260.0 (144.636 142.324 0.0)) (280.0 (164.079 
    147.011 0.0)) (300.0 
    (183.522 151.698 0.0)) (320.0 (202.965 156.385 0.0)) 
    (340.0 (222.408 161.072 
    0.0)) (360.0 (241.851 165.759 0.0)) (380.0 (261.295 
    170.446 0.0)) (400.0 
    (280.738 175.133 0.0)) (420.0 (300.181 179.82 0.0)) 
    (440.0 (319.624 184.506 
    0.0)) (460.0 (339.067 189.193 0.0)) (480.0 (358.51 
    193.88 0.0)) (500.0 (377.953 
    198.567 0.0)) (520.0 (397.396 203.254 0.0)) 
    (540.0 (416.839 207.941 0.0)) 
    (560.0 (436.282 212.628 0.0)) (580.0 (455.725 
    217.315 0.0)) (600.0 (475.168 
    222.002 0.0)) (620.0 (494.611 226.688 0.0)) 
    (640.0 (514.054 231.375 0.0)) 
    (660.0 (533.498 236.062 0.0)) (680.0 (552.941 
    240.749 0.0)) (700.0 (572.384 
    245.436 0.0)) (720.0 (591.827 250.123 0.0)) 
    (740.0 (611.27 254.81 0.0)) (760.0 
    (630.713 259.497 0.0)) (780.0 (650.156 
    264.184 0.0)) (800.0 (669.599 268.871 
    0.0)) (820.0 (689.042 273.557 0.0)) 
    (840.0 (708.485 278.244 0.0)) (860.0 
    (727.928 282.931 0.0)) (880.0 (747.371 
    287.618 0.0)) (900.0 (766.814 292.305 
    0.0)) (920.0 (786.257 296.992 0.0)) 
    (940.0 (805.701 301.679 0.0)) (960.0 
    (825.144 306.366 0.0)) (980.0 (844.587 
    311.053 0.0)) (990.275 (854.575 313.46 
    0.0)) (1000.0 (864.029 315.743 0.0)) 
    (1020.0 (883.45 320.518 0.0)) (1040.0 
    (902.809 325.543 0.0)) (1060.0 
    (922.054 330.982 0.0)) (1080.0 (941.127 336.999 
    0.0)) (1086.27 (947.062 
    339.035 0.0)) (1100.0 (959.986 343.655)) (1120.0 (978.7 
    350.715)) (1140.0 
    (997.263 358.162)) (1160.0 (1015.67 365.993)) (1180.0 
    (1033.91 374.203)) 
    (1200.0 (1051.97 382.79)) (1220.0 (1069.85 391.75)) (1240.0 
    (1087.54 
    401.079)) (1260.0 (1105.04 410.772)) (1280.0 (1122.33 420.827)) 
    (1300.0 
    (1139.41 431.238)) (1320.0 (1156.27 442.001)) (1340.0 (1172.9 453.111)) 
    
    (1360.0 (1189.29 464.563)) (1380.0 (1205.45 476.354)) (1400.0 (1221.36 
    
    488.477)) (1420.0 (1237.01 500.927)) (1440.0 (1252.4 513.699)) (1460.0 
    (1267.53 
    526.788)) (1480.0 (1282.38 540.188)) (1500.0 (1296.95 553.893)) 
    (1502.84 
    (1298.99 555.867)) (1520.0 (1311.02 567.884 0.0)) (1540.0 (1324.72 
    582.453 
    0.0)) (1560.0 (1338.05 597.367 0.0)) (1580.0 (1351.12 612.502 0.0)) 
    (1598.84 
    (1363.33 626.861 0.0))))
    You can run it within limits of 0,0 and 1200,1000 in Acad 2011.
    Please load two files and see.
    The trouble maker is the one that starts with (if (= (rem ch 100) 0)........
    Regards,
    Aloy

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

    Default

    The error is from the way you attempt to access the items in list - when list had only one item left you try to retrieve the second one, which is nil, thus the error. I have modified your code to avoid this. I added also some small modifications to it - marked in red. You may want to check the labels, too - not sure what you want to achieve.
    Code:
    (setq p1 (cadr (car l)))
    (setq ch(car (car l)))
    (setq w 8)
    (foreach pair (cdr l)
     (setq p2 (cadr pair))
     (setq p1xl (polar p1 (+ (angle p1 p2) (/ pi 2)) 1.5))
     (setq p1xr (polar p1 (- (angle p1 p2) (/ pi 2)) 1.5))
     (setq p1sl (polar p1 (+ (angle p1 p2) (/ pi 2)) w))
     (setq p1sr (polar p1 (- (angle p1 p2) (/ pi 2)) w))
     (setq p2sl (polar p2 (+ (angle p1 p2) (/ pi 2)) w))
     (setq p2sr (polar p2 (- (angle p1 p2) (/ pi 2)) w))
     (command "_line" "_NON" p1 "_NON" p2 "")
     (if (= (rem ch  20) 0)
      (command "_line" "_NON" p1xl "_NON" p1xr ""))
     (if (= (rem ch 100) 0)
      (command "_text" p1xr 4 (* (-(angle p1xl p1xr) (* 2 pi)) (/ 180 pi)) (substr (rtos ch) 1 6)))   ;""))
     (command "_line" "_NON" p1sl "_NON" p2sl "")
     (command "_line" "_NON" p1sr "_NON" p2sr "")
     (setq p1 p2)
     (setq ch (car pair))
    )
    Last edited by MSasu; 18th Aug 2012 at 07:23 pm. Reason: Edited the code to add all lines from OP's excerpt
    Regards,
    Mircea

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

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

    Default

    Sorry, Mircea
    The code did not work. However commenting off the end in the trouble maker on my code as sggested by you worked. Please try it. What I am trying to do is to draw the centre line and the road with chainages marked at every 20m. Similarly centre median also could be added for a dual carriagway. The list, l, contains the chainages with respective coordinates of a tangent, spiral (clothoid), circular curve and another spiral section at the end.
    Thanks for the help.
    Aloy

  6. #6
    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,008

    Default

    Aloy, when posted my changes to your code, have omitted intentionally the first lines from your excerpt since I didn't touched them. Maybe this had confused you. Sorry. I have added them now in post #4.
    For me if I load the l variable and next the modified code I got it draw a curved path with some labels; did you tried the new code in a new, clean drawing or there are other items in drawing or ther was other code run previously?
    If you get an error, can you please post it here?
    Regards,
    Mircea

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

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

    Default

    Mircea,
    Yes, it works fine; no errors. Thank you very much for the method. I will study how to use 'Foreach pair'.
    Regards,
    Aloy

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

    Default

    Registered forum members do not see this ad.

    Good to hear that, Aloy. You're entirely welcome!
    Regards,
    Mircea

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

Similar Threads

  1. Road alignment drafting problem using lisp routine
    By aloy in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 23rd Jun 2012, 11:47 pm
  2. Solidworks Drawing view alignment
    By vsolo in forum SolidWorks
    Replies: 0
    Last Post: 3rd Oct 2010, 10:24 am
  3. rotate and alignment of drawing to reference
    By studiorat in forum AutoCAD General
    Replies: 6
    Last Post: 10th Mar 2009, 06:21 am
  4. Drawing curves on a road.
    By edortizr6 in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 9th Jan 2008, 12:37 pm
  5. Road Markings
    By MarkCalvert in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 8th Jan 2008, 10:35 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