TAGGED: ansys-spaceclaim, api, python
-
-
June 30, 2023 at 2:44 pmSterling ButtersSubscriberGreetings,ÂI am trying to "check the box" for a number of parts in the structure tree. Using the recording feature of the API, I get the ViewHelper.SetObjectVisibility class/method. Trying to apply this to my existing selection yields nothing though - code below. How can I toggle the parts based on my existing selection?Âselect_bodies = []for i_body in GetRootPart()GetComponents():ÂÂ Â if i_body.GetName().Equals("
"): Â Â Â Â select_bodies.append(i_body)Â# Change Object Visibilityselection = Selection.Create(select_bodies)visibility = VisibilityType.ShowinSelectedView = FalsefaceLevel = FalseViewHelper.SetObjectVisibility(selection, visibility, inSelectedView, faceLevel)# EndBlockÂ# Change Object Visibilityselection = Selection.Create(select_bodies)ViewHelper.HideOthers(selection)# EndBlock -
July 3, 2023 at 2:12 pmAniketForum Moderator  if i_body.GetName().Equals(""):    select_bodies.append(i_body) ÂÂAre you checking bodies with blank name?
-
July 3, 2023 at 6:50 pmmjmiddleAnsys Employee
There are several problems in that first section:
- You forgot a dot (".") between GetRootPart() and GetComponents()
- A body is not a component. Maybe this was just a naming convention you were using in your script, because you can turn on/off visibility of components the same way as bodies. But you could have just as well named your variable i_component instead of i_body to be more clear, but it's just a variable name. However, if you intended to get bodies, you can get all bodies this with GetRootPart().GetAllBodies(). Or to get a body within a component (1st component in this case), go through the "Content" object: GetRootPart().Components[0].Content.Bodies. To get a component by name: comp = GetRootPart().GetComponents(comp_name)[0].
- An Aniket mentioned, bodies in SpaceClaim cannot exist without a name, so searching for bodies with blank names is not a sensible strategy.
-
July 5, 2023 at 6:20 pmSterling ButtersSubscriber
@Aniket
Sorry, I did not clarify that I did not provide the body name (since it is variable/changing).Â
I was able to get it working with:
selection = Selection.Create([body for body in GetRootPart().GetAllBodies() if body.Parent.GetName() == ComponentName])
  visibility = VisibilityType.Show
  inSelectedView = False
  faceLevel = False
  ViewHelper.SetObjectVisibility(selection, visibility, inSelectedView, faceLevel)Which I think implements the logic suggested by @mjmiddle
Thanks!
-
Viewing 3 reply threads
- The topic ‘Python API: Setting object visibility from selection’ is closed to new replies.
Ansys Innovation Space
Trending discussions
- Unable to attach geometry 2024 R2
- Getting Mesh Faces With Specified Normal Via SpaceClaim Scripting (V241)
- How to provide blade angles in bladegen.
- DXF file loaded incorrectly
- plugin error failed to import assembly from spaceclaim
- Overlapping contact face
- Thermoelectric Cooler Model
- Temperature’s Distribution not available in Refine Mode ?
- Issue Seeing Explore
- SpaceClaim stops sharing topology
Top Contributors
-
1301
-
591
-
544
-
524
-
366
Top Rated Tags
© 2025 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.