Jump to content

Recommended Posts

Posted

I'm trying to write some simple code that can change the transparency of a material. It seems this shouldn't be too hard but I can't find a way. Any help would be appreciated.

Posted (edited)

Here is the link that was posted in a previous thread about materials. The dxf code that you would be looking for is OPACITY.

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-DXF/files/GUID-E540C5BB-E166-44FA-B36C-5C739878B272-htm.html

 

Here is a QUICK snippet of code to change that transparency. Many of the folks could on here could write this more elegantly, but this is a quick and dirty get the job done sort of code.

 

(defun c:mattrans ()
 (setq tr (/ (getreal "\nEnter Transparancy: ") 100))
 (setq mats (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'Materials))
 (setq data (entget (vlax-vla-object->ename (vla-item mats "Glass2")))); Replace Glass2 is the name of your material
 (setq trx (assoc 140 data))
 (setq data (vl-remove trx data))
 (setq elist (append data (list (cons 140 tr))))
 (entmod elist)
 (princ)
 )

 

I hope this at least gets you going.

 

regards,

 

Hippe013

 

P.S. The Value for transparency should be between 0 and 100. When it is placed in the elist it should be a value between 0 and 1.

Edited by Hippe013
P.S.
Posted

Hippe013 could you not just use something like (vla-put-(vla-item mats "Glass2") tr) not tested 1 line v's 4

Posted

Bigal,

The only way I've seen to edit a material via lisp is through entmod. I can't see any properties available through VL properties and methods. I wish! That would make things a lot easier. Please remember that the code I posted was a quick and dirty way of doing things.

Posted

Thanks Hippe013! That was exactly what I needed. I'm proficient in autolisp but very new to the vlisp functions so it will take me time to understand how that works. Thanks for your code.

Posted

bcdrane42,

I can explain what is going on with the vlisp side of things.

 

The following:

 

(setq mats (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'Materials))

 

Can be written as Follows:

 

(setq acad (vlax-get-acad-object));Get the acad application object
(setq ad (vlax-get-property acad 'ActiveDocument));Get the Active Document from the acad object
(setq mats (vlax-get-property ad 'Materials));Get the Materials Collection from the Active Document

 

vla-item simply returns object from a collection.

vlax-vla-object->ename returns the entity name of a given vla-object

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