Jump to content

Layer split in several layers


Recommended Posts

Posted (edited)

Well what do you know. Jeff H. was right all along, now that the parameters are clear anyone can ptich in. :D

SplitTolayers

DRAFT1

(defun c:Ntest (/ bnd _sort wdwsize objts EntColl ent wave  b_ sp
   RemItm enx lnm cnt lyn lylst)
(vl-load-com)
(defun bnd (ent / ll ur)
 (vla-getboundingbox ent 'll 'ur)
 (if (< (distance (vlax-safearray->list ll)
    (vlax-safearray->list ur)
 )
 WdwSize
     )
   (list (vlax-safearray->list ll) (vlax-safearray->list ur))
 )
)
(defun _sort (lst)
 (vl-sort lst
            (function
 (lambda (y1 y2)
  ([color=blue]<[/color] (cadr (caadr y1))(cadr (caadr y2))))))
 )
(setq wdwsize 200.00 layern "Base" cnt 1 lylst nil)  
(if (setq objts (ssget "_X" (list '(0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")(cons 8 layern))))
  (progn
    (repeat (setq i (sslength objts))
     (setq ent (ssname objts (setq i (1- i))))
     (if (setq
    b (bnd (vlax-ename->vla-object ent))
         )
       (setq
         EntColl (cons (list ent b) EntColl)
       )
       (entmod (subst (cons 8 "Too_Large")
        (assoc 8 (entget ent))
        (entget ent)
        )
       )
     )
   )
        (setq EntColl (_sort EntColl))
 (while (setq b_ (car EntColl))
  (setq wave (ssget "_W" (setq sp (caadr b_))
              (polar sp 0.785398163 (* WdwSize 1.41421356))
   (list '(0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")(cons 8 layern))
    ))
    (repeat (sslength wave)
     (setq enx (entget (ssname wave 0)))
     (entmod
     (subst
       (cons 8 (setq lnm (strcat layern "_" (itoa cnt))))
       (assoc 8 enx)
       enx
     )
   )
     (if (not (member lnm lylst))(setq lylst (cons lnm lylst)))
     (setq wave (ssdel (setq RemItm (ssname wave 0)) wave)
         EntColl (vl-remove (assoc RemItm EntColl) EntColl))
    )

   (setq cnt (1+ cnt))
   )
    (if lylst (foreach lyr lylst
   (setq lyn (entget (tblobjname "LAYER" lyr)))
   (entmod (subst (cons 62 (atoi (vl-string-left-trim (strcat layern "_") lyr))
         )(assoc 62 lyn) lyn))
  )
 )
    )
  (princ (strcat "\nNo objects found on Layer " layern))
  )
(princ) 
 )

 

Found a bug on this code: the result varies from one drawing to another:

I think it needs a better sorting routine, lowest Y nearest to Leftmost X

 

Any suggestions are welcome. That means you :D

 

EDIT: Fixed it :)

Edited by pBe
  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

  • luiscarneirorm

    23

  • pBe

    20

  • BIGAL

    1

  • Jeff H

    1

Top Posters In This Topic

Posted Images

Posted

thanks for the help, I can only test the function Monday ...

Good weekend ...:D:D:D

Posted

Hum.... with the drawing that I put the example above the function does exactly what it is supposed, but with a slightly more complex is no longer so perfect :cry:

Experiment with drawing placa4(post #36), and see what you think

Posted

I've been testing the function in various designs, and I get it better how it works.

I understand it's hard to improve it, as she has to follow some logical.

you can just put the option to choose the window size?

Thank you for your good work

 

:beer:

Posted

I will make another version for you. on top of what you had now.

and yes i will put the prompt for window size back for you

 

I'll keep you posted. sorta busy right now luis

 

Cheers :beer:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...