How can I assign a material to multiple bodies in Spaceclaim?
Gabriel Messager
Member, Employee Posts: 56
✭✭✭✭
How can I assign a material to multiple bodies in Spaceclaim?
The material can be in the Local Materials or in the Library
Tagged:
0
Comments
-
material_name = "Gray Cast Iron" succ_local, local_mat = Window.ActiveWindow.Document.Materials.TryGetValue(material_name) if not succ_local: succ, mat = LibraryMaterial.Library.TryGetValue(material_name) local_mat = DocumentMaterial.Copy(Window.ActiveWindow.Document, mat) for body in GetRootPart().GetAllBodies(): body2.Material = local_mat
1 -
@Gabriel Messager , the LibraryMaterial and DocumentMaterial libraries are available if accessed using SC release's API. For example, for V20:
material_name = "Gray Cast Iron"
succ_local, local_mat = Window.ActiveWindow.Document.Materials.TryGetValue(material_name)
if not succ_local:
succ, mat = SpaceClaim.Api.V20.LibraryMaterial.Library.TryGetValue(material_name)
local_mat = SpaceClaim.Api.V20.DocumentMaterial.Copy(Window.ActiveWindow.Document, mat)
for body in GetRootPart().GetAllBodies():
body.Material = local_mat1 -
Thank you Nikos - that works perfect for v22 and v23 also - as you pointed out, one just needs to change as needed the version say from V20 to V22 etc.
SpaceClaim.Api.V22.LibraryMaterial.Library.TryGetValue
SpaceClaim.Api.V22.DocumentMaterial.Copy1