Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Select Random throws error #197

Open
crowbait opened this issue Jun 23, 2021 · 3 comments
Open

[BUG] Select Random throws error #197

crowbait opened this issue Jun 23, 2021 · 3 comments

Comments

@crowbait
Copy link

Describe the bug
When adding Select Random, Blender throws an error and the node doesn't work.

To Reproduce

  1. Add geometry, for example "Create Icosphere"
  2. Add "Select Random"
  3. See error

Desktop (please complete the following information):

  • OS: Win10 x64 20H2 b.19042.1052
  • Blender Version: 2.93.0
  • Sorcar Version: 3.2.1

Output

Python: Traceback (most recent call last):
  File "C:\Users\fabia\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\sorcar\operators\ScExecuteNode.py", line 19, in execute
    curr_tree.execute_node()
  File "C:\Users\fabia\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\sorcar\tree\ScNodeTree.py", line 77, in execute_node
    if (not n.execute()):
  File "C:\Users\fabia\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\sorcar\nodes\_base\node_base.py", line 56, in execute
    self.functionality()
  File "C:\Users\fabia\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\sorcar\nodes\selection\ScSelectRandom.py", line 31, in functionality
    bpy.ops.mesh.select_random(
  File "E:\Blender 2.93\2.93\scripts\modules\bpy\ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties: : keyword "percent" unrecognized

location: <unknown location>:-1
@paulrobello
Copy link

Same error, OS and Sorcar Version. Using Blender V2.93.1

@Credomo
Copy link

Credomo commented Jul 31, 2021

Hello, problem occurs due to blender API evolution

API
https://docs.blender.org/api/current/bpy.ops.mesh.html

bpy.ops.mesh.select_random(ratio=0.5, seed=0, action='SELECT')
    Randomly select vertices
    Parameters
            ratio (float in [0, 1], (optional)) – Ratio, Portion of items to select randomly
            seed (int in [0, inf], (optional)) – Random Seed, Seed for the random number generator
            action (enum in ['SELECT', 'DESELECT'], (optional)) –
            Action, Selection action to execute
                SELECT Select, Select all elements.
                DESELECT Deselect, Deselect all elements.

Code evolution
C:\Users[user]\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\Sorcar-master\nodes\selection\ScSelectRandom.py

import bpy

from bpy.props import EnumProperty, IntProperty, FloatProperty
from bpy.types import Node
from .._base.node_base import ScNode
from .._base.node_selection import ScSelectionNode

class ScSelectRandom(Node, ScSelectionNode):
    bl_idname = "ScSelectRandom"
    bl_label = "Select Random"
    
    #in_percent: FloatProperty(default=50.0, min=0.0, max=100.0, update=ScNode.update_value)
    in_ratio: FloatProperty(default=0.5, min=0.0, max=1.0, update=ScNode.update_value)
    in_seed: IntProperty(default=0, min=0, update=ScNode.update_value)
    in_action: EnumProperty(items=[("SELECT", "Select", ""), ("DESELECT", "Deselect", "")], default="SELECT", update=ScNode.update_value)
    
    def init(self, context):
        super().init(context)
        #self.inputs.new("ScNodeSocketNumber", "Percent").init("in_percent", True)
        self.inputs.new("ScNodeSocketNumber", "Ratio").init("in_ratio", True)
        self.inputs.new("ScNodeSocketNumber", "Seed").init("in_seed", True)
        self.inputs.new("ScNodeSocketString", "Action").init("in_action", True)
    
    def error_condition(self):
        return(
            super().error_condition()
            #or (self.inputs["Percent"].default_value < 0 or self.inputs["Percent"].default_value > 100)
            or (self.inputs["Ratio"].default_value < 0 or self.inputs["Ratio"].default_value > 1)
            or self.inputs["Seed"].default_value < 0
            or (not self.inputs["Action"].default_value in ["SELECT", "DESELECT"])
        )
    
    def functionality(self):
        bpy.ops.mesh.select_random(
            #percent = self.inputs["Percent"].default_value,
            ratio = self.inputs["Ratio"].default_value,
            seed = int(self.inputs["Seed"].default_value),
            action = self.inputs["Action"].default_value
        )

@wyhinton
Copy link

Getting this error in blender 3.1.2 and sorcar 3.2.1
OS: Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants