通过 API 使用外观资源创建材质
Creating Materials Via API With Appearance Asset
我有一个带有 RGB 值的 CSV 文件,我用它通过 Dynamo Python 脚本在 Revit 中创建材质,但是创建的材质没有分配给它的 AppearanceAsset(即使它有一个外观asset tab}。因为当我得到 Material 的 AppearanceAssetID 时,它 Returns '-1' 根据 API 意味着没有分配给它的资产。
如何创建已分配外观 ID 的材质
我想访问 Appearance 资产并为其设置颜色,因为通常只设置 graphics 颜色而不设置 appearance 颜色.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
def ToRevitColor(dynamoColor):return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)
def ToDynamoObject(revitObject, isRevitOwned=False):return revitObject.ToDSType(isRevitOwned)
doc = DocumentManager.Instance.CurrentDBDocument
newMaterials = []
appassetid = []
TransactionManager.Instance.EnsureInTransaction(doc)
mat_name = IN[0]
color = IN[1]
for i,y in zip (mat_name, color):
new_mat_id = Material.Create(doc, i)
new_mat = doc.GetElement(new_mat_id)
new_mat.Color = ToRevitColor(y)
newMaterials.append(ToDynamoObject(new_mat))
appassetid.append(new_mat.AppearanceAssetId)
TransactionManager.Instance.TransactionTaskDone()
OUT = newMaterials,appassetid
http://www.revitapidocs.com/2018.1/d02d0677-341a-8d1a-d3eb-35ff82f01695.htm
API参考
此问题已在 Revit API 论坛 creating materials With appearance asset 中得到圆满解决和确认。
我有一个带有 RGB 值的 CSV 文件,我用它通过 Dynamo Python 脚本在 Revit 中创建材质,但是创建的材质没有分配给它的 AppearanceAsset(即使它有一个外观asset tab}。因为当我得到 Material 的 AppearanceAssetID 时,它 Returns '-1' 根据 API 意味着没有分配给它的资产。
如何创建已分配外观 ID 的材质
我想访问 Appearance 资产并为其设置颜色,因为通常只设置 graphics 颜色而不设置 appearance 颜色.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
def ToRevitColor(dynamoColor):return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)
def ToDynamoObject(revitObject, isRevitOwned=False):return revitObject.ToDSType(isRevitOwned)
doc = DocumentManager.Instance.CurrentDBDocument
newMaterials = []
appassetid = []
TransactionManager.Instance.EnsureInTransaction(doc)
mat_name = IN[0]
color = IN[1]
for i,y in zip (mat_name, color):
new_mat_id = Material.Create(doc, i)
new_mat = doc.GetElement(new_mat_id)
new_mat.Color = ToRevitColor(y)
newMaterials.append(ToDynamoObject(new_mat))
appassetid.append(new_mat.AppearanceAssetId)
TransactionManager.Instance.TransactionTaskDone()
OUT = newMaterials,appassetid
http://www.revitapidocs.com/2018.1/d02d0677-341a-8d1a-d3eb-35ff82f01695.htm
API参考
此问题已在 Revit API 论坛 creating materials With appearance asset 中得到圆满解决和确认。