VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add Material/ Texture For Object by VBA

1 REPLY 1
Reply
Message 1 of 2
Anonymous
1341 Views, 1 Reply

Add Material/ Texture For Object by VBA

Hi.

 

I try to figure out the VBA's code to apply material for each part object in my this drawing. 

 

Of course, I can do it manually, but I would like to run a code to apply multiple file to save time. 

 

Can anyone help me code VBA for it? Thanks.

 

1.png

1 REPLY 1
Message 2 of 2
norman.yuan
in reply to: Anonymous

All AutoCAD entity object (AcadLine, AcadSolid, AcadSurface, AcadCircle, or more generic AcadEntity) as a string property "Material". So, to set a material to an AcadEntity, simply set this property to a valid AcadMaterial's name. Sample code:

 

Option Explicit

Public Sub test()

    Dim mat As AcadMaterial
    Dim matName As String
    For Each mat In ThisDrawing.Materials
        ''MsgBox mat.Name
        If UCase(mat.Name) = "SITEWORK.PLANTING.GRASS.SHORT" Then
            matName = mat.Name
            Exit For
        End If
    Next
    
    If Len(matName) > 0 Then
        Dim ent As AcadEntity
        For Each ent In ThisDrawing.ModelSpace
            If TypeOf ent Is AcadSolid Then
                ent.Material = matName
            End If
        Next
    End If

End Sub

Norman Yuan

Drive CAD With Code

EESignature

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report