AutoLISP Routine to Move All RevClouds to a Specified Layer

AutoLISP Routine to Move All RevClouds to a Specified Layer

ianmurph
Enthusiast Enthusiast
497 Views
5 Replies
Message 1 of 6

AutoLISP Routine to Move All RevClouds to a Specified Layer

ianmurph
Enthusiast
Enthusiast

I am far from an AutoLISP expert and I am trying to create a LISP that moves all of the revision clouds to an existing layer. I started with the LISP written by someone else on this page that selects all of the revision clouds and modified it only slightly:

 

https://www.cadtutor.net/forum/topic/50989-select-all-revclouds-in-current-drawing/

 

The issue for me is that the revision clouds are in paper space, so I removed the (410 . "Model") part, but now it will only select the revision clouds on the current paper space. My solution was to loop through all of the layout tabs and select the rev clouds, move them to a layer and then move onto the next layout tab (my code is below for reference). Everything is working but its running slow and I feel like this is very clunky. Is there a way to do this without actually opening each layout tab? Can I select all of the revision clouds on all of the layout tabs without opening each tab one by one?

 

(defun c:RevCloudLayers ()

    ;USER ENTERS THE LAYER NAME TO MOVE ALL REVCLOUDS TO
    (setq layerName (getstring T "Enter the revision layer name: "))
    
    (setq numlayouts (length (layoutlist))) ;STORES THE NUMBER OF LAYOUT TABS IN THE DRAWING

    ;LOOP THROUGH ALL THE LAYOUT TABS
    (setq i 0) ;LOOP COUNTER
    (while (< i numlayouts)
        (setvar "ctab" (nth i (layoutlist)))
        (c:CloudSel)
        (setq AllRevClouds (ssget))
        (vl-cmdf "._change" AllRevClouds "" "_p" "_la" layerName "")
        (setq i (+ 1 i))
    )

    ;MOVE BACK TO COVER PAGE AND ZOOM EXTENTS
    (setvar "ctab" (nth 0 (layoutlist)))
    (command "zoom" "e")
    
    (alert "RevClouds Moved To Layer: " layerName)
  
(princ)
)

;----------------------------------------------------------------------------------------------------
; THIS FUNCTION WILL SELECT ALL OF THE REVISION CLOUDS ON THE CURRENT PAPER SPACE OR IN MODEL SPACE
(defun c:CloudSel (/ s e i a p)

 (if (setq s (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "/=") (42 . 0) (-4 . ">") (90 . 4))))
   (repeat (setq i (sslength s))
     (setq e (ssname s (setq i (1- i)))
           a (length (vl-remove-if-not '(lambda (u) (and (eq (car u) 42) (not (eq (cdr u) 0)))) (entget e)))
           p (length (vl-remove-if-not '(lambda (u) (eq (car u) 10)) (entget e)))
     )
     (if (not (or (eq a p) (eq (1+ a) p)))
       (ssdel e s)
     )
   )
 )
 (sssetfirst nil s)
 
 (princ)
;----------------------------------------------------------------------------------------------------
)

 

 

0 Likes
498 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

Commands involving object selection can "see" only objects in the current space.  If you do it by manipulating entity data rather than with a CHANGE command, those not in the current space are reachable, and you don't need to move around from space to space.  After establishing the Layer name and the selection set, try this, with no need to know the number of layouts or for the loop counter for them, no CTAB settings, etc.:

 

(repeat (setq n (sslength AllRevClouds))

  (setq edata (entget (ssname AllRevClouds (setq n (1- n)))))

  (entmod (subst (cons 8 layerName) (assoc 8 edata) edata))

)

Kent Cooper, AIA
0 Likes
Message 3 of 6

ronjonp
Advisor
Advisor

If you're using the baked in REVCLOUD command you could also filter better like so:

 

(ssget '((0 . "LWPOLYLINE") (-3 ("RevcloudProps"))))

 

 

 

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Ronjonp

(ssget '((0 . "LWPOLYLINE") (-3 ("RevcloudProps"))))

Select objects: 0 found

 

Maybe a 90 > x as a revcloud has a lot of vertices. But could get other plines.

0 Likes
Message 5 of 6

ronjonp
Advisor
Advisor

@Sea-Haven Strange .. works here.

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

If you're using the baked in REVCLOUD command ....


... in a recent-enough version.  I don't know when the current version of that command came in, but the command used to make only an ordinary Polyline, of arc segments of a constant bulge factor, but with no "intelligence" about being a Revcloud.  So those made in older versions wouldn't be identifiable in that (-3 ...) way.  I have some code that will find all ordinary Polylines with only arc segments, and only of the correct bulge factor, to find such Revclouds that have not been altered.  But if part has been Trimmed out, or any grip-editing has been done, that uniformity of bulge factor would be spoiled, and it won't find them.

Kent Cooper, AIA
0 Likes