Automatic Trim

Automatic Trim

k005
Advisor Advisor
6,434 Views
29 Replies
Message 1 of 30

Automatic Trim

k005
Advisor
Advisor

 

Hello guys;

 

How can I do automatic Trim the drawings I have given in the example?

0 Likes
Accepted solutions (2)
6,435 Views
29 Replies
Replies (29)
Message 2 of 30

hak_vz
Advisor
Advisor

Autocad is primarily drafting software, and you have to exploit it well.

Lisp scripts are used for things that are not easy to draw or create using standard commands.

You can create wall contours  using command boundary, shortly BO.

Create new layer and set it active, or just use new color.

Start command boundary, pick all points inside rooms and finish command.

This creates all inside polylines (pic above). Create rectangle that bounds all entities.

Create a line that starts somewhere on outer wall and ends outside bounding rectangle. 

Create boundary by clicking a point between outer wall and rectangle. This will create

boundary that also holds points from rectangle. Move all entities in a layer for some

orthogonal distance aside. Explode other boundary and remove sufficient lines.

Use command join to put all into polylines, move mack to original location and you're done.

Less than minute of work and good result.

 

Untitled.png

 

 

 

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.
0 Likes
Message 3 of 30

k005
Advisor
Advisor

@hak_vz 

 

I'm not new to using AutoCAD effectively.

i asked how could this be done with the Lisp routine?

0 Likes
Message 4 of 30

hak_vz
Advisor
Advisor

From the way your drawing is created it would be hard work, since your walls are not closed polylines and  joining them is not easy by code. If all your walls and columns would have been created as rectangles code would be simple.

Start command REGION, select all polylines and convert to region. Use command UNION and join to  single region. Explode that region and use command JOIN to create new polylines and that results with what you ask.

If you are willing to change your drawing and the way you work,  code is not a problem.

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 5 of 30

k005
Advisor
Advisor

 

I thought it would be a little difficult too, I wasn't sure.

 

I can't change the drawing style right now. It's like a Standard.

 

In this case, I will do the trim manually.


Thank you very much. Friend.

0 Likes
Message 6 of 30

Sea-Haven
Mentor
Mentor

Drawing from scratch the way you want is the way to go, but requires a package for all the parts of a dwg. This has around 100 functions, walls, doors, windows, roofs etc. Yes it does have a cost, but is a low fee. I just did something for another post drawing concrete slab beams.

 

SeaHaven_0-1630799500563.png

 

 

 

0 Likes
Message 7 of 30

hak_vz
Advisor
Advisor

@k005

Created this for your particular drawing setup using layer names. Function erases existing walls and columns so if you want to retain them, you should work on copy somewhere aside. When function starts select all entities inside a rectangle (window selection using two points), provide thickness of wall elements in cm (so you can use it with different values) and function will join all polylines the way you asked. When operation is finished, change layers and other parameters for final polylines, or it can be added to the code later. It has took some time for me to find applicable algorithm, but it now works as expected. This will cost you at least two bottles of Efes Pilsner if I ever decide to visit Turkey.

 

(defun c:jointopoly ( / *error* adoc acet-pljoin take pointlist2d ss_ver ss_hor  e eo pts p1 p2 ss SS2 plines wall_thickness i lst)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(princ)
	)
	(defun acet-pljoin ( ss st fuzz)(acet-pljoin2 ss st fuzz))
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(princ "\nSelect all entites to join >")
	(setq p1 (getpoint "\nPick first window selection point >"))
	(setq p2 (getcorner p1 "\nSelect second window selection point >"))
	(initget 7)
	(setvar 'cmdecho 0)
	(setq wall_thickness (* 0.01(getint "\nWall whickness cm >")))
	(setq ss_ver (ssadd) ss_hor (ssadd))	
	(setq ss (ssget "_W" p1 p2 '((0 . "LWPOLYLINE")(8 . "Kolon"))))
		(cond 
			((and ss)
				(cond 
					((/=  (rem (sslength ss) (/ (sslength ss) 4.0)) 0.0)
						(princ "\nNumber of column edges is not rigth >")
					)
					(T
						(initcommandversion)
						(command "_.join" ss "")
					)
				)
			
			)
		)
		(setq ss (ssget "_W" p1 p2 '((0 . "LWPOLYLINE")(-4 . "=") (90 . 2))))
		(acet-autoload2    '("PLJOINSUP.LSP"    (acet-pljoin2 ss st fuzz)))
		(cond 
			((and ss)
				(setq i -1)
				(while (< (setq i (1+ i)) (sslength ss))
					(setq e (ssname ss i))
					(setq eo (vlax-ename->vla-object e))
					(setq pts (pointlist2d  (vlax-get eo 'Coordinates)))
					(if (equal  (apply '- (mapcar 'car pts))  0.0  1e-5) (setq ss_ver (ssadd e ss_ver)))
					(if (equal  (apply '- (mapcar 'cadr pts))  0.0  1e-5) (setq ss_hor(ssadd e ss_hor)))
				)

				(cond 
					((and ss_ver)

					  (acet-pljoin ss_ver "Both" wall_thickness)
					  (setq ss2 (acet-ss-new (entlast)))
					  (setq plines (acet-ss-union (list plines ss2)))
					)
				)
				(cond 
					((and ss_hor)
					 (acet-pljoin ss_hor "Both" wall_thickness)
					  (setq ss2 (acet-ss-new (entlast)))
					  (setq plines (acet-ss-union (list plines ss2)))
					)
				)
			)
		)
		(cond 
			((and ss)
				(setq ss (ssget "_W" p1 p2 '((0 . "LWPOLYLINE"))))
				(setq lst (entlast))
				(command "_.region" ss "")
			)
		)
		(setq lst (entlast))
		(setq ss (ssget "w" p1 p2 '((0 . "REGION"))))
		(cond 
			((and ss)
				(while (setq e (entnext lst))
					(setq ss(ssadd e ss))
				)
				(command "_.union" ss "")
			)
		)
		(setq ss (ssget "w" p1 p2 '((0 . "REGION"))))		
		(cond
			((and ss) (command "_.explode" ss)
				(setq ss (ssget "_W" p1 p2 '((0 . "LINE"))))
				(command (command "_.pedit" "M" ss "" "Y" "J" "" ""))
			)
		)
	(setvar 'cmdecho 1)
	(vla-endundomark adoc)
	(princ "\nDone!")
	(princ)
)

 

 

 

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 8 of 30

k005
Advisor
Advisor

 

I ran the code. I have attached the result as a screenshot. Didn't trim.

 

* I'll bring Efes beers right away. 🍻  🙂

0 Likes
Message 9 of 30

hak_vz
Advisor
Advisor

I run the code on your example posted above and it works. You use Autocad or something else?

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 10 of 30

k005
Advisor
Advisor

 

I am using AutoCAD. Can I have the result as a Screenshot?

0 Likes
Message 11 of 30

hak_vz
Advisor
Advisor

This is what I get running code on your sample drawing (used on before state). When you select window points click further aside and not directly on outer wall edge. I hope you have installed Express tools since I had to use function acet-pljoin. Classic pedit is not producing good result. For test try to run command MPEDIT. Does it work for you?

 

Untitled.png

 

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.
0 Likes
Message 12 of 30

k005
Advisor
Advisor

There is a misunderstanding.

I just wanted to trim. just trim.

Trimming columns and curtains automatically...

0 Likes
Message 13 of 30

hak_vz
Advisor
Advisor

To create regions I have to join lines to closed polylines. Final conversion to polyline is optional. I tried just trimming but it doesn't work as expected.

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 14 of 30

k005
Advisor
Advisor

No problem.., if not, continue with the manual trim command. Thank you buddy.

0 Likes
Message 15 of 30

Sea-Haven
Mentor
Mentor

This had me thinking about concrete slabs another post, and I went down the path of 3d solids using union you get the desired pattern, joining concrete beams or in this case columns.

 

As they say watch this space.

0 Likes
Message 16 of 30

3wood
Advisor
Advisor
Accepted solution

Another approach is here.

Although it is slower than @hak_vz 's solution but it doesn't require wall thickness input.

I have tested your example file and it is successful.

Here is the screenshot of another test file.

cleanwall.PNG

Message 17 of 30

k005
Advisor
Advisor

Yes . this is the transaction.

But I couldn't test it fully, can you send a full version?

0 Likes
Message 18 of 30

Sea-Haven
Mentor
Mentor

Not sure what is not fast, I drew multiple rectangs.

 

Ok tricky bit extrude select all, say 5, union all done took like 2 seconds. 

SeaHaven_0-1631178894396.png

 

 

0 Likes
Message 19 of 30

hak_vz
Advisor
Advisor

@Sea-Haven wrote:

Not sure what is not fast, I drew multiple rectangles.

Ok tricky bit extrude select all, say 5, union all done took like 2 seconds. 


Problem is that @k005 has to create his drawing (corporate standard) so that all construction segments are polilines. Column rectangle is not rectangle but rectangle drawn as 4 separate polyline segments. Region command don't work for this case.

 

Although, to be correct. @k005 has in his sample drawing created joined polylines and left us all confused. 

 

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.
0 Likes
Message 20 of 30

k005
Advisor
Advisor

@hak_vz 

 

If it was my own drawing, I would stick to the standards. But this is how these drawings come to me, Friends.

0 Likes