CLOSE 2 POLYLINES IN LISP

CLOSE 2 POLYLINES IN LISP

Domziman
Advocate Advocate
1,137 Views
8 Replies
Message 1 of 9

CLOSE 2 POLYLINES IN LISP

Domziman
Advocate
Advocate

Hi Guys 

 

The lisp i am busy with draw's a section of a stormwater drain, i am currently stuck where i am unsure of how to close the polylines on the side (green polylines)Here is my code:

 

Domziman_0-1672208581548.png

 

(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)
)

 

Civil 3D Certified Professional
0 Likes
1,138 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

You can try to use PEDIT, select both objects (use entlast to get offseted pline) and JOIN them with a GAP larger than your offset.

OR... you should be able to calculate the endpoints of the offseted pline and draw another plines to close them.

0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant

Look at the way CapEnd.lsp >here< does it, in its Line capping option.  It works with selected objects and checks whether their ends line up appropriately, but in your situation presumably that will always be the case, so the checking part would not be needed.  If the objects are both Polylines and the capping is with a Line [or an Arc], it joins them together.  Can you work out how to use that approach, and at both ends?  The (vlax-curve-getStartPoint) and (vlax-curve-getEndPoint) functions will get you both ends to draw Lines between, in place of CapEnd's determination, and if one of the Polylines is the result of Offsetting the other, then the same ends for both will connect appropriately [you won't get an X if you draw two Lines].

Kent Cooper, AIA
0 Likes
Message 4 of 9

Shanky1999
Enthusiast
Enthusiast

Try this lisp.

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

[PolylineContinue.lsp is really not what is wanted -- it does something entirely different.]

 

@Domziman:  Another routine that demonstrates how to close off the ends between two Polylines that are Offset is OffsetBothSidesClose.lsp, >here<.  It starts with a center path and Offsets to both sides, but I assume you can figure out how to carry its end Line closures and Joining into your routine.

Kent Cooper, AIA
0 Likes
Message 6 of 9

Sea-Haven
Mentor
Mentor
0 Likes
Message 7 of 9

Domziman
Advocate
Advocate

I had a look at the lisp and to be honest i dont even understand half of what he is doing, my knowledge of autolisp isnt that much.

Civil 3D Certified Professional
0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

Try this [super-minimally tested].  With some wild guesses about appropriate relative values, it made this, the green part being a closed Polyline:

Kent1Cooper_1-1672321621506.png

Things that have

;; <-- ADDED

at the end [and in some cases the obviously related following lines] are taken from OffsetBothSidesClose.lsp.  Things with

;;;

at the beginning I just commented out because they don't do anything -- that kind of check is useful when a (command) function leaves a command still running, and you don't know how many user inputs it will take to finish it, so it needs to accept user input(s) until the command is done.  But here you would never be in mid-command at those places.

Everything else is just your original code.

 

(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 toJoin) ;; <-- ADDED toJoin to list

(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) ;; <-- [does nothing]
;;;  (command pause))
(setq pl (entlast)); Gets last entity
(setq toJoin (ssadd pl)); start selection set for Joining ;; <-- ADDED
;;;  (while (= (logand (getvar "cmdactive") 1) 1) ;; <-- [does nothing]
;;;  (command pause))
(command "_.offset" dt pl ip "") ;offset
;;;  (while (= (logand (getvar "cmdactive") 1) 1) ;; <-- [does nothing]
;;;  (command pause))
  (ssadd (entlast) toJoin) ;; <-- ADDED
  (command "_.line" ; connect starts ;; <-- ADDED
    "_none" (trans (vlax-curve-getStartPoint (ssname toJoin 0)) 0 1)
    "_none" (trans (vlax-curve-getStartPoint (ssname toJoin 1)) 0 1)
    ""
  ); command
  (ssadd (entlast) toJoin) ;; <-- ADDED
  (command "_.line" ; connect ends ;; <-- ADDED
    "_none" (trans (vlax-curve-getEndPoint (ssname toJoin 0)) 0 1)
    "_none" (trans (vlax-curve-getEndPoint (ssname toJoin 1)) 0 1)
    ""
  ); command
  (ssadd (entlast) toJoin) ;; <-- ADDED
  (command "_.pedit" "_multiple" toJoin "" "_join" 0 "") ;; <-- ADDED
(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)
)

 

It could [should?] make those Layers, as well as have other usual enhancements, like *error* handling and Object snap control.

It could also include a definition for the (dtr) function, but I would also suggest a little simplification:  converting zero degrees to zero radians is unnecessary, because it's zero in both cases, that is:  (dtr 0.0) is exactly the same as simply 0.   Similarly, (dtr 180.0) is exactly the same as simply pi.  You could skip the (dtr) function entirely if you make those replacements and also replace (dtr 90.0) with (/ pi 2).

Kent Cooper, AIA
0 Likes
Message 9 of 9

calderg1000
Mentor
Mentor

Regards @Domziman 

If you were able to get there, I'm sure you only need one more step to achieve what you need.
By applying trial and error you can determine where your code fails.
Here I give you a test that I did with data that I have entered as constant values. For my part, I work in the metric system; I hope it will fit your request.
I recommend adding the prefix "_none" in all cases where you apply "command" and a period is requested.

calderg1000_0-1672324810094.png

 

(defun c:Test1( / dw dd dt de ds nl sl ip np np1 np2 p1 p2 p3 p3_1 p4 p4_1 p5 p6 p7 p8 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 dw 1.)
;;;(setq dd (getreal "\nInsert Drain Depth: "))
  (setq dd 0.55)
;;;(setq dt (getreal "\nInsert Drain Thickness: "))
  (setq dt 0.15)
;;;(setq de (getreal "\nInsert Drain Side Extension Length: "))
  (setq de 0.20)
;;;(setq ds (getreal "\nInsert Daylight Slope 1: "))
  (setq ds 5)
;;;(setq nl (getreal "\nInsert NGL Length "))
 (setq nl 1.0) 
; 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)))
  (command "text" p1 0.05 0. "p1" "")
(setq p2 (polar ip (dtr 0.0) (/ dw 2)))
  (command "text" p2 0.05 0. "p2" "")
(setq p3 (polar np1 (dtr 180.0) sl ))
  (command "text" p3 0.05 0. "p3" "")
(setq p3_1 (polar p3 (dtr 180.0) de ))
  (command "text" p3_1 0.05 0. "p3_1" "")
(setq p4 (polar np2 (dtr 0.0) sl ))
  (command "text" p4 0.05 0. "p4" "")
(setq p4_1 (polar p4 (dtr 0.0) de ))
  (command "text" p4_1 0.05 0. "p4_1" "")
(setq p5 (polar p4_1 (dtr 0.0) nl ));...
  (command "text" p5 0.05 0. "p5" "")
(setq p6 (polar p3_1 (dtr 180.0) nl ));...
(setq p7 (polar p3_1 (dtr 270.0) dt ));...
(setq p8 (polar p4_1 (dtr 270.0) dt ));...
  (command "text" p6 0.05 0. "p6" "")
  (command "text" p7 0.05 0. "p7" "")
  (command "text" p8 0.05 0. "p8" "")
; Draw Stormwater Drain
(setvar "clayer" ".CONCRETE")
(setvar "Offsetdist" dt)
;;;(command "Pline" p3_1 p3 p1 p2 p4 p4_1 "")
(setvar "clayer" ".NGL");Change Layer to .NGL 
(command "PLine" "_non" p6 "_non" p3_1 "")
(command "Pline" "_non" p4_1 "_non" p5 "")
(setvar "clayer" ".CONCRETE")    
(command "Pline" "_non" p3_1 "_non" p7 "")
(command "Pline" "_non" p4_1 "_non" p8 "")
(setvar "clayer" ".NGL DASHED");Change Layer to .NGL  dashed  
(command "Pline" "_non" p3 "_non" p4 "")
(setvar "clayer" ".CONCRETE")
(command "Pline" "_non" p3_1 "_non" p3 "_non" p1 "_non" p2 "_non" p4 "_non" 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" "_non" p6 "_non" p3_1 "")
;;;(setvar "clayer" ".NGL DASHED");Change Layer to .NGL  dashed
;;;;;;(command "Pline" "_non" p3 "_non" p4 "")
;;;(setvar "clayer" ".NGL");Change Layer to .NGL 
;;;;;;(command "Pline" "_non" p4_1 "_non" p5 "")
(setvar "clayer" OldLayer)
(princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes