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

Change all block element to Layer 0 except defpoints

18 REPLIES 18
Reply
Message 1 of 19
pixelarch
4101 Views, 18 Replies

Change all block element to Layer 0 except defpoints

Dear All,

 

I create this topic http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Change-all-block-element-to-Layer-0-w...

 

I got solution for that topic but now i need a liitle bit change as my latest comments in that topic. I dont want to change defpoint layer to layer 0.

 

Thanks.

 

 

18 REPLIES 18
Message 2 of 19
_Tharwat
in reply to: pixelarch

This ?

(defun c:Test nil
  ;; 	Tharwat 24.Sep.2013	;;
  (or acdoc
      (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (vlax-for x (vla-get-blocks acdoc)
    (if (and (eq :vlax-false (vla-get-Islayout x))
             (eq :vlax-false (vla-get-IsXref x))
        )
      (vlax-for b x
        (if (/= (vla-get-layer b) "Defpoints")
          (vla-put-layer b "0")
        )
      )
    )
  )
  (vla-regen acdoc AcAllViewports)
  (princ)
)
(vl-load-com)

 

Message 3 of 19
3wood
in reply to: pixelarch

I would suggest give user an option to remain objects on both Layer defpoint and any other non-plot layers as they are.

Message 4 of 19
pixelarch
in reply to: _Tharwat

This one works well, it is what i needed but i dont want defpoint or another non plot layer will be changed to 0.

 

Could you adjust base on this code? Thanks.

 

(defun c:test ( / s )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
        (LM:ApplytoBlockObjects
            (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
           '(lambda ( obj / lin )
                (vla-put-layer obj "0")
                (setq lin (strcase (vla-get-linetype obj)))
                (cond
                    (   (= "BYLAYER" lin))
                    (   (= "CONTINUOUS" lin)
                        (vla-put-linetype obj "BYLAYER")
                    )
                    (   t
                        (vla-put-linetype obj "HIDDEN")
                        (vla-put-linetypescale obj 1.0)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 5 of 19
CADaSchtroumpf
in reply to: pixelarch

Perhaps?

 

(defun c:test ( / lockedLayerPlot s )
  (setq lockedLayerPlot '("Defpoints"))
  (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (= (vla-get-Plottable l) :vlax-false)
      (setq lockedLayersPlot (cons (vla-get-Name l) lockedlayersPlot))
    )
  )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
        (LM:ApplytoBlockObjects
            (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
           '(lambda ( obj / lin )
                (if (not (member (vla-get-layer obj) lockedLayersPlot)) (vla-put-layer obj "0"))
                (setq lin (strcase (vla-get-linetype obj)))
                (cond
                    (   (= "BYLAYER" lin))
                    (   (= "CONTINUOUS" lin)
                        (vla-put-linetype obj "BYLAYER")
                    )
                    (   t
                        (vla-put-linetype obj "HIDDEN")
                        (vla-put-linetypescale obj 1.0)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 6 of 19
pixelarch
in reply to: CADaSchtroumpf

Please see the error

 

; error: no function definition: LM:APPLYTOBLOCKOBJECTS

 

I tried with script beforeto lock defpoints layer. But when we lock layer we can not use APPLYTOBLOCKOBJECTS

 

I thinks this lisp have the same problem.

Message 7 of 19
CADaSchtroumpf
in reply to: pixelarch

Message 8 of 19
pixelarch
in reply to: CADaSchtroumpf

Yes. From Lee. But that thread got solution so no support anymore. That's reason i create new thread.

Message 9 of 19
CADaSchtroumpf
in reply to: pixelarch

If your code uses the function of Lee Mac (LM:ApplytoBlockObjects ...), you must have loaded it beforehand...
You can simply the integrer in your code in the single file, example of final file:

 

(defun c:test ( / lockedLayerPlot s )
;; Apply to Block Objects  -  Lee Mac
;; Evaluates a supplied function on all objects in a block definition.
;; Arguments:
;; blks - VLA Block Collection in which block resides
;; name - Block name
;; func - function to apply to all objects in block
;; Returns a list of results of evaluating the function, else nil.

(defun LM:ApplytoBlockObjects ( blks name func / def result )
    (setq func (eval func))
    (if (not (vl-catch-all-error-p (setq def (vl-catch-all-apply 'vla-item (list blks name)))))
        (vlax-for obj def (setq result (cons (func obj) result)))
    )
    (reverse result)
)

  (setq lockedLayerPlot '("Defpoints"))
  (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (= (vla-get-Plottable l) :vlax-false)
      (setq lockedLayersPlot (cons (vla-get-Name l) lockedlayersPlot))
    )
  )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
        (LM:ApplytoBlockObjects
            (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
           '(lambda ( obj / lin )
                (if (not (member (vla-get-layer obj) lockedLayersPlot)) (vla-put-layer obj "0"))
                (setq lin (strcase (vla-get-linetype obj)))
                (cond
                    (   (= "BYLAYER" lin))
                    (   (= "CONTINUOUS" lin)
                        (vla-put-linetype obj "BYLAYER")
                    )
                    (   t
                        (vla-put-linetype obj "HIDDEN")
                        (vla-put-linetypescale obj 1.0)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 10 of 19
Kent1Cooper
in reply to: pixelarch


@pixelarch wrote:

.... 

I got solution for that topic but now i need a liitle bit change as my latest comments in that topic. I dont want to change defpoint layer to layer 0.

....


Here's my take on it -- BEL0CL.lsp [= Block Entities to Layer 0 with Color & Linetype from entity's original layer].  Other suggestions here all seem to either require selection of one Block, or do it to all Block definitions in the drawing.  This lets you select as many Blocks as you want, and does it to all [and only] Block definitions among the selection.  No external routine is used.  It could use some of the usual bells and whistles that I haven't added in yet....

Kent Cooper, AIA
Message 11 of 19
jahbgd
in reply to: Kent1Cooper

Kent, 

 

would it be possible to extend this function to include nested blocks also?

 

thanks

Janko

Message 12 of 19
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

.... 

would it be possible to extend this function to include nested blocks also?

....


Never got around to this back then [I hope you're still watching...], but another recent thread got me going.  Here's BENL0CL.lsp [the N is for its including everything in Nested Blocks' definitions, too] with its eponymous command.  It has a few additional improvements over the earlier BEL0CL.lsp, mainly Undo begin/end wrapping.

Kent Cooper, AIA
Message 13 of 19
jahbgd
in reply to: Kent1Cooper

Kent,

 

Thanks, I will try it, although I have been using Edit_bloc by Gilles Chanteau. Is very helpful and has many options. Highly recommendable!

 

Anyway thanks for the effort!

 

Cheers

Message 14 of 19
jahbgd
in reply to: jahbgd

Although you can't leave out entities on defpoint layer.... 

Message 15 of 19
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

Although you can't leave out entities on defpoint layer.... 


Why not?  That's part of the intent -- see the Subject line.

Kent Cooper, AIA
Message 16 of 19
3wood
in reply to: jahbgd

With updated CHZ20.vlx, now you can set up rules to change all subentities to Layer 0 except for those on Layer Defpoints.

Rules as below, save it as a txt file and use "By file" option from "Put subentities to layer" to select the txt file as the matching rule file.

((8 . "defpoints"))  *Defpoints ;Remain objects on layer defpoints
("True")   *0  ;Change all other objects except above to Layer 0

 Settings as below:

chz20_7.PNG

 

 

Message 17 of 19
dsparkes
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@jahbgd wrote:

.... 

would it be possible to extend this function to include nested blocks also?

....


Never got around to this back then [I hope you're still watching...], but another recent thread got me going.  Here's BENL0CL.lsp [the N is for its including everything in Nested Blocks' definitions, too] with its eponymous command.  It has a few additional improvements over the earlier BEL0CL.lsp, mainly Undo begin/end wrapping.


Ressurecting older thread... now:

 

What would one have to change in order to NOT retain the layers color? Have everything be on layer 0 w/o inheriting the original layers color?

 

Thanks!

Message 18 of 19
Kent1Cooper
in reply to: dsparkes


@dsparkes wrote:
.... 

What would one have to change in order to NOT retain the layers color? Have everything be on layer 0 w/o inheriting the original layers color?

....


Remove or comment out this part:

(if
  (or ; [no Color override]
    (not (assoc 62 edata)); Bylayer
    (member '(62 . 0) edata); Byblock
  ); or
  (setq edata (append edata (list (assoc 62 ldata)))); then -- assign Layer's color
); if

 

If you also want things to not be given their original Layer's linetypes, similarly remove or comment out the entire (if) function that immediately follow the one above.

Kent Cooper, AIA
Message 19 of 19
dsparkes
in reply to: Kent1Cooper

Perfect, thanks Kent.

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

Post to forums  

Autodesk Design & Make Report

”Boost