IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Problème tests Python dans blender


Sujet :

Python

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Enseignant
    Inscrit en
    Février 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2014
    Messages : 1
    Par défaut Problème tests Python dans blender
    Bonjour,
    J'utilise blender 2.75 sur windows 7 64bits.
    J'ai récupéré un programme pour tester la programmation en python, et lorsque je tente de le run sur blender, rien ne se passe dans la console.
    J'ai essayé de le run sous Python 3.4.2 Shell, et la console me renvoie
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Traceback (most recent call last):
      File "C:\Python34\essais-tests\test.py", line 20, in <module>
        import bpy
    ImportError: No module named 'bpy'
    Je ne comprends pas, je vous transmets le code test.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
     
    # ##### BEGIN GPL LICENSE BLOCK #####
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation; either version 2
    #  of the License, or (at your option) any later version.
    #
    #  This program is distributed in the hope that it will be useful,
    #  but WITHOUT ANY WARRANTY; without even the implied warranty of
    #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #  GNU General Public License for more details.
    #
    #  You should have received a copy of the GNU General Public License
    #  along with this program; if not, write to the Free Software Foundation,
    #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # ##### END GPL LICENSE BLOCK #####
     
    # <pep8 compliant>
    import bpy
    from bpy.types import Menu, Panel, UIList
    from rna_prop_ui import PropertyPanel
     
     
    class MESH_MT_vertex_group_specials(Menu):
        bl_label = "Vertex Group Specials"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            layout.operator("object.vertex_group_sort", icon='SORTALPHA', text="Sort by Name").sort_type = 'NAME'
            layout.operator("object.vertex_group_sort", icon='ARMATURE_DATA', text="Sort by Bone Hierarchy").sort_type = 'BONE_HIERARCHY'
            layout.operator("object.vertex_group_copy", icon='COPY_ID')
            layout.operator("object.vertex_group_copy_to_linked", icon='LINK_AREA')
            layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA')
            layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT').use_topology = False
            layout.operator("object.vertex_group_mirror", text="Mirror Vertex Group (Topology)", icon='ARROW_LEFTRIGHT').use_topology = True
            layout.operator("object.vertex_group_remove_from", icon='X', text="Remove from All Groups").use_all_groups = True
            layout.operator("object.vertex_group_remove_from", icon='X', text="Clear Active Group").use_all_verts = True
            layout.operator("object.vertex_group_remove", icon='X', text="Delete All Groups").all = True
            layout.separator()
            layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All").action = 'LOCK'
            layout.operator("object.vertex_group_lock", icon='UNLOCKED', text="UnLock All").action = 'UNLOCK'
            layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock Invert All").action = 'INVERT'
     
     
    class MESH_MT_shape_key_specials(Menu):
        bl_label = "Shape Key Specials"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
            layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
            layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT').use_topology = False
            layout.operator("object.shape_key_mirror", text="Mirror Shape Key (Topology)", icon='ARROW_LEFTRIGHT').use_topology = True
            layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix").from_mix = True
            layout.operator("object.shape_key_remove", icon='X', text="Delete All Shapes").all = True
            layout.operator("object.shape_key_move", icon='TRIA_UP_BAR', text="Move To Top").type = 'TOP'
            layout.operator("object.shape_key_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").type = 'BOTTOM'
     
     
    class MESH_UL_vgroups(UIList):
        def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
            # assert(isinstance(item, bpy.types.VertexGroup))
            vgroup = item
            if self.layout_type in {'DEFAULT', 'COMPACT'}:
                layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
                icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
                layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
            elif self.layout_type == 'GRID':
                layout.alignment = 'CENTER'
                layout.label(text="", icon_value=icon)
     
     
    class MESH_UL_shape_keys(UIList):
        def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
            # assert(isinstance(item, bpy.types.ShapeKey))
            obj = active_data
            # key = data
            key_block = item
            if self.layout_type in {'DEFAULT', 'COMPACT'}:
                split = layout.split(0.66, False)
                split.prop(key_block, "name", text="", emboss=False, icon_value=icon)
                row = split.row(align=True)
                if key_block.mute or (obj.mode == 'EDIT' and not (obj.use_shape_key_edit_mode and obj.type == 'MESH')):
                    row.active = False
                if not item.id_data.use_relative:
                    row.prop(key_block, "frame", text="", emboss=False)
                elif index > 0:
                    row.prop(key_block, "value", text="", emboss=False)
                else:
                    row.label(text="")
                row.prop(key_block, "mute", text="", emboss=False)
            elif self.layout_type == 'GRID':
                layout.alignment = 'CENTER'
                layout.label(text="", icon_value=icon)
     
     
    class MESH_UL_uvmaps_vcols(UIList):
        def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
            # assert(isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer)))
            if self.layout_type in {'DEFAULT', 'COMPACT'}:
                layout.prop(item, "name", text="", emboss=False, icon_value=icon)
                icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
                layout.prop(item, "active_render", text="", icon=icon, emboss=False)
            elif self.layout_type == 'GRID':
                layout.alignment = 'CENTER'
                layout.label(text="", icon_value=icon)
     
     
    class MeshButtonsPanel:
        bl_space_type = 'PROPERTIES'
        bl_region_type = 'WINDOW'
        bl_context = "data"
     
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            return context.mesh and (engine in cls.COMPAT_ENGINES)
     
     
    class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
        bl_label = ""
        bl_options = {'HIDE_HEADER'}
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            ob = context.object
            mesh = context.mesh
            space = context.space_data
     
            if ob:
                layout.template_ID(ob, "data")
            elif mesh:
                layout.template_ID(space, "pin_id")
     
     
    class DATA_PT_normals(MeshButtonsPanel, Panel):
        bl_label = "Normals"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            mesh = context.mesh
     
            split = layout.split()
     
            col = split.column()
            col.prop(mesh, "use_auto_smooth")
            sub = col.column()
            sub.active = mesh.use_auto_smooth and not mesh.has_custom_normals
            sub.prop(mesh, "auto_smooth_angle", text="Angle")
     
            split.prop(mesh, "show_double_sided")
     
     
    class DATA_PT_texture_space(MeshButtonsPanel, Panel):
        bl_label = "Texture Space"
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            mesh = context.mesh
     
            layout.prop(mesh, "texture_mesh")
     
            layout.separator()
     
            layout.prop(mesh, "use_auto_texspace")
            row = layout.row()
            row.column().prop(mesh, "texspace_location", text="Location")
            row.column().prop(mesh, "texspace_size", text="Size")
     
     
    class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
        bl_label = "Vertex Groups"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
     
        def draw(self, context):
            layout = self.layout
     
            ob = context.object
            group = ob.vertex_groups.active
     
            rows = 2
            if group:
                rows = 4
     
            row = layout.row()
            row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
     
            col = row.column(align=True)
            col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
            col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
            col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
            if group:
                col.separator()
                col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
                col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
     
            if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
                row = layout.row()
     
                sub = row.row(align=True)
                sub.operator("object.vertex_group_assign", text="Assign")
                sub.operator("object.vertex_group_remove_from", text="Remove")
     
                sub = row.row(align=True)
                sub.operator("object.vertex_group_select", text="Select")
                sub.operator("object.vertex_group_deselect", text="Deselect")
     
                layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
     
     
    class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
        bl_label = "Shape Keys"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
     
        def draw(self, context):
            layout = self.layout
     
            ob = context.object
            key = ob.data.shape_keys
            kb = ob.active_shape_key
     
            enable_edit = ob.mode != 'EDIT'
            enable_edit_value = False
     
            if ob.show_only_shape_key is False:
                if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
                    enable_edit_value = True
     
            row = layout.row()
     
            rows = 2
            if kb:
                rows = 4
            row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
     
            col = row.column()
     
            sub = col.column(align=True)
            sub.operator("object.shape_key_add", icon='ZOOMIN', text="").from_mix = False
            sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="").all = False
            sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
     
            if kb:
                col.separator()
     
                sub = col.column(align=True)
                sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
                sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
     
                split = layout.split(percentage=0.4)
                row = split.row()
                row.enabled = enable_edit
                row.prop(key, "use_relative")
     
                row = split.row()
                row.alignment = 'RIGHT'
     
                sub = row.row(align=True)
                sub.label()  # XXX, for alignment only
                subsub = sub.row(align=True)
                subsub.active = enable_edit_value
                subsub.prop(ob, "show_only_shape_key", text="")
                sub.prop(ob, "use_shape_key_edit_mode", text="")
     
                sub = row.row()
                if key.use_relative:
                    sub.operator("object.shape_key_clear", icon='X', text="")
                else:
                    sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
     
                if key.use_relative:
                    if ob.active_shape_key_index != 0:
                        row = layout.row()
                        row.active = enable_edit_value
                        row.prop(kb, "value")
     
                        split = layout.split()
     
                        col = split.column(align=True)
                        col.active = enable_edit_value
                        col.label(text="Range:")
                        col.prop(kb, "slider_min", text="Min")
                        col.prop(kb, "slider_max", text="Max")
     
                        col = split.column(align=True)
                        col.active = enable_edit_value
                        col.label(text="Blend:")
                        col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
                        col.prop_search(kb, "relative_key", key, "key_blocks", text="")
     
                else:
                    layout.prop(kb, "interpolation")
                    row = layout.column()
                    row.active = enable_edit_value
                    row.prop(key, "eval_time")
     
     
    class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
        bl_label = "UV Maps"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            me = context.mesh
     
            row = layout.row()
            col = row.column()
     
            col.template_list("MESH_UL_uvmaps_vcols", "uvmaps", me, "uv_textures", me.uv_textures, "active_index", rows=1)
     
            col = row.column(align=True)
            col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
            col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
     
     
    class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
        bl_label = "Vertex Colors"
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            me = context.mesh
     
            row = layout.row()
            col = row.column()
     
            col.template_list("MESH_UL_uvmaps_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=1)
     
            col = row.column(align=True)
            col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
            col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
     
     
    class DATA_PT_customdata(MeshButtonsPanel, Panel):
        bl_label = "Geometry Data"
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     
        def draw(self, context):
            layout = self.layout
     
            obj = context.object
            me = context.mesh
            col = layout.column()
     
            col.operator("mesh.customdata_mask_clear", icon='X')
            col.operator("mesh.customdata_skin_clear", icon='X')
     
            if me.has_custom_normals:
                col.operator("mesh.customdata_custom_splitnormals_clear", icon='X')
            else:
                col.operator("mesh.customdata_custom_splitnormals_add", icon='ZOOMIN')
     
            col = layout.column()
     
            col.enabled = (obj.mode != 'EDIT')
            col.prop(me, "use_customdata_vertex_bevel")
            col.prop(me, "use_customdata_edge_bevel")
            col.prop(me, "use_customdata_edge_crease")
     
     
    class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
        COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
        _context_path = "object.data"
        _property_type = bpy.types.Mesh
     
     
    if __name__ == "__main__":  # only for live edit.
        bpy.utils.register_module(__name__)

    Merci d'avance.

  2. #2
    Expert confirmé
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 486
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 486
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    Le code n'était pas utile: la simple ligne "ImportError: No module named 'bpy'" veut dire que blender n'est pas installé.

    Pourtant, avec le fichier .msi, ça devrait s'installer tout seul?

    Quand au code, sans les indentations, il est inutilisable! => Il faut modifier le message et entourer le code avec les tags de codes (le sigle "#" en haut et à droit de la fenêtre d'édition des messages).

  3. #3
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 699
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 699
    Par défaut
    Citation Envoyé par tyrtamos Voir le message
    Le code n'était pas utile: la simple ligne "ImportError: No module named 'bpy'" veut dire que blender n'est pas installé.

    Pourtant, avec le fichier .msi, ça devrait s'installer tout seul?
    Que neni, bpi est un module qui vient avec le python inclus (embedded) dans Blender.
    Un script "blender" se lance via "blender --python /home/me/my_script.py".
    Et ce python là n'est certainement pas dans "C:\Python34\"

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

Discussions similaires

  1. Exécution d'un script python dans Blender avec un fichier .bat
    Par ero91 dans le forum Général Python
    Réponses: 4
    Dernier message: 24/01/2013, 12h53
  2. Problème fichier joint dans un projet de test
    Par LP-mpascolo dans le forum Visual Studio
    Réponses: 1
    Dernier message: 04/02/2009, 10h36
  3. Problème de logique dans ce test conditionnel
    Par Gunner4902 dans le forum Langage
    Réponses: 2
    Dernier message: 13/12/2007, 14h38
  4. Problème test d'un champ dans un Textbox
    Par porci82 dans le forum IHM
    Réponses: 5
    Dernier message: 01/06/2007, 09h29
  5. [XSLT] Problème de variable dans un test
    Par san julio dans le forum XSL/XSLT/XPATH
    Réponses: 8
    Dernier message: 30/01/2007, 16h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo