gghg Posted April 2, 2013 Posted April 2, 2013 I found a lisp routine to make a 2d railroad track but it has some errors in it and I know nothing about writing lisp routines and so I cannot figure out where the errors are or how to fix them. I am using Civil3d 2012. Thanks for any help on this. Here is the code: ;Create a railroad line from a defined centerline drawn as a polyline (defun C:rrtrax ( / curlyr rr-cl rrlyr oldosnap rt lt e ename etype nent tent osdone entstart cntr bulge rtoff ltoff startpt TblLst bss blname lyrcount) (defun myerror (s) ; If an error (such as ESC or invalid selection) occurs ; while this command is active... (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "osmode" oldosnap) (command "_layer" "s" curlyr "") ; Restore saved modes (setq *error* olderr) ; Restore old *error* handler (princ) ) (command "undo" "begin" ) (setq olderr *error* *error* myerror) (setq oldosnap (getvar "osmode")) (if (< oldosnap 16384)(setvar "osmode" (+ 16384 oldosnap))) (setq curlyr (getvar "clayer")) (setq rrlyr "1-RR-TRACK") (setq rrcl "rr-cl") (if (= (tblsearch "layer" rrlyr) nil) (command "_layer" "n" rrlyr "c" "12" rrlyr "s" rrlyr "") (command "_layer" "T" rrlyr "on" rrlyr "s" rrlyr "") ) (if (= (tblsearch "layer" rrcl) nil) (command "_layer" "n" rrcl "") (command "_layer" "T" rrcl "on" rrcl "") ) (defun osline () (setq rt (polar entstart (+ (angle entstart entend) (/ pi 2)) 1.0) lt (polar entstart (- (angle entstart entend) (/ pi 2)) 1.0) ) (doos rt lt) ) ;end osline (defun osarc () (setq rt (polar entstart (angle entstart cntr) 1.0) lt (polar entstart (angle cntr entstart) 1.0) ) (doos rt lt) ) ;end osarc (defun dopoly () (setq osdone nil ename (entnext ename) tent (entget ename) nent (entget (entnext ename)) ) (while (/= "SEQEND" (cdr (assoc 0 nent))) (setq entstart (cdr (assoc 10 tent)) entend (cdr (assoc 10 nent)) bulge (cdr (assoc 42 tent)) ) (if (= bulge 0.0) (drawline) (drawarc) ) (setq ename (entnext ename) tent (entget ename) nent (entget (entnext ename)) ) ) );end dopoly (defun drawline () (if (= osdone nil) (progn (osline) (setq startpt entstart) ) ) ) (defun drawarc () (if (= osdone nil) (progn (osarc) (setq startpt entstart) ) ) ) (defun doos (rt lt) (command "_offset" (/ rr_w 2) e rt "") (command "_change" "l" "" "p" "la" rrlyr "") (setq rtoff (entlast)) (command "_offset" (/ rr_w 2) e lt "") (command "_change" "l" "" "P" "LA" rrlyr "") (setq ltoff (entlast)) (setq osdone t) ) ;end doos ;Make block if needed (defun makebl () (entmake '((0 . "BLOCK") (2 . "rr-tie") (8 . "1-RR-TRACK") (70 . 0) (10 0.333 3.354 0) ) ) (entmake '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (8 . "1-RR-TRACK") (100 . "AcDbPolyline") (90 . 4) (10 0.00 0.00) (10 0.666 0.00) (10 0.666 6.708) (10 0.00 6.708) (70 . 129) ) ) (entmake '((0 . "ENDBLK"))) ) (defun GetFilterTable (Tbl Nme / CurTbl) (setq TblLst nil) (while (setq CurTbl (tblnext Tbl (not CurTbl))) (if (wcmatch (cdr (assoc 2 CurTbl)) Nme) (setq TblLst (cons CurTbl TblLst)) ) ) (reverse TblLst) ) (defun insblock () (setq bss (ssget "_X" '((2 . "rr-tie")))) (ssadd rtoff bss) (ssadd ltoff bss) (if (= (GetFilterTable "BLOCK" "TRACKS-*") nil) (setq blname "TRACKS-1") (progn (setq lyrcount (1+ (length TblLst))) (setq blname (strcat "TRACKS-" (rtos lyrcount))) ) );end if (command "_-block" blname startpt bss "") (command "_-insert" blname startpt 1 "" 0) ) (if (= rr_w nil)(setq rr_w 4.708)) (princ (strcat "\nDraws U.S. Standard <" (rtos rr_w) "'> railroad tracks.")) (setq e (entsel "\nPick a LWPolyline: ")) (while e (setq ename (car e) etype (cdr (assoc 0 (entget ename))) ) (if (or (= etype "POLYLINE")(= etype "LWPOLYLINE")) (progn (if (= etype "LWPOLYLINE") (progn (command "_convertpoly" "h" e "") (setq @poly T) ) ) (dopoly) (setq e2 e) (setq e nil) ) (setq e (entsel "\nYou must pick a POLYLINE - Try again")) ) ) ;Make Tie block if not exist (if (= (tblsearch "block" "rr-tie") nil) (makebl) );end block if (command "_measure" e2 "b" "rr-tie" "y" "3" ) (insblock) (command "_layer" "s" curlyr "") (setvar "osmode" oldosnap) (command "_change" e2 "" "P" "la" "rr-cl" "") (command "_layer" "off" "rr-cl" "") (setq bss (ssget "_x" '((2 . "rr-tie")))) (if (= @poly T) (command "convertpoly" "l" e2 "") ) (command "undo" "end" ) (princ) ) Quote
ReMark Posted April 4, 2013 Posted April 4, 2013 What kinds of errors? Can you be more specific? Quote
David Bethel Posted April 4, 2013 Posted April 4, 2013 Some standard gauge dimensions look to be: Rails: 8' 4-1\2" between inner edge iof the rails 2-3\4" wide at the head 5-1\2" wide at the base 6" high overall Ties: 9" wide x 7" high x 102" long 19.5" on center Are these the dimensions you use? -David Quote
stevesfr Posted April 4, 2013 Posted April 4, 2013 well there is one extra right prens at the very end. HTH Quote
gghg Posted April 4, 2013 Author Posted April 4, 2013 The dimensions work good for me. The main issues I am having with it : 1. When I load it using appload, it immediately is asking for input instead of waiting for me to invoke the command. 2. After I load it, other than when it auto starts the command, I can't use it without using appload again. 3. If I load it to my startup suite, it goes directly into the command as soon as I start a new drawing and again it won't work after that, unless I use appload. Thanks for your help on this. Quote
David Bethel Posted April 4, 2013 Posted April 4, 2013 Sounds like you need to look into the extra parenthesies as Steve suggested. -David Quote
gghg Posted April 4, 2013 Author Posted April 4, 2013 I deleted the last parenthesis as suggested, but that didn't make a difference in the errors. Quote
eldon Posted April 4, 2013 Posted April 4, 2013 Some standard gauge dimensions look to be: Rails: 8' 4-1\2" between inner edge of the rails Are these the dimensions you use? I hope that should read 4' 8½" otherwise there is a budding broad gauge Quote
David Bethel Posted April 4, 2013 Posted April 4, 2013 I'm sorry, but the routine is so poorly written, it would be a wouldn't be wise use of time to to try and decypher it. -David Quote
David Bethel Posted April 4, 2013 Posted April 4, 2013 I hope that should read 4' 8½" otherwise there is a budding broad gauge How can many ways can you say dyslexic ! Good Catch ! -David Quote
SLW210 Posted April 4, 2013 Posted April 4, 2013 It is nice routine, I wish it worked better. I believe I grabbed my copy off of Autodesk community. You might see if you can find the Author and have them give it a look. Quote
gghg Posted April 4, 2013 Author Posted April 4, 2013 (edited) It figures. The one I finally find that does the tracks exactly like I want, has all these errors in it. Just my luck I guess. Thanks for trying to help guys. Edited April 4, 2013 by gghg Removed wrong quote Quote
gghg Posted April 4, 2013 Author Posted April 4, 2013 It is nice routine, I wish it worked better. I believe I grabbed my copy off of Autodesk community. You might see if you can find the Author and have them give it a look. Yeah I agree it works really well if not for the errors. Quote
David Bethel Posted April 4, 2013 Posted April 4, 2013 Here's a brute force method with way too many (command ) references for me. HTH -David RRAIL.LSP Quote
gghg Posted April 4, 2013 Author Posted April 4, 2013 Here's a brute force method with way too many (command ) references for me. HTH -David When I try to select objects, whether its a line or polyline, it says no objects found. Quote
troggarf Posted April 4, 2013 Posted April 4, 2013 Here are two that might be useful or be tweaked. I dont remember where i found these... ~Greg psd.lsp Railway and Waterproofing.LSP Quote
gghg Posted April 10, 2013 Author Posted April 10, 2013 If anyone tries this and figures out how to fix it or if someone could write a lisp that does what this one does but without errors I would be very appreciative. 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.