Help with a LISP code.

Help with a LISP code.

UNKNOWN.DESIGN.LAB
Advocate Advocate
3,374 Views
22 Replies
Message 1 of 23

Help with a LISP code.

UNKNOWN.DESIGN.LAB
Advocate
Advocate

Hello i am trying to add a super practical LISP code i found that will change all block items layer to "0" layer and end the "CANNOT DELETE LAYER BECAUSE IT IS BEING USED BY BLOCK(S)" issue.

 

It is my first time creating a LISP, though i followed a tutorial before this one and got the code they were using to work properly.

 

I found this code code i want to use here: < http://forums.augi.com/showthread.php?127731-changing-multiple-blocks-to-quot-0-quot-layer >

 

Here is the error message COPIED FROM MY COMMAND LINE:

Command: FIXBLKS
Select objects: 1 found
Select objects: undo Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back] <1>: BEgin
Command: ; error: no function definition: VLAX-ENAME->VLA-OBJECT

 

I will attach a copy of the .lsp i created with this post as well for anyone who wished to review.

 

Here is the code copied

[This is an amateur question but should not the code start at the "(defun.....)" and not "; written by:....." ??]:

; Written By: Tom Beauford
; Changes all block entities to layer "0" with color, linetype & lineweight ByBlock
(defun C:FIXBLKS (/ SSET intCount ENAM ELST BNAM FLST FIX1)
  (defun FIX1 (BNAM / BENAM BONAM)
    (if (not (member BNAM FLST))
   (progn
     (setq FLST  (cons BNAM FLST)
     BENAM (tblobjname "block" BNAM)
     )
   (while (setq BENAM (entnext BENAM))
      (if (= (cdr (assoc 0 (entget BENAM))) "INSERT")
       (fix1 (cdr (assoc 2 (entget BENAM))))
       (progn
         (setq BONAM(vlax-ename->vla-object BENAM))
                (vl-catch-all-apply 'vla-put-layer (list BONAM "0"))
                (vl-catch-all-apply 'vla-put-color (list BONAM 0))
                (vl-catch-all-apply 'vla-put-linetype (list BONAM "Byblock"))
                (vl-catch-all-apply 'vla-put-Lineweight (list BONAM -2))
;                (vl-catch-all-apply 'vla-put-PlotStyleName (list BONAM "Byblock"))
       )
     )
   )
        )
    )
  )
  (setq SSET (ssget (list (cons 0 "INSERT"))))
  (vl-cmdf "undo" "BEgin")
  (repeat (setq intCount (sslength SSET))
    (setq intCount     (1- intCount)
          ENAM (ssname SSET intCOunt)
    ELST (entget ENAM)
    BNAM (cdr (assoc 2 ELST))
    FLST nil
    )
    (fix1 BNAM)
  )
  (vl-cmdf "undo" "End")
  (vl-cmdf "regen")
  (princ)
)

 

0 Likes
Accepted solutions (1)
3,375 Views
22 Replies
Replies (22)
Message 21 of 23

dbroad
Mentor
Mentor

I don't see the problem with your three images. The last image has a blank layer setting because the selected objects are on different layers, not that the layer doesn't exist. If you select objects one by one you will see that a few objects are on layers other than 0.  To get the most control, just select the layer you want those nested entities on, presumably layer 0.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 22 of 23

maxim_k
Consultant
Consultant

 


@dbroad wrote:

..... The last image has a blank layer setting because the selected objects are on different layers, not that the layer doesn't exist....


If selected objects are on different layers. Properties palette on Mac shows:

 

2019-03-15_09-59-00.png

 

There is a bug in LAYMGR command on Mac: when layer you want to remove from drawing is inside on of blocks, then the objects that were on that layer inside block simply loose Layer name information - it become blank.

As the result you even cannot copy such objects to clipboard and it is necessary to run AUDIT command in order to repair this. After auditing objects with empty layer name placed to $AUDIT-BAD-LAYER layer.

 


Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.


Maxim Kanaev
Architect
MARSS

MacACAD | Linkedin

Etiquette and Ground Rules of Autodesk Community
Message 23 of 23

UNKNOWN.DESIGN.LAB
Advocate
Advocate

Grateful your help @maxim_k @dbroad @dlanorh @ВeekeeCZ @Kent1Cooper .

Thank you guys !

 

The new FIXBLK.lsp by @dlanorh fulfills the requested task well.

0 Likes