# USDView Not Rendering PointInstancer Instances Immediately After Creation

**URL:** <https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation/619>\
**Category:** USD\
**Created:** [September 7, 2023, 6:49pm UTC](https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation/619 "2023-09-07T18:49:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nick](https://forum.aousd.org/u/Nick)\
**Post date:** [September 7, 2023, 6:49pm UTC](https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation/619/1 "2023-09-07T18:49:14Z")

</div>

Hello everyone,

I’ve been experimenting with the Python API in `usdview` to dynamically create a `PointInstancer` and set up a few instances. After setting up the `PointInstancer`, I noticed that the instances aren’t immediately visible in the viewer. However, if I save the stage to a USD file and then reopen that file in `usdview`, the instances render as expected.

Has anyone else experienced this issue? Is there a step or refresh command I might be missing to update the `usdview` renderer immediately after making these changes?

Any insights or suggestions would be greatly appreciated!

Thank you!

Minimal code to recreate:

```python
from pxr import Usd, UsdGeom, Gf

# Get the current stage from usdview
stage = usdviewApi.stage

# Create a new PointInstancer at the root of the stage
pointInstancer = UsdGeom.PointInstancer.Define(stage, '/myPointInstancer')

# Create a new Sphere as the prototype for the PointInstancer
sphereProto = UsdGeom.Sphere.Define(stage, '/myPointInstancer/sphereProto')

# Set the prototypes relationship on the PointInstancer to point to the Sphere
pointInstancer.GetPrototypesRel().AddTarget(sphereProto.GetPath())

# Set the positions for three instances of the sphere
positions = [
    Gf.Vec3f(0, 0, 0),
    Gf.Vec3f(2, 0, 0),
    Gf.Vec3f(4, 0, 0)
]
pointInstancer.GetPositionsAttr().Set(positions)

# Set the protoIndices for the three instances (all pointing to the single sphere prototype)
protoIndices = [0, 0, 0]
pointInstancer.GetProtoIndicesAttr().Set(protoIndices)

# Edit/update
# Required to render the PointInstancer after populating attributes
stage.GetEditTarget()

```

---

<div class="post-metadata">

**Author:** ![Nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nick](https://forum.aousd.org/u/Nick)\
**Post date:** [September 8, 2023, 1:36pm UTC](https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation/619/2 "2023-09-08T13:36:33Z")

</div>

I want to add that I am getting a user warning:

```auto
Point instancer /myPointInstancer does not have a valid 'prototypes' relationship. Not adding it to the render index.

```

This occurs at the line:

```auto
# Create a new PointInstancer at the root of the stage
pointInstancer = UsdGeom.PointInstancer.Define(stage, '/myPointInstancer')

```

How to add the point instancer to the render index after populating the required attributes?

Thanks!

Edit/Update: I found that simply adding ‘stage.GetEditTarget()’ after populating the required attributes is enough to trigger the updates to be rendered.

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [September 9, 2023, 8:52pm UTC](https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation/619/3 "2023-09-09T20:52:11Z")

</div>

I think this is a plain old bug. An empty `prototypes` relationship should only be considered invalid if the `protoIndices` attribute is **not** empty. Could you file an Issue, please?

In terms of (ugly) workaround, when you are done with your configuration of the new prim, first SetActive(False), and then ClearActive(). That should kick Hydra, I think.

---

<div class="post-metadata">

**Author:** ![Nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nick](https://forum.aousd.org/u/Nick)\
**Post date:** [September 10, 2023, 6:36pm UTC](https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation/619/4 "2023-09-10T18:36:56Z")

</div>

Thanks for the feedback Spiff. I created an issue, see link below.  
Nick

> <https://github.com/PixarAnimationStudios/OpenUSD/issues/2670>
>
> \### Description of Issue
> After configuring a new PointInstancer prim, I noticed… that the instances aren’t immediately visible in the viewer.
> \### Steps to Reproduce
> 1. Using UsdView python interpreter:
> \`\`\`python
> from pxr import Usd, UsdGeom, Gf
> 
> \# Get the current stage from usdview
> stage = usdviewApi.stage
> 
> \# Create a new PointInstancer at the root of the stage
> pointInstancer = UsdGeom.PointInstancer.Define(stage, '/myPointInstancer')
> 
> \# Create a new Sphere as the prototype for the PointInstancer
> sphereProto = UsdGeom.Sphere.Define(stage, '/myPointInstancer/sphereProto')
> 
> \# Set the prototypes relationship on the PointInstancer to point to the Sphere
> pointInstancer.GetPrototypesRel().AddTarget(sphereProto.GetPath())
> 
> \# Set the positions for three instances of the sphere
> positions = \[
> Gf.Vec3f(0, 0, 0),
> Gf.Vec3f(2, 0, 0),
> Gf.Vec3f(4, 0, 0)
> \]
> pointInstancer.GetPositionsAttr().Set(positions)
> 
> \# Set the protoIndices for the three instances (all pointing to the single sphere prototype)
> protoIndices = \[0, 0, 0\]
> pointInstancer.GetProtoIndicesAttr().Set(protoIndices)
> \`\`\`
> 
> In order to trigger the rendering as a workaround it has been suggested to deactivate/activate the pointinstancer prim.
> Conversation here:
> https://forum.aousd.org/t/usdview-not-rendering-pointinstancer-instances-immediately-after-creation
> 
> \### System Information (OS, Hardware)
> 
> \### Package Versions
> usd 23.02
> python 3.10
> 
> \### Build Flags
