How to modify the color property of beams and surfaces from script

Options
riccardoPD
riccardoPD Member Posts: 4
First Comment

Hello,
I'm using SpaceClaim 2021 R1 with python interpreter V19
I need to change the color property of beams and surfaces, in particular beams, but I couldn't find a way.
I tried recording the operation to get the snippet code but, when I change the color, it doesn't record anything.
I hope someone have already found out a way

Tagged:

Answers

  • Gabriel Messager
    Gabriel Messager Member, Employee Posts: 54
    5 Likes Name Dropper First Anniversary Ansys Employee
    edited September 2023
    Options

    Hi Riccardo,

    Below is a script to color beam and surface bodies. (same color if same cross section for beams, same color if same thickness for surfaces).

    Python Script, API Version = V19

    from SpaceClaim.Api.V19 import PartType
    
    beam_profiles = {}
    thickness = {}
    color=[ColorHelper.Magenta,ColorHelper.Blue,ColorHelper.Cyan,ColorHelper.Red,ColorHelper.Azure] # Il faut au minimum autant de couleurs dans la liste que d'épaisseur ou de profil différent
    
    ########  BEAM ########
    i=0
    for item in GetRootPart().Components:
        part = item.Content.GetMaster()
        if part.Type == PartType.BeamProfile:
            beam_profiles[part]=color[i]
            i+=1
    
    for beam in GetRootPart().GetDescendants[IBeam]():
        ColorHelper.SetColor(Selection.Create(beam), SetColorOptions(), beam_profiles.get(beam.GetMaster().SectionSource))
    
    #########  BEAM2 ########
    #i=0
    #for beam in GetRootPart().GetDescendants[IBeam]():
    #    sect=beam.GetMaster().SectionSource
    #    if beam_profiles.has_key(sect)==False:
    #                beam_profiles[sect]=color[i]
    #                i+=1
    #    ColorHelper.SetColor(Selection.Create(beam), SetColorOptions(), beam_profiles.get(beam.GetMaster().SectionSource))
    
    
    ########  SURFACE ########
    i=0
    for body in GetRootPart().GetAllBodies():
            if body.Master.Shape.IsClosed==False:  #ne fonctionne que si tous les corps sont placés dans des components
                thick=body.GetMidSurfaceAspect().GetThickness()
                if thickness.has_key(thick)==False:
                    thickness[thick]=color[i] 
                    i+=1
                ColorHelper.SetColor(Selection.Create(body), SetColorOptions(), thickness.get(thick))
    
  • riccardoPD
    riccardoPD Member Posts: 4
    First Comment
    Options

    Thanks!