Jump to content
kimmmmm

change layer with specific linetype inside blocks

Recommended Posts

kimmmmm
Posted (edited)

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

Share this post


Link to post
Share on other sites
Lee Mac

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

Share this post


Link to post
Share on other sites
kimmmmm
Posted (edited)

thank you so much .🥰😭

DASHED have to be changed layer [HIDDEN]

layer with line type DSHED change to DASHED.

 

Edited by kimmmmm

Share this post


Link to post
Share on other sites
Lee Mac
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)

 

Share this post


Link to post
Share on other sites
kimmmmm

This is perfect. I can dance now🥰💃🕺

 

Thanks a lot. It was lisp I had been searching for a long time

 

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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