我们需要一份所有可能材料的清单。
- 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
- Sub AddMaterialToLibrary()
- ' This example finds the name of the block associated with a layout.
- Dim material As acadMaterial
- Dim count As Integer
- count = 0
- For Each material In ThisDrawing.Materials
-
- If (StrComp(material.Name, "Bamboo", vbTextCompare) = 0) Then
- MsgBox "The Bamboo material Exists"
- count = count + 1
- Exit For
- End If
- Next
-
- If (count < 1) Then
- ThisDrawing.Materials.Add ("Bamboo")
- End If
- MsgBox "Done"
- End Sub
|