Particles python access is broken in 2.8 #58792

Closed
opened 2018-12-05 14:37:14 +01:00 by lucas veber · 14 comments

Win10
Gtx 580

Blender 2.8 Beta and latest daily build

Accessing the particle_systems.particlesproperty is broken in Blender 2.8

  • Open the attached file
    bug_particles.blend

  • It contains a cube with one particle system

  • Press Run Script to print the numbers of particles of this system via python, in the console

  • It returns 0 particles

Win10 Gtx 580 Blender 2.8 Beta and latest daily build Accessing the **particle_systems.particles**property is broken in Blender 2.8 - Open the attached file [bug_particles.blend](https://archive.blender.org/developer/F5834097/bug_particles.blend) - It contains a cube with one particle system - Press Run Script to print the numbers of particles of this system via python, in the console - It returns 0 particles
Author

Added subscriber: @LucasVeber

Added subscriber: @LucasVeber

#62837 was marked as duplicate of this issue

#62837 was marked as duplicate of this issue
Author

Evaluating the depsgraph first seems to fix it:

ob = bpy.context.active_object
eval_ob = bpy.context.depsgraph.objects.get(ob.name, None)
ps = eval_ob.particle_systems[0]

However not sure it's the correct approach, maybe it should be made obvious for users?

Evaluating the depsgraph first seems to fix it: ``` ob = bpy.context.active_object eval_ob = bpy.context.depsgraph.objects.get(ob.name, None) ps = eval_ob.particle_systems[0] ``` However not sure it's the correct approach, maybe it should be made obvious for users?
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev

Added subscriber: @nantille

Added subscriber: @nantille

Thanks Lucas for the code! It helps to at least have that.

Thanks Lucas for the code! It helps to at least have that.
Member

Added subscribers: @mont29, @Sergey, @lichtwerk

Added subscribers: @mont29, @Sergey, @lichtwerk
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Philipp Oeser self-assigned this 2019-01-22 15:07:22 +01:00
Member

There is a similar case in blender/blender-addons#60083.

Quoting from there:

In blender/blender-addons#60083#596434, @Sergey wrote:
From predictability point of view using an explicit evaluation object from a script will be preferable solution: this eliminates possibility of system silently switching to an object instance which you don't intent to. Points are:

  • Access to any ID field should be following one rule (as in, it shouldn't be reading some fields from given ID and other fields from an evaluated ID).
  • Scripts need to be able to read write fields which are considered inputs for evaluation.
    So from this point of view i am in favor of leaving it up to script to decide what ID to access.

In blender/blender-addons#60083#600524, @mont29 wrote:
Yes, totally agree with @Sergey here. We do have a few helpers (like for raycast) where is sort of make sense to implicitly get the evaluated data from context's depsgraph, but think this should remain an exception (and a documented one).

So the solution @LucasVeber posted is the preferred and correct one.
Guess this can be closed then...

There is a similar case in blender/blender-addons#60083. Quoting from there: > In blender/blender-addons#60083#596434, @Sergey wrote: > From predictability point of view using an explicit evaluation object from a script will be preferable solution: this eliminates possibility of system silently switching to an object instance which you don't intent to. Points are: > - Access to any ID field should be following one rule (as in, it shouldn't be reading some fields from given ID and other fields from an evaluated ID). > - Scripts need to be able to read write fields which are considered inputs for evaluation. > So from this point of view i am in favor of leaving it up to script to decide what ID to access. > In blender/blender-addons#60083#600524, @mont29 wrote: > Yes, totally agree with @Sergey here. We do have a few helpers (like for raycast) where is sort of make sense to implicitly get the evaluated data from context's depsgraph, but think this should remain an exception (and a documented one). So the solution @LucasVeber posted is the preferred and correct one. Guess this can be closed then...
Member

Added subscriber: @BlenderTim

Added subscriber: @BlenderTim

Added subscriber: @georgK

Added subscriber: @georgK

Does this still apply? I changed the code in the attached blend to

import bpy

ob = bpy.context.active_object
eval_ob = bpy.context.depsgraph.objects.get(ob.name, None)
ps = eval_ob.particle_systems[0]

print(len(ps.particles))

But I get "AttributeError: 'Context' object has no attribute 'depsgraph'" - am I doing something wrong?

Does this still apply? I changed the code in the attached blend to ``` import bpy ob = bpy.context.active_object eval_ob = bpy.context.depsgraph.objects.get(ob.name, None) ps = eval_ob.particle_systems[0] print(len(ps.particles)) ``` But I get "AttributeError: 'Context' object has no attribute 'depsgraph'" - am I doing something wrong?

@georgK, the API has been changed in e693918d40: to access dependency graph use context.evaluated_depsgraph_get().
The API docs will be updated soon.

@georgK, the API has been changed in e693918d40: to access dependency graph use `context.evaluated_depsgraph_get()`. The API docs will be updated soon.

Thank you!

Thank you!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#58792
No description provided.