I would like to change the 3d viewport to orthogonal from a python script. From the key mapping I found this command &quot;view3d.view_persportho&quot;. I always find it tricky when I have to mess with the context (Which I think is nescesary). Anyway, I tried this: for area in bpy.context.window.screen.areas:         if area.type == 'VIEW_3D':             for region in area.regions:                 if region.type == 'WINDOW':                     override = bpy.context.copy()                     override['area'] = area                     override['region'] = region                     override['scene'] = bpy.context.scene                                           bpy.ops.wm.setup_ui(override)                      # Maybe I can set perspective here somehow?  class MYOP_setup_ui(bpy.types.Operator):     bl_idname = &quot;wm.setup_ui&quot;     bl_label = &quot;Setup UI&quot;     def execute(self, context):         context.space_data.show_region_ui = True # This opens the sidebar panels correctly         # I know that I can't pass arguments to operators like in the next line.         # bpy.ops.view3d.view_persportho('ORTHO') # 'PERSP', 'CAMERA'                     return {'FINISHED'}  I found these, which is pretty much what I want, but I can't get it to work. Maybe pre 2.8?
30573
What is the python command to check if current view is in orthographic or perspective mode?
106843
def execute(self, context):     stl_path = bpy.path.abspath(bpy.context.scene.stl_path)     bpy.ops.import_mesh.stl(filepath=stl_path)     try:         ob_new = bpy.context.selected_objects[0]         for f in ob_new.data.polygons:             f.use_smooth = True         for b in ob_new.data.polygons:             bpy.context.space_data.show_textured_solid = True             bpy.context.object.show_transparent = True             bpy.context.scene.render.engine = 'CYCLES'             bpy.ops.object.editmode_toggle()                bpy.ops.mesh.select_all(action='TOGGLE')                             bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')             bpy.ops.mesh.select_all(action='TOGGLE')                 bpy.ops.mesh.tris_convert_to_quads()             bpy.ops.view3d.snap_cursor_to_selected()             bpy.ops.object.origin_set(type = 'ORIGIN_CURSOR')                   Everything is working well, until I use origin_set. Maybe I should go to object mode, after converting mesh to quads.  But when I'm adding bpy.ops.object.editmode_toggle() after tris_convert_to_quads Blender is freezing. Without this last command, everything is working, also snapping cursor to selected.    Ok, I changed script.  def execute(self, context):     stl_path = bpy.path.abspath(bpy.context.scene.stl_path)     bpy.ops.import_mesh.stl(filepath=stl_path)     try:         ob_new = bpy.context.selected_objects[0]         for f in ob_new.data.polygons:             f.use_smooth = True             bpy.context.object.show_transparent = True             bpy.context.scene.render.engine = 'CYCLES'             bpy.ops.object.editmode_toggle()             bpy.ops.mesh.select_all(action='TOGGLE')                             bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')             bpy.ops.mesh.select_all(action='TOGGLE')                 bpy.ops.mesh.tris_convert_to_quads()             bpy.ops.mesh.faces_shade_smooth()             bpy.ops.object.mode_set(mode='EDIT')             bpy.ops.mesh.select_all(action='TOGGLE')    to this line everything is ok, and script is ends in object mode. but If I add this line                 bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')  I have msg in console, that I must be in object mode. If i add this command                 bpy.ops.object.mode_set(mode='OBJECT') Blender is switching off.
23121
Is there a Python command that will allow me to set the camera clip end for viewing my objects in Blender (via scripting)? According to  the "bpy.context.space_data" variable is read-only.
67601
In 2.7x and earlier we have .  The setting can still be set via the python api (bpy.context.scene.render.display_mode), but I can't seem to find it in the gui anywhere. Is it still there? If so, where is it?
27618
I want to fully automatize some of my blender processes, an i run into a lot of problems not finding the correct commands, not using the correct args...  Can i just "see" in a log somewhere what were the commands blender ran ?  To be very precise, i want to load a gltf file, and export it to stl.  No problem through the gui, but i'm stuck with that bit of code :   import bpy import sys import os  file = open(r"C:\Users\theo1\Documents\GitHub\Hackathon2020\map&amp;mapdata\mini.gltf")  bpy.ops.import_scene.gltf(file) bpy.ops.export_mesh.stl(filePath=r"C:\Users\theo1\Documents\GitHub\Hackathon2020\map&amp;mapdata\mini.stl")   Which gives me this :   Traceback (most recent call last):   File "&lt;string&gt;", line 1, in &lt;module&gt;   File "C:\Users\theo1\Desktop\impExp.py", line 7, in &lt;module&gt;     bpy.ops.import_scene.gltf(file)   File "C:\Program Files\Blender Foundation\Blender 2.81\2.81\scripts\modules\bpy\ops.py", line 198, in __call__     C_dict, C_exec, C_undo = BPyOpsSubModOp._parse_args(args)   File "C:\Program Files\Blender Foundation\Blender 2.81\2.81\scripts\modules\bpy\ops.py", line 151, in _parse_args     raise ValueError("1-3 args execution context is supported") ValueError: 1-3 args execution context is supported   thanks.
116717
If i switch between solid and wireframe mode, i can see in the info window that these commands are invoked :  bpy.data.screens["Layout"].shading.type = 'WIREFRAME' bpy.data.screens["Layout"].shading.type = 'SOLID'   Now i want to execute this command using python console. So i cut and paste the codes into python console but i got this error :   &gt;&gt;&gt; bpy.data.screens["Layout"].shading.type = 'WIREFRAME' Traceback (most recent call last):   File "&lt;blender_console&gt;", line 1, in &lt;module&gt; AttributeError: 'Screen' object has no attribute 'shading'  &gt;&gt;&gt; bpy.data.screens["Layout"].shading.type = 'SOLID' Traceback (most recent call last):   File "&lt;blender_console&gt;", line 1, in &lt;module&gt; AttributeError: 'Screen' object has no attribute 'shading'   Does anyone know why ? and what the correct script should i use in python console ?  Thanks
85538
I want to switch 3D views in my presentation. I have read in the movie15 package that it is possible with the command: (dice example from movie15.pdf page 16)  \movieref[3Dviewindex=N]{dice}{Click here}   But in this case I have to click with my mouse on a button. It is possible to bind the command on a key or to call the button via a key or combine this with the command \pause ?  Regards,  Grandement.
109212
I'm using Blender Internal due to its object outline effect, and am trying to use a 1800 degree environment map for the reflections (not lighting). I'm trying what seems like should work, and am failing.   Most of the tutorials for this are in Cycles, which is handled easily, can anyone tell me how to do it in Blender 2.6+ Internal?  EDITS:   So my question is really just "How do I apply an environment map in Blender Internal?"; the perspective of the environment map is trivial to the question.
99054
I'm still new with python and scripting. I tried editing the . Since I'm exporting tons of object groups, I need each of scene collection or selected objects to be exported as an :  import bpy import os  # get the path where the blend file is located basedir = bpy.path.abspath('//')  # deselect all objects # bpy.ops.object.select_all(action='DESELECT')      # loop through all the objects in the scene scene = bpy.context.scene for ob in scene.objects:     # make the current object active and select it     scene.objects.active = ob     ob.select = True      # make sure that we only export meshes     if ob.type == 'MESH':         # export the currently selected object to its own file based on its name         bpy.ops.export_scene.gltf(                 filepath=os.path.join(basedir+'gltf-individual', ob.name + '.gltf'),                 use_selection=True,                 )     # deselect the object and move on to another if any more are left     ob.select = False   Q: Can someone help me with this?
94591
I'm trying to use Python to place a camera. I know the camera's location, and the forward and up vectors for the camera (i.e. the direction it's pointing and its orientation). How do I do this?  I know that it's possible to calculate a raw world matrix from the above information, which I can then apply to the camera, but I was rather hoping not to have to. Is there an easier way?
98809
I have some points in EPSG:2284 and I'm trying to convert them to EPSG:4326 using pyproj, however I get weird results. When I go to the  I see that there is an endpoint that does the conversion. When I use that instead I get the correct result.   Here is some code illustrating the different results:  from pyproj import Proj, transform import requests  if __name__ == '__main__':      # points I want to convert from EPSG:2284 -&gt; EPSG:4326     targets = [         (3669486.63386,11293013.10592,709.08004),         (3669559.13811,11292972.72831,711.60055),         (3669639.51308,11292851.48264,712.22258),         (3669800.62304,11292949.38118,714.75766),     ]      for northing, easting, up in targets:         print "Converting", easting, northing          # Transform using pyproj (gives wrong answer)         WGS84 = Proj(init='EPSG:4326')         inp = Proj(init='EPSG:2284')         x, y = transform(inp, WGS84, easting, northing)         print x, y, "(with proj4)"          # Transform using spatialreference.org URL (gives correct answer)         url = "http://spatialreference.org/projection/?json=%7B%22type%22%3A%22Feature%22%2C%20%22geometry%22%3A%7B%22type%22%3A%22Point%22%2C%20%22coordinates%22%3A%5B{lon}%2C%20{lat}%5D%7D%2C%22properties%22%3A%7B%7D%7D&amp;inref=EPSG:{inp}&amp;outref=epsg:{outp}"         url = url.format(lon=easting, lat=northing, inp='2284', outp='4326')         x, y = requests.get(url).json()['coordinates']         print x, y, '(using spatialreference.org URL)'   Does anyone know why they are giving different result and what is wrong with the Pyproj code?
13341
In my plugin I have an operator that needs to iterate through potentially 100's of objects that might be 'hidden in viewport' or 'disabled in viewport' and perform some operations  that require the object to be visible in viewport. Afterwards I want to restore whatever visibility the object had, so I need to both get and set these options.  IE, get/set the status of these. When I hover over the icons, both show the parameter bpy.context.object.hide_viewport. Obviously they can't both be the same parameter as they both do different things. How do I get and set 'hidden in viewport' and how do I get and set 'disabled in viewport' using the Python API? Edit: I can see that both ObjectBase(bpy_struct) and Object(ID) have the hide_viewport property, however ObjectBase is documented as 'Temporarily hide in viewport' and Object is documented as 'Globally disable in viewports'. How do I access an Object's ObjectBase?
101880
I'm considering adding a feature to the 3d-printing tools, or to the Transform menu -- whichever is more appropriate.  Background: When 3d printing, one often must rotate an object so some face(s) lie flat on the xy plane, so it'll print flat.  Present method (which works, but is a lot of steps):   Select the desired face (in edit mode) Shift+Numpad7 to view it from its local Top Go to Object mode and add an Empty Check Align to view (so the empty is aligned to the top-down view of the face) Parent the object to the empty (empty becomes parent) Select the empty and clear its rotation (Alt+R) Select and unparent (Alt+P) the object, using Keep transformation Success!   Desired methods: A. Rotating the mesh in edit mode might be satisfactory, so:   Select face Hit button (Make Face Bottom?) in 3d-Printing tools, which rotates the whole mesh so that face aims down.   Note: Sometimes someone may want to align so this is the top or side face, so the button might be better as: Align object to face, followed by a tool option which allows a selection of: "Top, bottom, left, right"    B. Rotating the object itself might also be desired by some, instead:   Select face Shift+7 to view from face's "top" Go to object mode In the transform menu, select Align object view-rotation.  Tooltip: Rotates object to align the current view's rotation with an axis.(Or something more clear). Tool-options allow overriding default of -Z with: Z-, Z+, Y-, Y+, X-, X+   Note: Tool-options may also allow a pulldown of the available Transform orientations, defaulting to global.    The easiest and fastest implementation might be a python addition to the 3d-printing tools, but I believe it worthwhile to consider the usefulness of this feature in normal modeling, and therefore its addition to the transform menu -- this has the secondary positive effect of it working on the object instead of the mesh, thereby retaining the object's local transform orientation.  Advice, suggestions, questions, or assistance are all welcome.
50281
Basically, I want to have a single operator which can do multiple things, based on some attributes values.  class MyPanel(bpy.types.Panel):     # (...)     layout = self.layout     row = layout.row()     row.operator("my.button", text="Button text")  class MY_BUTTON_OT_Button(bpy.types.Operator):     bl_idname = "my.button"     bl_description = "Button description"     bl_label = "Button"     foo = bpy.props.IntProperty()     bar = bpy.props.BoolProperty()      if bar:         # Do something with foo     else:         # Do something else :P   I know how to set one attribute, like so:      row.operator("my.button", text="Button text").foo=5   But what about multiple arguments? I tried several things that didn't worked, like (e.g.):   With setattr(): row.operator("my.button", text="Button text").setattr(foo=5,bar=True)   With a custom method setVal() in the operator class: row.operator("my.button", text="Button text").setVal(foo=5,bar=True)   Maybe I must use a single EnumProperty? I hope to avoid this, so my question is: Is it possible to pass multiple custom arguments to set attributes in an operator class? And if yes, how ?  Thanks for your help.
35631
Trying to follow along with a tutorial and in that tutorial the idea is to look at an object I created from the front and then set the camera to the current view.  The steps to do this are:   Numpad 1 (Front perspective) Ctrl+Alt+Numpad 0 (Align Camera to View)   For some reason whenever I do this I don't see anything in the camera and then panning the view around I see that my object seems to have moved to where I wanted the camera and my camera hasn't moved at all.
28966
I'm trying to get invoke_props_popup to work. But my code produces this error:   Error: Operator 'OBJECT_OT_keyframe_changer' does not have register enabled, incorrect invoke function  Traceback &lt;most recet call last):     File "(Script-path)", line 63, in &lt;module&gt; ...  RuntimeError: Error: Operator 'OBJECT_OT_keyframe_changer' does not have register enabled, incorrect invoke function   Line 63 is bpy.ops.object.keyframe_changer('INVOKE_DEFAULT')  I haven't been able to find any documentation to help me with this. Why does it not run? Why does it give me an error?    This is the code I have so far:  class KeyframeChangerOperator(bpy.types.Operator):     """Let's you change keyframe position"""     bl_idname = "object.keyframe_changer"     bl_label = "Keyframe changer"     my_float = bpy.props.FloatProperty(name="Keyframe position")       def execute(self, context):         set_keyframe_position(self.my_float)         return {'FINISHED'}      def invoke(self, context, event):         wm = context.window_manager         return wm.invoke_props_popup(self, event)  def register():     bpy.utils.register_class(KeyframeChangerOperator)  def unregister():     bpy.utils.unregister_class(KeyframeChangerOperator)   if __name__ == "__main__":     register()      # test call     bpy.ops.object.keyframe_changer('INVOKE_DEFAULT')
12567
How can I change Blender from the default cube/lamp/camera default setup? Also, is it possible to change other features, such as the default view direction (Top, Side, etc) or the Editor type (3D View, Node Editor, Graph Editor, etc)?