Create regions out of different layers and place them in their correspondent layer, is it possible?

Create regions out of different layers and place them in their correspondent layer, is it possible?

manso86
Enthusiast Enthusiast
518 Views
7 Replies
Message 1 of 8

Create regions out of different layers and place them in their correspondent layer, is it possible?

manso86
Enthusiast
Enthusiast

Hi guys,

 

I would like to create a AutoLISP but I am still very new to it and I believe I need a lot of time, perhaps you can help?

 

I need to create create regions out of polylines and allocate these new regions into the layer of the polylines it was created from. The region command does the first step but it allocates all the new region in the same layers so I am trying to make the process quicker not do go one-by-one.

 

Could anyone help?

 

Regards,

 

 

manso86_0-1685552266813.png

 

0 Likes
Accepted solutions (3)
519 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor
Accepted solution
Message 3 of 8

paullimapa
Mentor
Mentor
Accepted solution

Give attached RegByLyr.lsp a try.

Routine cycles through all layers and converts closed lwpolylines to regions and changes them to the corresponding layer.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 8

komondormrex
Mentor
Mentor
Accepted solution

hey,

sure it is possible

 

 

(defun c:closed_pline_region nil
	(vlax-map-collection (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
			'(lambda (object)
				(if (and 
						 (= "AcDbPolyline" (vla-get-objectname object))
						 (minusp (vlax-get object 'closed))
					)
						(progn
							(vla-put-layer
								(car (vlax-invoke (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))) 
															  'addregion 
															  (list object)
												  )
								)
							    (vla-get-layer object)
							)
					 		(vla-erase object) 
						)
				)
			)
	)
	(princ)
)

 

 

 

Message 5 of 8

manso86
Enthusiast
Enthusiast

Thanks a lot @Sea-Haven , this works perfectly and very quick response! 

0 Likes
Message 6 of 8

manso86
Enthusiast
Enthusiast

Hello @paullimapa awesome this also works, thanks a lot for your help! looking forward to getting into the autolisp world!

0 Likes
Message 7 of 8

manso86
Enthusiast
Enthusiast

@komondormrex Thanks a lot! you guys are awesome! very quick response and works as I wanted ! 🙏

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

Glad to have helped. As you can see there are more than one way to get it done. That’s what’s so fascinating about programming. Enjoy the learning process and cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos