aloy Posted August 17, 2012 Posted August 17, 2012 (edited) I have a routine drawing road alignment which needs relaoding every 100m. due to the line on the text. It is as follows: (setq p1 (cadr (car l))) (setq ch(car (car l))) (setq w (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 Edited August 17, 2012 by aloy Quote
MSasu Posted August 17, 2012 Posted August 17, 2012 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. Quote
aloy Posted August 17, 2012 Author Posted August 17, 2012 Thanks MSasu, Here is the variable I: (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 Quote
MSasu Posted August 18, 2012 Posted August 18, 2012 (edited) 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. [color=blue](setq p1 (cadr (car l))) (setq ch(car (car l))) (setq w [/color] [color=red](foreach pair (cdr l)[/color] [color=red] (setq p2 (cadr pair))[/color] (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 "[color=red]_[/color]line" "_NON" p1 "_NON" p2 "") (if (= (rem ch 20) 0) (command "[color=red]_[/color]line" "_NON" p1xl "_NON" p1xr "")) (if (= (rem ch 100) 0) (command "[color=red]_[/color]text" p1xr 4 (* (-(angle p1xl p1xr) (* 2 pi)) (/ 180 pi)) (substr (rtos ch) 1 6))) ;[color=red]""))[/color] (command "[color=red]_[/color]line" "_NON" p1sl "_NON" p2sl "") (command "[color=red]_[/color]line" "_NON" p1sr "_NON" p2sr "") (setq p1 p2) (setq ch (car [color=red]pair[/color])) ) Edited August 18, 2012 by MSasu Edited the code to add all lines from OP's excerpt Quote
aloy Posted August 18, 2012 Author Posted August 18, 2012 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 Quote
MSasu Posted August 18, 2012 Posted August 18, 2012 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? Quote
aloy Posted August 18, 2012 Author Posted August 18, 2012 Mircea, Yes, it works fine; no errors. Thank you very much for the method. I will study how to use 'Foreach pair'. Regards, Aloy Quote
MSasu Posted August 19, 2012 Posted August 19, 2012 Good to hear that, Aloy. You're entirely welcome! Quote
sheyda Posted August 8, 2014 Posted August 8, 2014 hi every body I have never used codes in civil3d how u run it and how u write it? Quote
sheyda Posted August 8, 2014 Posted August 8, 2014 does any one know how to draw a serpentine curve in civil3d it is common in mountains and hard roads where there isn't enough area to have a simple curve Quote
aloy Posted August 8, 2014 Author Posted August 8, 2014 Dear sheyda,Welcome to cadtutor. It appears you are not familiar with C3D. I suggest you first go to the following link and refer to the 'help' section and read getting started and the rest as much as possible: http://docs.autodesk.com/CIV3D/2013/ENU/index.html?url=filesCTU/GUID-899731B5-0B6A-451E-9CF2-0DCF00FA9B64.htm,topicNumber=CTUd30e6049 If you want to write codes in Autolisp that can run in AutoCAD you can get help from 'Afralisp' Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.