woodman78 Posted February 5, 2013 Share Posted February 5, 2013 Hi, I need to draw cross sections in CAD from a list in a text file. I am trying to automate the process. So far this is what I have. (defun c:Clon( / fn fp lst l p1 p2) (command "_.-layer" "_N" "CCC_LAYOUT_Cross_Sections_Datum" "_M" "CCC_LAYOUT_Cross_Sections_Datum" "_C" "1" "CCC_LAYOUT_Cross_Sections_Datum" "" ) (command "_.pline" "-10,0" "12,0" "") (command "_.-layer" "_N" "CCC_LAYOUT_Cross_Sections_Outline" "_M" "CCC_LAYOUT_Cross_Sections_Outline" "_C" "150" "CCC_LAYOUT_Cross_Sections_Outline" "" ) (setq p1 (strcat "-12" "," "10")) (setq p2(strcat "15" "," "-4")) (command "rectang" p1 p2 "") (setq insertpoint (strcat "-11" "," "-3")) (command "text" insertpoint 0.5 0 (strcat (princ textinput))) (setq fn (getfiled "Select ASCII file" "" "txt" 4)) (setq fp (open fn "r") lst '()) (while (setq l (read-line fp)) (setq lst (cons l lst)) ) (close fp) (setq lst (reverse lst)) (setvar "osmode" 0) (command "._pline" "") (foreach item lst (command item) (command "") ) ) (princ) ) 1020.txt I am trying to get the lisp to plot the points from the file as a polyline. But what I really want to do is to have more than one cross section in the file separated by a blank line and so that the program will run once and then move the cross section up on the drawing and complete the second and so on. Right now the lisp will read the file and launch the pline command but it is not recognizing the coords. What have I left out of the pline command? Thanks. Woodman78 Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 5, 2013 Share Posted February 5, 2013 An easier appoach will be to build a script from that file: _PLINE -5.789,2.196 -4.621,2.176 -4.333,2.202 -2.048,2.159 -0.904,2.148 0,2.113 0.423,2.117 1.954,2.077 3.916,2 ;end of script Quote Link to comment Share on other sites More sharing options...
woodman78 Posted February 5, 2013 Author Share Posted February 5, 2013 Ok. Can I run the script from a lisp? And can I run multiple scripts from the one text file? Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 5, 2013 Share Posted February 5, 2013 The script can be executed with SCRIPT command. And, yes, you can include more commands into one script file: _LINE 1,1 2,2 _CIRCLE 0,0 5 ;end of script Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 5, 2013 Share Posted February 5, 2013 I did some corrections to your code. A point can be supplied easily as a list, not need to build a string for it; this will simplify calculations also (if required). Please pay attention to the line that attempt to add a label - the textinput variable isn't defined. Another comment, a good programming practice is to restore the environment if you modify it (the OSMODE system variable). (defun c:Clon( / fn fp lst l p1 p2 oldOSM ) (command "_.-layer" "_N" "CCC_LAYOUT_Cross_Sections_Datum" "_M" "CCC_LAYOUT_Cross_Sections_Datum" "_C" "1" "CCC_LAYOUT_Cross_Sections_Datum" "" ) (command "_.pline" "-10,0" "12,0" "") (command "_.-layer" "_N" "CCC_LAYOUT_Cross_Sections_Outline" "_M" "CCC_LAYOUT_Cross_Sections_Outline" "_C" "150" "CCC_LAYOUT_Cross_Sections_Outline" "" ) (setq p1 [color=red]'(-12 10)[/color]) (setq p2 [color=red]'(15 -4)[/color]) (command "rectang" p1 p2) [color=red];"")[/color] (setq insertpoint [color=red]'(-11 -3)[/color]) ;(command "text" insertpoint 0.5 0 (strcat [s][color=red](princ[/color][/s] textinput[s][color=red])[/color][/s])) (setq fn (getfiled "Select ASCII file" "" "txt" 4)) (setq fp (open fn "r") lst '()) (while (setq l (read-line fp)) (setq lst (cons l lst)) ) (close fp) (setq lst (reverse lst)) [color=red](setq oldOSM (getvar "osmode"))[/color] (setvar "osmode" 0) (command "._pline" "") (foreach item lst [color=red] (if (/= item "")[/color] (command item) [color=red] (command "" "._pline") ) )[/color] (command "") [color=red][/color] [color=red] (setvar "osmode" oldOSM)[/color] (princ) ) Example of data file: -5.789,2.196 -4.621,2.176 -4.333,2.202 1,2 2,4 4,11 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 6, 2013 Share Posted February 6, 2013 A better approach so that not only do you get a pline you get the boxes as well. Think of a cross section as 3 parts Chainage offset and level. Read a line say a CSV for the 3 values. When the chainage value is different then thats the end of that crossection, you can then draw vertical lines and have two rows of text Offset and RL with a surface line drawn last. The only other question required is the grid spacing and how many rows and columns. Its a bit complicated but achieveable the one thing I would do differently woodman is I would use a series of defuns to do certain tasks this way you can write the code as a simpler series of steps, eg draw pline defun last. Adding more defuns rather than debugging one big program Just had a look at something similar around 200+ lines of code, pretty sure I had a manual cross section lisp will try to find this stuff was done in 1991. -> defuns get row column spacing etc this would be a double loop row-column open file while loop EOF read line, get ch off rl -> draw vertical line & text add pt to pline if chainge is different -> draw pline, -> draw horizontal linework, -> change start pt for line work & text continue while end row column double loop 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.