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

Options
Gabriel Messager
Gabriel Messager Member, Employee Posts: 50
5 Likes Name Dropper First Anniversary Ansys Employee
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: 50
    5 Likes Name Dropper First Anniversary Ansys Employee
    Options
    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: 24
    First Anniversary First Comment Ansys Employee Name Dropper
    Options

    @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: 124
    First Answer Name Dropper First Anniversary Ansys Employee
    edited April 19
    Options

    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