Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Anonymous
1467 Views, 16 Replies

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

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
 
 
 
 
Tags (2)
Labels (1)
16 REPLIES 16
Message 2 of 17
kajanthangavel
in reply to: Anonymous

Can You post sample drawing

Message 3 of 17
Anonymous
in reply to: kajanthangavel

Sorry about my bad explanation.

 
Message 4 of 17
Anonymous
in reply to: kajanthangavel

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)
)
Message 5 of 17
kajanthangavel
in reply to: Anonymous

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.

Message 6 of 17
Sea-Haven
in reply to: kajanthangavel

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

Message 7 of 17
Anonymous
in reply to: kajanthangavel

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.

Message 8 of 17
Anonymous
in reply to: Sea-Haven

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?

Message 9 of 17
kajanthangavel
in reply to: Anonymous

@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.

Message 10 of 17
Anonymous
in reply to: kajanthangavel

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 😁 

Message 11 of 17
kajanthangavel
in reply to: Anonymous

@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

 

 

 

 

Message 12 of 17
Anonymous
in reply to: kajanthangavel

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

Message 13 of 17
kajanthangavel
in reply to: Anonymous

Glad you were able to figure out how it works

Message 14 of 17
maratovich
in reply to: Anonymous

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 15 of 17
Anonymous
in reply to: maratovich

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

This solves all my issues.

Message 16 of 17
maratovich
in reply to: Anonymous

Update files 

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

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  

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report