I have a lisp routine that draws storm pipes (solid lines at the edges of the pipe; the centerline is a dashed pline the width of the pipe). Now I would like it to automatically label the pipe. Pipe diameter (in inches) and the length of the pipe (in feet). The attached .png is an example. I know Civil 3d will do this but I am looking for a strictly cad solution.
Any help would be greatly appreciated.
@nsorem wrote:I have a lisp routine that draws storm pipes .... Now I would like it to automatically label the pipe. Pipe diameter (in inches) and the length of the pipe (in feet). The attached .png is an example. ....
Something like this, perhaps. I left some of your original code alone, and did some things a little differently for various reasons that you may be able to figure out [particularly the Lines along the edges by Offset rather than by calculating all those points, and consolidating multiple (setq) and (command) functions]. Minimally tested, and with no error handling, etc.
(defun C:PIPE (/ CE OTM OSM pea PNT1 PNT2 Din Dft HD clay A ET obj) (setq CE (getvar "CMDECHO") OTM (getvar "ORTHOMODE") OSM (getvar "osmode") pea (getvar 'peditaccept) PNT1 (getpoint "\nPick Start of Pipe: ") PNT2 (getpoint PNT1 "\nPick End of Pipe: ") Din (getreal "\nEnter Pipe Diameter in Inches: ") ; User input IE 24", 30", 42" SO ON. ; Using (getreal) instead of (getdist), because (getdist) ; allows picking points on-screen; if drawing unit = 1 ; foot, that would return value in feet, not inches. Dft (/ Din 12) HD (/ Dft 2) clay (getvar 'clayer) ); end setq (setvar "CMDECHO" 0) (setvar "ORTHOMODE" 0) (setvar "OSMODE" 0) (setvar 'peditaccept 1); avoid possible Pedit question whether to convert Line to Polyline (while Pnt2 (setvar 'clayer "YourStormPipeLayer") ; <------ edit (command ".line" PNT1 PNT2 "") (setq A (angle PNT1 PNT2) ET (entlast) obj (vlax-ename->vla-object ET) ); end setq (vla-offset obj HD) (vla-offset obj (- HD)) (command ".chprop" ET "" "LT" "HIDDENX2" "" "" ; change linetype to suit ".Pedit" ET "W" Dft "" "_.layer" "_set" "YourTextLabelLayer" "" ; <------ edit "_.text" "_style" "YourTextStyle" ; <------ edit "_c" ; spelling out "_center" is interpreted as Osnap call (polar (mapcar '/ (mapcar '+ PNT1 PNT2) '(2 2 2)); midpoint of mid-line (+ A (if (< (/ pi 2) A (* pi 1.5)) (* pi 1.5) (/ pi 2))) (+ HD 0.5); distance from edge line to Text base-line <------ edit ); end polar 1 ; height -- omit if Style is fixed-height <------ edit (* (/ (if (< (/ pi 2) A (* pi 1.5)) (+ A pi) A) pi) 180); angle (strcat (rtos (distance PNT1 PNT2) 2 0); length rounded to nearest whole foot "' - " (rtos Din 2 0); diameter in inches "\" STM" ); end strcat & Text ); end command (setq PNT1 PNT2 PNT2 (getpoint PNT1 "\nNext Point: <Return or Enter to Quit>: ") ); end setq ); end while (setvar "CMDECHO" CE) (setvar "ORTHOMODE" OTM) (setvar "OSMODE" OSM) (setvar 'peditaccept pea) (setvar 'clayer clay) (redraw) ); end pipe.lsp
The question remains whether in an end-to-end series it would be better to make one Polyline, so that the bends in the edges would automatically be cleaned up. But that would require doing the whole route first, and then going back and labeling all the segments, which would be more complicated but doable.
@nsorem wrote:I get to the point where it asks for pipe diameter, I type in 24, and it quits. Any suggestions?
It works for me. Is there an error message?
If it doesn't get as far as the next thing that the User should see happen [drawing the Line from PNT1 to PNT2], does it get as far as setting the proper Layer for that? Have you put in a Layer name that exists in the drawing? If you have but it doesn't set the Layer, try changing the top line to add the red right parenthesis and semicolon [which you'll remove later when it's figured out]:
(defun C:PIPE ();/ CE OTM....[etc.]
That will temporarily leave variables un-localized, so they'll be readable after the routine is run. Then run it again, and type each of those variable names, from where it quits up to where it should draw that Line, with a preceding exclamation point, to see how many of them were set:
!Din
!Dft
!HD
!clay
Each of those should return an appropriate value. The first one that doesn't [presumably returning nil] should be the clue to where something's wrong.
Kent will be beat me to it 🙂
Glad to help
Thanks for the beer, buddy
Cheers 🙂
@Hallex wrote:Kent will be beat me to it 🙂 [with PIPE.txt attached]
That's good for incorporating some User choices mine didn't include [assuming the OP wants the User to have all those choices, but I'll leave that to them]. But there are some things I noticed:
The Text insertion point can be inside the edge Line if the height is small enough in relation to the pipe diameter [try a text height of 1 foot and a pipe diameter of 48"].
There is nothing to make the text Style that has been created current, so it still uses the Style that's current when you start the routine, and the Style definition within the routine is wasted.
There's an extraneous Enter at the end of the Chprop command that changes the Linetype and Scale of the mid-line Line, which causes an Unknown command "PIPE" message at every step.
And there are a variety of other things that can be cleaned up: extraneous (append) and (progn) functions; unused variables; functions and variables that are used only once, so there's no point in the overhead of defining them [simply use the function-definition's content or the variable's definition/calculation at the one place where the function or variable would be used], things that seem more complicated than they need to be, etc.
Attached are PIPErev-com.lsp [revised with commentaries on what I changed and why, all preceded by ;;;;] and PIPErev.lsp [the same revised routine, but with the commentaries and associated code removed, except for the suggestions that certain things be calculated, and not left to the User].
Need help again.
Would it be possible to revise the lisp routine so that the user can specify the type of pipe needed? Instead of it automatically labeling the pipe as STM I want to be able to choose whether the pipe is STM or SAN or WTR etc. Also, I don't need it to label the length of the pipe.
Thanks.
@nsorem wrote:.... Would it be possible to revise the lisp routine so that the user can specify the type of pipe needed? Instead of it automatically labeling the pipe as STM I want to be able to choose whether the pipe is STM or SAN or WTR etc. Also, I don't need it to label the length of the pipe. ....
Untested, but I hope this will do that.
first, i'm sorry for my english.
i have to change this lisp to metric system. hw can i do that? can you help me please?