How can I assign a material to multiple bodies in Spaceclaim?

Gabriel Messager
Gabriel Messager Member, Employee Posts: 54
Ansys Employee First Anniversary Name Dropper 5 Likes
✭✭✭✭
edited June 2023 in 3D Design

How can I assign a material to multiple bodies in Spaceclaim?

The material can be in the Local Materials or in the Library


Comments

  • Gabriel Messager
    Gabriel Messager Member, Employee Posts: 54
    Ansys Employee First Anniversary Name Dropper 5 Likes
    ✭✭✭✭
    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
    
  • Nikos Kallitsis
    Nikos Kallitsis Member, Employee Posts: 34
    First Anniversary 5 Likes 10 Comments Photogenic
    ✭✭✭✭

    @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_mat

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 202
    50 Answers 100 Comments Photogenic 5 Likes
    ✭✭✭✭
    edited April 19

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