aloy Posted August 19, 2012 Share Posted August 19, 2012 I have a list giving chainages and respective coordinates of a road alignment. I need to prepare a table with four columns for the Chainage, X value, Y Value and Remark. I used to convert these with 'rtos' and put them on columns but has seen some other elegant wayn this forum. But that table does not give the colunms I need. Can someone give a clue?. The list is given below: (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)))) Thanking in advance. Aloy Quote Link to comment Share on other sites More sharing options...
MSasu Posted August 19, 2012 Share Posted August 19, 2012 Please check the advices from this tutorial. Quote Link to comment Share on other sites More sharing options...
aloy Posted August 19, 2012 Author Share Posted August 19, 2012 Thaks Mircea, This appears to be one way. I need to study a bit on Vlisp and then modify the program appropriately. Regards, Aloy Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 19, 2012 Share Posted August 19, 2012 Aloy . This sub-function would help you to reform the list to appended list to become much easier to set the value after converting it to a string to a table . Good luck . (defun AppendList (l / i n lst) (setq i -1) (repeat (length l) (setq lst (cons (list (car (setq n (nth (setq i (1+ i)) l))) (car (cadr n)) (cadr (cadr n)) (caddr (cadr n)) ) lst ) ) ) lst ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 19, 2012 Share Posted August 19, 2012 Or simply: (mapcar '(lambda ( x ) (cons (car x) (cadr x))) l) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 19, 2012 Share Posted August 19, 2012 Or simply: (mapcar '(lambda ( x ) (cons (car x) (cadr x))) l) Certainly . Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 LeeMac, Yes, the lambda fuction did the trick. I was able to make use of the existing routine for polyline coordinates without reinventing the wheel and without drawing the polyline. I could use my list, l. given above. However as you will observe there is a Z coordinate aslo at some places and the function coverted that also where ever Z exist and put it in the fourth colunm. That also shows that the polyline table can be extended to many more columns. Is there a way of shutting off the Z value when generating the list l ?. Thank you for the help. Aloy Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 Tharwat, The function gave an error message. May be it needs a bit of modification to prepare the sub liist. Regards, Aloy Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 Mircea, I could not make use of the tutorial as the polylines are closed ones and the solution looks a bit more comlex than in the case of open polyline given above. Regards, Aloy Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2012 Share Posted August 21, 2012 May be it needs a bit of modification to prepare the sub liist. No. it does not need anything , except to have them in order just add (reverse lst) at the last lst in the sub-function . What was the error message that you have received ? Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 Tharwat, The error message is 'too few arguments'. Regards, Aloy Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2012 Share Posted August 21, 2012 The error message is 'too few arguments'. That's because you did not add argument L to the sub-function . Load my sub-function and load your variable name L (defun AppendList (l / i n lst) (setq i -1) (repeat (length l) (setq lst (cons (list (car (setq n (nth (setq i (1+ i)) l))) (car (cadr n)) (cadr (cadr n)) (caddr (cadr n)) ) lst ) ) ) (reverse lst) ) Then run the function like this . (appendlist l) Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 Sorry Tharwat, It works. Thanks. Aloy Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2012 Share Posted August 21, 2012 Sorry Tharwat,It works. Thanks. Aloy Not a problem Aloy . Now , were you able to write the code to get your works done with it ? If not , post an image showing the last appearance of the table . Tharwat Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2012 Share Posted August 21, 2012 (edited) Here is a draft code try it and let me know if you need any modification . Load your list also within the same file of this code or just post the list of coordinates instead of the variable L for the sub-function AppendList . You may need to wait a few seconds to list all strings inside table cells . Good Luck . (defun c:lst2Table (/ pt TitleAndHeader tbl AppendList len i j lst)(vl-load-com) ;;; Author : Tharwat Al Shoufi ;;; ;;; Date : 21. August. 2012 ;;; (defun TitleAndHeader (acdoc Title ListofHeaders rows pt / cols space hgt inc e) (vl-load-com) (defun *error* (msg) (redraw) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq cols (length ListofHeaders)) (setq space (if (> (vla-get-activespace acdoc) 0) (vla-get-modelspace acdoc) (vla-get-paperspace acdoc))) (setq hgt (if (zerop (cdr (assoc 40 (setq e (entget (tblobjname "STYLE" (getvar 'textstyle))))))) (cdr (assoc 42 e)) (cdr (assoc 40 e)))) (setq tbl (vla-addtable space (vlax-3d-point pt) rows cols (* hgt 2.5) (* hgt 2.5))) (vla-settext tbl 0 0 Title) (vla-setcolumnwidth tbl 0 (* hgt 10.)) (vla-setrowheight tbl 0 (* hgt 1.5)) (setq inc -1) (repeat (length ListofHeaders) (vla-setcolumnwidth tbl (setq inc (1+ inc)) (* hgt 10.)) (vla-settext tbl 1 inc (nth inc ListofHeaders)) (vla-setcellalignment tbl 1 inc acMiddleCenter)) (princ)) (defun AppendList (l / i n) (setq i -1) (repeat (length l) (setq lst (cons (list (car (setq n (nth (setq i (1+ i)) l))) (car (cadr n)) (cadr (cadr n)) (caddr (cadr n))) lst))) lst) (if (and (setq len (length (AppendList l))) (setq pt (getpoint "\n Specify point :"))) (progn (TitleAndHeader (vla-get-activedocument (vlax-get-acad-object)) "\\C3;Coordinates " '("\\C1;Chainage" "\\C1;X" "\\C1;Y" "\\C1;Remarks") (+ 2 len) pt) (setq i 1 j -1) (foreach x (reverse lst) (vla-settext tbl (setq i (1+ i)) (setq j (1+ j)) (if (nth j x) (nth j x) "")) (vla-setcellalignment tbl i j acMiddleCenter) (vla-settext tbl i (setq j (1+ j)) (if (nth j x) (nth j x) "")) (vla-setcellalignment tbl i j acMiddleCenter) (vla-settext tbl i (setq j (1+ j)) (if (nth j x) (nth j x) "")) (vla-setcellalignment tbl i j acMiddleCenter) (vla-settext tbl i (setq j (1+ j)) (if (nth j x) (nth j x) "")) (vla-setcellalignment tbl i j acMiddleCenter) (setq j -1)))) (princ "\n Written by Tharwat Al Shoufi") (princ)) Edited August 21, 2012 by Tharwat Codes updated according to OP needs Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 Hi Tharwat, Here is the drawing file, prepared with the pline Table code from this forum) which I modified. I will try the code you have given later. Regards, Aloy Drawing1.dwg Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2012 Share Posted August 21, 2012 Hi Tharwat,Here is the drawing file, prepared with the pline Table code from this forum) which I modified. I will try the code you have given later. Regards, Aloy Okay , CODES UPDATED to match the one that you have attached Check the code and tell me back . Tharwat Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 Here is the error message with updated code Command: (c:lst2Table) Specify point :; error: no function definition: VLAX-GET-ACAD-OBJECT Aloy Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2012 Share Posted August 21, 2012 Here is the error message with updated codeCommand: (c:lst2Table) Specify point :; error: no function definition: VLAX-GET-ACAD-OBJECT Aloy You must have missed the (vl-load-com) from the code . Don't remove anything from the code , just copy and paste them in a new file in Vlide and load the routine with your list . Or tell me how you run the code ? Quote Link to comment Share on other sites More sharing options...
aloy Posted August 21, 2012 Author Share Posted August 21, 2012 (edited) Tharwat, No, it is there. I load my list, then your code, then enter as I have shown against command prompt. I think you better try it out first with the code and my list. It should return the table as you said. I used your earlier fuction to get a new list for L, I use this list for Table_Data in the Pline table routine after coverting it to text with a lambda function, thereby bypassing the need for polyline vertexes. Perhaps you may need to refine your new code. Regards, Aloy Edited August 21, 2012 by aloy Quote Link to comment Share on other sites More sharing options...
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.