Jump to content

Layer transperency in AutoLISP


zwonko

Recommended Posts

trying to set many layers transperency by autolisp. Is it another way or it only possible by "command". Part of sample code:

 

  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (wcmatch (vla-get-name layer) "*|*")
      (progn
        (command "_-LAYER" "_TR" "35" (vla-get-name layer) "")
      )
    )
    (if (wcmatch (vla-get-name layer) "*map*|*")
      (progn
        (command "_-LAYER" "_TR" "55" (vla-get-name layer) "")
      )
    )
  )

 

The code is finding xref layers and setting the transperency, but it is slow.

Link to comment
Share on other sites

Why not just:

(command "_.-layer" "_tr" "35" "*|*" "_tr" "55" "*map*|*" "")

 

Edited by Lee Mac
  • Like 2
Link to comment
Share on other sites

Command always takes a second to run. so if you had about 50 layers that match the wcmatch its setting the first transparency to 35. then if it maches the 2nd wcmatch it then changes to 55 trans.  this means it could take 50 to 100 seconds. using a cond function and swapping the order it would only execute the correct transparency on the layer.

 

Lee's way works because its running the command once rather then 50 to 100 times. Tho I try and stay away from using command. if you don't want 100 lines of spam to the command prompt you have to set cmdecho to 0 then back after,  also has a higher potential to error.

 

this should work for autocad.  might also have to throw in a regen to take effect.

 

(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  (cond
    ((wcmatch (vla-get-name layer) "*map*|*")
      (setpropertyvalue layer "Transparency" 55)
    )
    ((wcmatch (vla-get-name layer) "*|*")
      (setpropertyvalue layer "Transparency" 35)
    )
  )
)

 

 

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

WoW! @Lee Mac approach is fast. One thing and it is hundreads time faster. Tahnk You!
@mhupp also thanks for You! problem is that I'm using ZWCAD which is lack of setpropertyvalue in LISP

Link to comment
Share on other sites

You're welcome @zwonko - whilst repeated calls to a command within a loop may be slow, the internal operations performed by commands are implemented in C++ and so will outstrip LISP when it comes to iterating over a collection and performing an operation on many items.

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