Jump to content

change layer with specific linetype inside blocks


kimmmmm

Recommended Posts

hi. 

first of all,i don't know about lisp. really beginer

i found some lisp and changed some command

but i want to change layer inside blocks

could you please give me  advice ?

or does someone have lisp for changing layer inside blocks? 

 

(DEFUN C:lll ()
(setvar "cmdecho" 1)
   (setq olderr *error*
         *error* CHGTERR)
  (if (tblsearch "ltype" "DASHED")
                (progn
    (command "._chprop" (ssget "X" '((6 . "DASHED"))) ""  "LT" "ByLayer" "s" "0.2" "la" "HIDDEN" "")
   );end progn
  );end if
;
(if (tblsearch "ltype" "CENTER")
                (progn
    (command "._chprop" (ssget "X" '((6 . "CENTER"))) ""  "LT" "ByLayer" "s" "0.2" "la" "CENTER" "")
   );end progn
  );end if
;
(if (tblsearch "ltype" "PHANTOM")
                (progn
    (command "._chprop" (ssget "X" '((6 . "PHANTOM"))) ""  "LT" "ByLayer" "s" "0.2" "la" "PHANTOM" "")
   );end progn
  );end if
;
(if (tblsearch "ltype" "CONTINUOUS")
                (progn
    (command "._chprop" (ssget "X" '((6 . "CONTINUOUS"))) ""  "LT" "ByLayer" "s" "0.2" "la" "0" "")
   );end progn
  );end if
;
(COMMAND "-PURGE" "ALL" "" "N")
(COMMAND "REGEN")
;
);END DEFUN

 

Edited by kimmmmm
Link to comment
Share on other sites

When operating on objects nested within block definitions in addition to primary objects, it typically becomes easier to iterate over the ActiveX Block Collection, e.g.:

(defun c:fixlay ( / doc lay lst ltp lyr )
    (setq lst
       '(
            "DASHED"
            "CENTER"
            "PHANTOM"
        )
    )
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
          lyr (vla-get-layers doc)
    )
    (vlax-for blk (vla-get-blocks doc)
        (if (= :vlax-false (vla-get-isxref blk))
            (vlax-for obj blk
                (if (and (member (setq ltp (strcase (vla-get-linetype obj))) lst)
                         (vlax-write-enabled-p obj)
                         (or (member ltp lay)
                             (and (vla-add lyr ltp)
                                  (setq lay (cons ltp lay))
                             )
                         )
                    )
                    (progn
                        (vla-put-linetype obj "bylayer")
                        (vla-put-linetypescale obj 0.2)
                        (vla-put-layer obj ltp)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

  • Like 2
Link to comment
Share on other sites

thank you so much .🥰😭

DASHED have to be changed layer [HIDDEN]

layer with line type DSHED change to DASHED.

 

Edited by kimmmmm
Link to comment
Share on other sites

16 hours ago, kimmmmm said:

thank you so much .🥰😭

DASHED have to be changed layer [HIDDEN]

layer with line type DSHED change to DASHED.

 

You're welcome :)

 

To account for cases in which the target layer differs from the source linetype, consider the following:

(defun c:fixlay ( / doc itm lay lst lyr )
    (setq lst
       '(
        ;;   Source Linetype    Target Layer
            ("DASHED"           "HIDDEN" )
            ("CENTER"           "CENTER" )
            ("PHANTOM"          "PHANTOM")
        )
    )
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
          lyr (vla-get-layers doc)
    )
    (vlax-for blk (vla-get-blocks doc)
        (if (= :vlax-false (vla-get-isxref blk))
            (vlax-for obj blk
                (if (and (setq itm (cadr (assoc (strcase (vla-get-linetype obj)) lst)))
                         (vlax-write-enabled-p obj)
                         (or (member itm lay)
                             (and (vla-add lyr itm)
                                  (setq lay (cons itm lay))
                             )
                         )
                    )
                    (progn
                        (vla-put-linetype obj "bylayer")
                        (vla-put-linetypescale obj 0.2)
                        (vla-put-layer obj itm)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...

hello.Lee MAC.

I need your help one more time. please

It was helpful that you made this lisp. 

and I wonder that it is possible to change the layer of the selected block ? not all of layer.

 

Link to comment
Share on other sites

Lee can be very busy but if you want to ask him direct then go to his web site www.Lee-Mac.com and contact him there.

 

Else 

 

"I have this great lisp done by lee-mac and I  wonder that it is possible to change the layer of the selected block ? not all of layer."

Edited by BIGAL
Link to comment
Share on other sites

Try something like this (untested):
 

(defun c:fixlay ( / blk def doc ent itm lay lst lyr obj )
    (setq lst
       '(
        ;;   Source Linetype    Target Layer
            ("DASHED"           "HIDDEN" )
            ("CENTER"           "CENTER" )
            ("PHANTOM"          "PHANTOM")
        )
    )
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
          lyr (vla-get-layers doc)
          blk (vla-get-blocks doc)
    )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect block: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
                    (princ "\nThe selected object is not a block.")
                )
                (   (progn
                        (setq obj (vlax-ename->vla-object ent)
                              def (vla-item blk (vlax-get-property obj (if (vlax-property-available-p obj 'effectivename) 'effectivename 'name)))
                        )
                        (= :vlax-true (vla-get-isxref def))
                    )
                    (princ "\nThe selected block is an external reference.")
                )
                (   t
                    (vlax-for obj def
                        (if (and (setq itm (cadr (assoc (strcase (vla-get-linetype obj)) lst)))
                                 (vlax-write-enabled-p obj)
                                 (or (member itm lay)
                                     (and (vla-add lyr itm)
                                          (setq lay (cons itm lay))
                                     )
                                 )
                            )
                            (progn
                                (vla-put-linetype obj "bylayer")
                                (vla-put-linetypescale obj 0.2)
                                (vla-put-layer obj itm)
                            )
                        )
                    )
                    (vla-regen doc acactiveviewport)
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Link to comment
Share on other sites

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...