Subidoooo Posted December 28, 2022 Posted December 28, 2022 Hi guys i need help to close the 2 green polylines. the goal is to draw a section of a stormwater drain created in my lisp file here is my code that i have so far: (defun c:Test (/ dw dd dt de ds nl sl ip np np1 np2 p1 p2 p3 p3_1 p4 p4_1 p5 p6 pl pl2) (setq OldLayer (getvar "clayer")); Gets Old Layer (setq OldOffsetValue (getvar "offsetdist")); Gets Old Offset distance ; Get information from user (setq dw (getreal "\nInsert Base Width: ")) (setq dd (getreal "\nInsert Drain Depth: ")) (setq dt (getreal "\nInsert Drain Thickness: ")) (setq de (getreal "\nInsert Drain Side Extension Length: ")) (setq ds (getreal "\nInsert Daylight Slope 1: ")) (setq nl (getreal "\nInsert NGL Length ")) ; Calculations (setq sl (* ds dd)) ; Calculates the Drain Slope (setq ip (getpoint "\nChoose Insertion Point : ")) (setq np (polar ip (dtr 90.0) dd)) (setq np1 (polar np (dtr 180.0) (/ dw 2))) (setq np2 (polar np (dtr 0.0) (/ dw 2))) (setq p1 (polar ip (dtr 180.0) (/ dw 2))) (setq p2 (polar ip (dtr 0.0) (/ dw 2))) (setq p3 (polar np1 (dtr 180.0) sl )) (setq p3_1 (polar p3 (dtr 180.0) de )) (setq p4 (polar np2 (dtr 0.0) sl )) (setq p4_1 (polar p4 (dtr 0.0) de )) (setq p5 (polar p4 (dtr 0.0) nl )) (setq p6 (polar p3 (dtr 180.0) nl )) ; Draw Stormwater Drain (setvar "clayer" ".CONCRETE") (setvar "Offsetdist" dt) (command "Pline" p3_1 p3 p1 p2 p4 p4_1 "") (while (= (logand (getvar "cmdactive") 1) 1) (command pause)) (setq pl (entlast)); Gets last entity (while (= (logand (getvar "cmdactive") 1) 1) (command pause)) (command "offset" dt pl ip "") ;offset (while (= (logand (getvar "cmdactive") 1) 1) (command pause)) ; STUCK HER TO CLOSE POLYLINE BOUNDARY (setvar "clayer" ".NGL");Change Layer to .NGL (command "PLine" p6 p3_1 "") (setvar "clayer" ".NGL DASHED");Change Layer to .NGL dashed (command "Pline" p3 p4 "") (setvar "clayer" ".NGL");Change Layer to .NGL (command "Pline" p4_1 p5 "") (setvar "clayer" OldLayer) (princ) ) Quote
mhupp Posted December 28, 2022 Posted December 28, 2022 I would make a dynamic block that have measurements you want defined. Quote
Steven P Posted December 28, 2022 Posted December 28, 2022 I am sure there is a more efficient way to work out the geometry - can think about that another time (I am on my holidays and not doing any thinking about CAD, definitely not thinking about forums and stuff). The lines are offset so set P2 to be the offset line (use entlast if you want), (assoc 10) this to give the first point and then an (assoc 10 (reverse P2)) to get the last point (will need to check the syntax) P3_1 corresponds tot he first point, P4_1 to the last point, you shiyklkd be able to make a line at ewach end - name them and use the names, P1m, P2, P3? and P4? to join polyline Just a thought - or go dynamic block as above Quote
Steven P Posted December 28, 2022 Posted December 28, 2022 (edited) And try this as an example to join the ends together. Many ways to do this. Also added a check that the layer .concrete exists else make it - you can modify that line to suit what you want but it is useful to have when changing layers just in case (copy and repeat lower down the code?), also moved setting the variable offsetdist and resetting it closer together in case of error it is more likely to be as it was - just me being picky that's all and since i am on holiday I am not looking at more unless I get bored, though I think there is a better way to work out the points, perhaps using mapcar instead of angles (defun c:Test (/ dw dd dt de ds nl sl ip np np1 np2 p1 p2 p3 p3_1 p4 p4_1 p5 p6 pl pl2) (setq OldLayer (getvar "clayer")); Gets Old Layer (setq OldOffsetValue (getvar "offsetdist")); Gets Old Offset distance ; Get information from user (setq dw (getreal "\nInsert Base Width: ")) (setq dd (getreal "\nInsert Drain Depth: ")) (setq dt (getreal "\nInsert Drain Thickness: ")) (setq de (getreal "\nInsert Drain Side Extension Length: ")) (setq ds (getreal "\nInsert Daylight Slope 1: ")) (setq nl (getreal "\nInsert NGL Length ")) (setq ip (getpoint "\nChoose Insertion Point : ")) ; Calculations (setq sl (* ds dd)) ; Calculates the Drain Slope (setq np (polar ip (dtr 90.0) dd)) (setq np1 (polar np (dtr 180.0) (/ dw 2))) (setq np2 (polar np (dtr 0.0) (/ dw 2))) (setq p1 (polar ip (dtr 180.0) (/ dw 2))) (setq p2 (polar ip (dtr 0.0) (/ dw 2))) (setq p3 (polar np1 (dtr 180.0) sl )) (setq p3_1 (polar p3 (dtr 180.0) de )) (setq p4 (polar np2 (dtr 0.0) sl )) (setq p4_1 (polar p4 (dtr 0.0) de )) (setq p5 (polar p4 (dtr 0.0) nl )) (setq p6 (polar p3 (dtr 180.0) nl )) ; Draw Stormwater Drain (if (tblsearch "layer" ".CONCRETE") ;; check if layer exisats.. copy to below.... () (command "-layer" "New" ".CONCRETE" "") ) (setvar "clayer" ".CONCRETE") (command "Pline" p3_1 p3 p1 p2 p4 p4_1 "") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (setq pl (entlast)); Gets last entity (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (setvar "Offsetdist" dt) (command "offset" dt pl ip "") ;offset (setvar "Offsetdist" OldOffsetValue) ; reset offset dist (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) ; end while (setq pn (entlast)) (command "line" (cdr (assoc 10 (entget pl))) (cdr (assoc 10 (entget pn))) "") (setq panda (entlast)) (command "line" (cdr (assoc 10 (reverse (entget pl)))) (cdr (assoc 10 (reverse (entget pn)))) "") (setq pendb (entlast)) (command "join" pl panda pendb pn "") (setvar "clayer" ".NGL") ;Change Layer to .NGL (command "PLine" p6 p3_1 "") (setvar "clayer" ".NGL DASHED");Change Layer to .NGL dashed (command "Pline" p3 p4 "") (setvar "clayer" ".NGL");Change Layer to .NGL (command "Pline" p4_1 p5 "") (setvar "clayer" OldLayer) ; reset layer (princ) ) Just because I mentioned it.... mapcar, my favourite thing this week.... ; Calculations (setq sl (* ds dd)) ; Calculates the Drain Slope (setq np1 (mapcar '+ ip (list (/ dw -2) dd))) (setq np2 (mapcar '+ ip (list (/ dw 2) dd))) (setq p1 (mapcar '- ip (list (/ dw 2) 0))) (setq p2 (mapcar '+ ip (list (/ dw 2) 0))) (setq p3 (mapcar '- np1 (list sl 0))) (setq p3_1 (mapcar '- p3 (list de 0))) (setq p4 (mapcar '+ np2 (list sl 0))) (setq p4_1 (mapcar '+ p4 (list de 0))) (setq p5 (mapcar '+ p4 (list nl 0))) (setq p6 (mapcar '- p3 (list nl 0))) Edited December 29, 2022 by Steven P Quote
BIGAL Posted December 29, 2022 Posted December 29, 2022 (edited) ; Get information from user Subidoooo or Pteven P Your welcome to use Multi getvals.lsp can set some default values also. Just a thought is it necessary to do offset maybe work out the other side points and make 1 pline. Because its a continuous shape each pt could be say ptx using set and read can do a (set (strcat "pt" "rtos (setq x (1+ x)) 2 0)) value will find example if you want. Multi GETVALS.lsp Edited December 29, 2022 by BIGAL 1 Quote
Subidoooo Posted December 29, 2022 Author Posted December 29, 2022 11 hours ago, Steven P said: And try this as an example to join the ends together. Many ways to do this. Also added a check that the layer .concrete exists else make it - you can modify that line to suit what you want but it is useful to have when changing layers just in case (copy and repeat lower down the code?), also moved setting the variable offsetdist and resetting it closer together in case of error it is more likely to be as it was - just me being picky that's all and since i am on holiday I am not looking at more unless I get bored, though I think there is a better way to work out the points, perhaps using mapcar instead of angles (defun c:Test (/ dw dd dt de ds nl sl ip np np1 np2 p1 p2 p3 p3_1 p4 p4_1 p5 p6 pl pl2) (setq OldLayer (getvar "clayer")); Gets Old Layer (setq OldOffsetValue (getvar "offsetdist")); Gets Old Offset distance ; Get information from user (setq dw (getreal "\nInsert Base Width: ")) (setq dd (getreal "\nInsert Drain Depth: ")) (setq dt (getreal "\nInsert Drain Thickness: ")) (setq de (getreal "\nInsert Drain Side Extension Length: ")) (setq ds (getreal "\nInsert Daylight Slope 1: ")) (setq nl (getreal "\nInsert NGL Length ")) (setq ip (getpoint "\nChoose Insertion Point : ")) ; Calculations (setq sl (* ds dd)) ; Calculates the Drain Slope (setq np (polar ip (dtr 90.0) dd)) (setq np1 (polar np (dtr 180.0) (/ dw 2))) (setq np2 (polar np (dtr 0.0) (/ dw 2))) (setq p1 (polar ip (dtr 180.0) (/ dw 2))) (setq p2 (polar ip (dtr 0.0) (/ dw 2))) (setq p3 (polar np1 (dtr 180.0) sl )) (setq p3_1 (polar p3 (dtr 180.0) de )) (setq p4 (polar np2 (dtr 0.0) sl )) (setq p4_1 (polar p4 (dtr 0.0) de )) (setq p5 (polar p4 (dtr 0.0) nl )) (setq p6 (polar p3 (dtr 180.0) nl )) ; Draw Stormwater Drain (if (tblsearch "layer" ".CONCRETE") ;; check if layer exisats.. copy to below.... () (command "-layer" "New" ".CONCRETE") ) (setvar "clayer" ".CONCRETE") (command "Pline" p3_1 p3 p1 p2 p4 p4_1 "") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (setq pl (entlast)); Gets last entity (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (setvar "Offsetdist" dt) (command "offset" dt pl ip "") ;offset (setvar "Offsetdist" OldOffsetValue) ; reset offset dist (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) ; end while (setq pn (entlast)) (command "line" (cdr (assoc 10 (entget pl))) (cdr (assoc 10 (entget pn))) "") (setq panda (entlast)) (command "line" (cdr (assoc 10 (reverse (entget pl)))) (cdr (assoc 10 (reverse (entget pn)))) "") (setq pendb (entlast)) (command "join" pl panda pendb pn "") (setvar "clayer" ".NGL") ;Change Layer to .NGL (command "PLine" p6 p3_1 "") (setvar "clayer" ".NGL DASHED");Change Layer to .NGL dashed (command "Pline" p3 p4 "") (setvar "clayer" ".NGL");Change Layer to .NGL (command "Pline" p4_1 p5 "") (setvar "clayer" OldLayer) ; reset layer (princ) ) Just because I mentioned it.... mapcar, my favourite thing this week.... ; Calculations (setq sl (* ds dd)) ; Calculates the Drain Slope (setq np1 (mapcar '+ ip (list (/ dw -2) dd))) (setq np2 (mapcar '+ ip (list (/ dw 2) dd))) (setq p1 (mapcar '- ip (list (/ dw 2) 0))) (setq p2 (mapcar '+ ip (list (/ dw 2) 0))) (setq p3 (mapcar '- np1 (list sl 0))) (setq p3_1 (mapcar '- p3 (list de 0))) (setq p4 (mapcar '+ np2 (list sl 0))) (setq p4_1 (mapcar '+ p4 (list de 0))) (setq p5 (mapcar '+ p4 (list nl 0))) (setq p6 (mapcar '- p3 (list nl 0))) the lisp does not finish, it doesnt draw anything when i use the code you have given Quote
Steven P Posted December 29, 2022 Posted December 29, 2022 1 hour ago, Subidoooo said: the lisp does not finish, it doesnt draw anything when i use the code you have given Missed out a "" , corrected the code above, try again and if it doesn't work let us know Quote
Steven P Posted December 29, 2022 Posted December 29, 2022 as Bigal - if you want to take this a bit further, his multi getvals has a pop-up dialogue that makes data entry a bit clearer when there are a few values to enter, makes the user interface nicer Quote
Subidoooo Posted December 29, 2022 Author Posted December 29, 2022 11 hours ago, BIGAL said: ; Get information from user Subidoooo or Pteven P Your welcome to use Multi getvals.lsp can set some default values also. Just a thought is it necessary to do offset maybe work out the other side points and make 1 pline. Because its a continuous shape each pt could be say ptx using set and read can do a (set (strcat "pt" "rtos (setq x (1+ x)) 2 0)) value will find example if you want. Multi GETVALS.lsp 2.96 kB · 7 downloads The reason why i use offset is because the plines are at angles so if you add a thickness it is hard to work out the correct position of the points, if you have a method of calculating them i am more than happy Quote
Dadgad Posted December 29, 2022 Posted December 29, 2022 This could also be done by creating definitions of MultiLines, in as many different widths as you would like to have available on a pallet. Quote
BIGAL Posted December 30, 2022 Posted December 30, 2022 Dadgad nice idea, a make a Mline example. (defun chkml ( / lst dic) (if (and (setq dic (dictsearch (namedobjdict) "ACAD_MLINESTYLE")) (not (dictsearch (setq dic (cdr (assoc -1 dic))) "HIDDEN-SOLID-LINE" )) ) (progn (setq lst (list (cons 0 "MLINESTYLE") (cons 100 "AcDbMlineStyle") (cons 2 "HIDDEN-SOLID-LINE") ; Name (cons 70 (+ 272)) ; caps/fill/joints (cons 3 "MLC") ; Desc (cons 51 (/ pi 2.)); Start ang (cons 52 (/ pi 2.)); End ang (cons 71 2) ; Number of lines (cons 49 0.5) ; Element Offset (cons 62 13) ; Element Colour (cons 6 "HIDDEN") ; Element Linetype (cons 49 -0.5) (cons 62 256) (cons 6 "BYLAYER") ) ) (setq obj (entmakex lst)) (dictadd dic "HIDDEN-SOLID-LINE" obj) ) ) (princ) ) 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.