Delete outside of multiple polylines in one instance, is this possible?

Delete outside of multiple polylines in one instance, is this possible?

Jonathan.Gray68UQW
Enthusiast Enthusiast
12,021 Views
47 Replies
Message 1 of 48

Delete outside of multiple polylines in one instance, is this possible?

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Hello all, 
I am wondering is there a lisp routine or something that will allow me to select multiple closed polylines and then delete everything outside of these closed polylines in one command? 

 

Please see the screenshots below as well as the corresponding AutoCAD file for any generous help you guys could give me :).  

Also out of curiosity could the inverse of what is shown below be somehow made as well? Where that I select the same 3 closed boundaries and have autocad trim what inside of each of 3 all at the same time? 

0 Likes
12,022 Views
47 Replies
Replies (47)
Message 41 of 48

Sea-Haven
Mentor
Mentor

Taking your sample dwg you just pick the boundaries 3,  then Enter as I say though more successful in Bricscad than Autocad just does not like doing the trim. I was looking at changing the pline and doing single segment offset trims to get around the problem. If you just do a external trim you can lose lines that cross 2 boundaries. Hence the trim between 2 boundaries methods, will see if I can find time.

0 Likes
Message 42 of 48

Sea-Haven
Mentor
Mentor

I have tried this on your sample dwg, its super quick Bricscad and super slow Autocad but does work, will try to speed up may be a zoom thing.

 

Any way pick the 3 boundaries, then top right of all the contour lines bottom left below contour lines.

 

;  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/delete-outside-of-multiple-polylines-in-one-instance-is-this/m-p/9776779/highlight/false#M405195
; deletes outside multiple pline bondaries
; By AlanH Oct 2020


(defun c:deloutb ( / CO-ORD ENT MAXI MINI OLDSNAP SS X)
(alert "Make sure you only have layers that should be displayed\n \nThis is destructive routine")
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(setq maxi (getpoint "\Pick top right cnr"))
(setq mini (getpoint "\nPick bottom left cnr"))
(repeat (setq J (sslength ss))
(setq ent (ssname ss (setq J (- J 1))))
(command "offset" 1.0 ent maxi "")
(setq co-ord (reverse (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast))))))
(setq co-ord (cons (nth (- (length co-ord)1) co-ord) co-ord))
(command "erase" (entlast) "")
(command "offset" 2.0 ent maxi "")
(setq ent2 (entlast))
(setq K (length co-ord))
(repeat (- (length co-ord) 1)
(command "trim" ent ent2 "" "_F" (nth (setq K (- K 1)) co-ord)(nth (- K 1) co-ord) "" "")
)
(setq ss2 (ssget "_WP" co-ord))
(command "move" ss2 "" (list 0.0 0.0) (list 0.0 5000.0))
)
(command "zoom" "e")
(command "erase" "w" mini maxi "")
(Command "move" (ssget "_W" (getvar 'extmax)(getvar 'extmin)) "" "0.0,5000.0" "0.0,0.0")
(command "zoom" "e")
(setvar 'osmode oldsnap)
(princ)
)
(c:deloutb)

 

0 Likes
Message 43 of 48

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Hello there!  Thank you so much for putting your time, efforts and skills into this for me!  I gave it a shot in Autocad but didn't work out like I thought it would. I don't want to bother you anymore with it but just wanted to stop by and say thank you for trying!!  

To anybody else out there that wants to give it shot please feel free to do so! I think this could be in at the right time and place a valuable tool for people to have :). 

0 Likes
Message 44 of 48

ВeekeeCZ
Consultant
Consultant

Well, you never commented on my routine, so not sure if you even tried it, or why it did not work for you.

I don't really mind so much - I put it together mainly for myself. 

 

It uses the EXPORTTOMODEL function which I consider very/most powerful tool for this kind of job. The speed is far beyond the traditional TRIM approach (or EXTRIM). It even handles XREFs. Well, it has it!s limits, it might fail on too complex drawings, but still... it's the best tool we have.

 

Just had the chance to use it a couple of times today.. yeah, it's good. Just saying...

0 Likes
Message 45 of 48

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Well, you never commented on my routine, so not sure if you even tried it, or why it did not work for you.

I don't really mind so much - I put it together mainly for myself. 


 

Me like it. 👏

 

genie-gif (1).gif

 

I once used .EXPORTLAYOUT for sheets exported to REVIT.

0 Likes
Message 46 of 48

ВeekeeCZ
Consultant
Consultant

Thanks, Big Boy, appreciate it. 😎

0 Likes
Message 47 of 48

hak_vz
Advisor
Advisor

@ВeekeeCZYour code is superb, as always.

Miljenko Hatlak

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.
Message 48 of 48

lena.talkhina
Alumni
Alumni

Hello @Jonathan.Gray68UQW  !

Great to see you here on LISP Forum.

Did you find a solution?
If yes, please click on the "Accept as Solution" button as then also other community users can easily find and benefit from the information.
If not please don't hesitate to give an update here in your topic so all members know what ́s the progression on your question is and what might be helpful to achieve what you ́re looking for. 🙂

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

0 Likes