Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Create new layer for each object (solid) in base layer

Anonymous

Create new layer for each object (solid) in base layer

Anonymous
Not applicable
Please help me with this. And sorry because of my bad English.
I have a solid named A (it's in layer A) and then I sliced it to many smaller solids (each solid is the concrete block I have to pour in one day, from left to right and bottom to top).
Now I want to count how many solid in layer A (let say n solids) then create new n layers named A1, A2,..., An; then set each solid for each new layer based on their Centroid (from left to right and bottom to top).
I've already searched so many topics but I can't find any lisp like this.
Thanks in advance and appreciate your help!
Example.png
 
 
 
 
0 Likes
Reply
Accepted solutions (2)
1,620 Views
16 Replies
Replies (16)

kajanthangavel
Advocate
Advocate

Can You post sample drawing

Anonymous
Not applicable

Sorry about my bad explanation.

 
0 Likes

Anonymous
Not applicable

I found this lisp has the same idea as mine but it can't sort in the order I want.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-layer-lisp-routine/td-p/22545...

(defun c:RCC2 (/ en layername objects ct enlist add-zeros)
(setq en (entsel "\nSelect an object on the layer")) ; select an object on the layer desired
(setq layername (cdr (assoc 8 (entget (car en))))) ; extract the name of the layer from that object
(setq objects (ssget "X" (list (cons 8 layername)))) ; use that name to select all objects on that layer in the drawing
(setq ct 0) ; set iterator to 0 in prep for loop
(repeat (sslength objects) ; start loop, repeat for as many objects as there were found
(setq layer (strcat layername (itoa ct))) ; make a string with our new layer name, layer1, layer2, etc.
(command "-layer" "_n" layer "") ; make the new layer
(setq enlist (entget (ssname objects ct))) ; get the object's entity data
(setq enlist (subst (cons 8 layer) (assoc 8 enlist) enlist)); update object's entity data with new layer name
(entmod enlist) ; update the object
(setq ct (1+ ct)) ; increment iterator
) ; end loop
(princ)
)
0 Likes

kajanthangavel
Advocate
Advocate

Try this ...

 

FormatFactory Screen Record20200819_213452.gif

 

Code Here...

(defun nLayer (Nme Col)
	(if (not (tblsearch "LAYER" Nme))
		(entmake	(list (cons 0 "LAYER")
					(cons 100 "AcDbSymbolTableRecord")
					(cons 100 "AcDbLayerTableRecord")
					(cons 2  Nme) ; Layer name
					(cons 70 0) 
					(cons 62 Col) ; Colour
					(cons 6 "Continuous") ; Line type
					(cons 290 1) ; plot
					(cons 370 0)) ;lineweght
		)
		
		(prompt (strcat "\n" Nme " - Layer Already Exit"))

	)
	(princ)
)

(defun c:slay (/ en layername objects ct enlist add-zeros)
(setq ct 1) 
(setq laycor 9)
(prompt (strcat "\nSelect Solid Reversly..."))
(if (setq objects (ssget "_:L" '((0 . "3DSOLID"))))

(repeat (setq i (sslength objects))
	(setq obj (vlax-ename->vla-object (ssname objects (setq i (1- i)))))
	(setq layername (vla-get-layer obj))
	(setq layer (strcat layername "-" (itoa ct)))
	(if (= laycor 😎 (setq laycor 9) (setq laycor 8))
	(nLayer layer laycor)
	(vla-put-layer obj layer)
	(setq ct (1+ ct))
)
(prompt (strcat "\nSolid Not Selected...."))
)
(princ)
)
(prompt (strcat "\nType SLAY to run"))

 

I hope, This will help you.

Sea-Haven
Mentor
Mentor

Try using (ssget "F" (list pt1 pt2) can drag a line over all slices in one go, just pick pt1 pt2 as Fence option. 

Anonymous
Not applicable

Thanks a lot for your help. This lisp result is exactly what I want.

But there is one problem I hope you can help me. Each time my boss changes the original solid (pouring method, size of concrete block...) I have to redo this process and a total of solids each time I have to name is around 2000 solids. Could you upgrade the lisp so I can select all the solid and it will show the same result?
Anyway, thanks again.

0 Likes

Anonymous
Not applicable

I've changed this: (if (setq objects (ssget "_:L" '((0 . "3DSOLID"))))

to this: (if (setq objects ((ssget "F" (list pt1 pt2) "_:L" '((0 . "3DSOLID"))))

And select using fence method (from right to left) but the order is not right. Maybe I'm doing something wrong?

0 Likes

kajanthangavel
Advocate
Advocate

@Sea-Haven 

thank you for your comment.

 

I write code with

(vl-sort lst (function (lambda (a b) (< (cdr a) (cdr b)))))

This is not sort that solid.

If you have any solution. recommend to me

I am a beginner for Lisp.

Anonymous
Not applicable

Thank you. Your lisp solves 80% of my work.

I'll wait for one more day and see if anyone has another idea for the selection method.

If not I'll "Accept Solution" and happy with your lisp, just need a little bit more time to select those 2000 solids 😁 

kajanthangavel
Advocate
Advocate
Accepted solution

@AnonymousI tired to make selection set X axis order and Z axis order, I can not get solution,

 

I try to make something for you.

You can select all object, but it not uniform.

slection.gif

 

if you like fence selection

try this

Fence selection.gif

 

 

 

 

Anonymous
Not applicable

I prefer the 1st method. I've tried it and it's really amazing. Thank you for your help.

0 Likes

kajanthangavel
Advocate
Advocate

Glad you were able to figure out how it works

maratovich
Advisor
Advisor
Accepted solution

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net

Anonymous
Not applicable

Thank you for finding this topic and upgrade your software more than I asked through email.

This solves all my issues.

0 Likes

maratovich
Advisor
Advisor

Update files 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes

sameerulcdc
Contributor
Contributor

hi 
this lsp need to modified to select 3d polyline and make new layer 

 

example

layer-15 having 3 3d polylines i need to make layer01-15, layer02-15, layer03-15

for different layers like that 

 

Thank you in Advance  

0 Likes