(defun C:MF (/ ent elay ldata); = Move To -New Layer [and make that Layer]
(prompt "\nTo make ...-New Layers and move objects to them,")
(setq ss (ssget ":L")); not things on locked Layers
(repeat (sslength ss)
(setq
ent (ssname ss 0); first [remaining] object in selection
elay (cdr (assoc 8 (entget ent)))
ldata ; Layer data without non-transferable elements
(vl-remove-if-not
'(lambda (x) (member (car x) '(0 100 2 70 62 6)))
(entget (tblobjname "layer" elay))
); vl-remove-if-not & ldata
); setq
(if
(or
(< (strlen elay) 5)
; not a long-enough Layer name to already end in -New with anything preceding
(/= (strcase (substr elay (- (strlen elay) 3))) "-New"); not already on a Layer like that
); and
(progn
(entmake (subst (cons 2 (strcat elay "-New")) (assoc 2 ldata) ldata)); create Layer
(command "_.chprop" ent "" "_layer" (strcat elay "-New") ""); move object to it
); progn
); if
(ssdel ent ss); take that one out of selection
); repeat
); defun
Thanks Lee for the update. Could I ask what is the difference between the way the original code versus the revised one? I did not know if there was a few strings in there that just needed to be "swapped" to become a prefix from the original suffix.
Also, for a side note (I guess) with users who are on Civil3D Cogo / parts, the original lisp can take those parts and move them to the correct layer. I tried with the revised and am not getting the same result. Thank you Lee for your help!
That's amazing. Basically the same outline of the code but swapping out the ent to the vla. Wow. It works. Active X... wow.
Try the following:"*meh*" post.
...
Good post.Thanks Lee for the update. Could I ask what is the difference between the way the original code versus the revised one? I did not know if there was a few strings in there that just needed to be "swapped" to become a prefix from the original suffix.
The original code included an if statement to test whether the layer of the selected object was already suffixed, however, this is unnecessary as such objects can easily be omitted from the initial selection using an appropriate ssget filter list.
To revise the original code you would essentially need to change (cons 2 (strcat elay "-New")) to (cons 2 (strcat "New-" elay)) however, the test expressions for the if statement would also need to be either removed or amended to test for the existence of this prefix.
...
Thank you John, I take your point.
Code - Auto/Visual Lisp: [Select]
) ) ) ) ) )
: (entmake (subst '(2 . "Target") '(2 . "Source") (entget (tblobjname "layer" "Source"))))
((-1 . <Entity name: cbf8cb0>) (0 . "LAYER") (5 . "AD") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 1afb2f50>) (102 . "}") (330 . <Entity name: cae2638>) (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "Target") (70 . 0) (62 . 7) (6 . "Continuous") (290 . 1) (370 . -3) (390 . <Entity name: cae9f18>) (347 . <Entity name: caeb0a0>))
: AUDIT
Fix any errors detected? Yes/<No>: y
Name: AcDbDictionary(B3)
Value: Owner Id (B5)
Validation: Invalid
Replaced by: Set to AcDbLayerTableRecord(AD)
Name: AcDbLayerTableRecord(B5)
Value: Duplicate ownership of reference (B3)
Validation: Invalid
Replaced by: Removed
117 objects audited
Total errors found during audit 2, fixed 2
(defun c:removesuffix ( / a e i n s )
(if (setq s (ssget "_:L" '((8 . "*_DEMO"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
a (cdr (assoc 8 (entget e)))
n (strcat "_DEMO" a)
)
(if (or (tblsearch "layer" n)
(entmake (subst (cons 2 n) (cons 2 a) (entget (tblobjname "layer" a))))
)
(vla-put-layer (vlax-ename->vla-object e) n)
)
)
)
(princ)
)
(vl-load-com) (princ)
Gosh, I need to do this on all the other ones, so I know what the heck is going on. I forget so easily. Thank you for that. Seriously THANK YOU!:) Glad to help out.