167
224
@rtype: 4x4 float matrix
168
225
@return: the current matrix.
228
def GetPerspMatrix ():
230
Get the current 3d perspective matrix.
231
@rtype: 4x4 float matrix
232
@return: the current matrix.
235
def EditMode(enable = -1, undo_msg = 'From script'):
237
Get and optionally set the current edit mode status: in or out.
240
in_editmode = Window.EditMode()
241
# MUST leave edit mode before changing an active mesh:
242
if in_editmode: Window.EditMode(0)
244
# make changes to the mesh
246
# be nice to the user and return things to how they were:
247
if in_editmode: Window.EditMode(1)
249
@param enable: get/set current status:
250
- -1: just return current status (default);
251
- 0: leave edit mode;
252
- 1: enter edit mode.
254
It's not an error to try to change to a state that is already the
255
current one, the function simply ignores the request.
256
@type undo_msg: string
257
@param undo_msg: only needed when exiting edit mode (EditMode(0)). This
258
string is used as the undo message in the Mesh->Undo History submenu in
259
the 3d view header. Max length is 63, strings longer than that get
262
@return: 0 if Blender is not in edit mode right now, 1 otherwise.
263
@warn: this is an important function. NMesh operates on normal Blender
264
meshes, not edit mode ones. If a script changes an active mesh while in
265
edit mode, when the user leaves the mode the changes will be lost,
266
because the normal mesh will be rebuilt based on its unchanged edit mesh.
269
def ViewLayers (layers = []):
271
Get and optionally set the currently visible layers in all 3d Views.
272
@type layers: list of ints
273
@param layers: a list with indexes of the layers that will be visible. Each
274
index must be in the range [1, 20]. If not given or equal to [], the
275
function simply returns the visible ones without changing anything.
277
@return: the currently visible layers.
282
Get the current VIEW3D view quaternion values.
283
@rtype: list of floats
284
@return: the quaternion as a list of four float values.
287
def SetViewQuat (quat):
289
Set the current VIEW3D view quaternion.
290
@type quat: floats or list of floats
291
@param quat: four floats or a list of four floats.
294
def GetViewOffset ():
296
Get the current VIEW3D offset values.
297
@rtype: list of floats
298
@return: a list with three floats: [x,y,z].
301
def SetViewOffset (ofs):
303
Set the current VIEW3D offset values.
304
@type ofs: 3 floats or list of 3 floats
305
@param ofs: the new view offset values.
308
def CameraView (camtov3d = 0):
310
Set the current VIEW3D view to the active camera's view. If there's no
311
active object or it is not of type 'Camera', the active camera for the
312
current scene is used instead.
313
@type camtov3d: int (bool)
314
@param camtov3d: if nonzero it's the camera that gets positioned at the
315
current view, instead of the view being changed to that of the camera.
320
Check if there are pending events in the event queue.
322
@return: 1 if there are pending events, 0 otherwise.
327
Get the next pending event from the event queue.
330
# let's catch all events and move the 3D Cursor when user presses
331
# the left mouse button.
332
from Blender import Draw, Window
334
v3d = Window.GetScreenInfo(Window.Types.VIEW3D)
335
id = v3d[0]['id'] # get the (first) VIEW3D's id
339
while not done: # enter a 'get event' loop
340
evt, val = Window.QRead() # catch next event
341
if evt in [Draw.MOUSEX, Draw.MOUSEY]:
342
continue # speeds things up, ignores mouse movement
343
elif evt in [Draw.ESCKEY, Draw.QKEY]: done = 1 # end loop
344
elif evt == Draw.SPACEKEY:
345
Draw.PupMenu("Hey!|What did you expect?")
346
elif evt == Draw.Redraw: # catch redraw events to handle them
347
Window.RedrawAll() # redraw all areas
348
elif evt == Draw.LEFTMOUSE: # left button pressed
349
Window.QAdd(id, evt, 1) # add the caught mouse event to our v3d
350
# actually we should check if the event happened inside that area,
351
# using Window.GetMouseCoords() and v3d[0]['vertices'] values.
352
Window.QHandle(id) # process the event
353
# do something fancy like putting some object where the
354
# user positioned the 3d cursor, then:
355
Window.Redraw() # show the change in the VIEW3D areas.
358
@return: [event, val], where:
359
- event: int - the key or mouse event (see L{Draw});
360
- val: int - 1 for a key press, 0 for a release, new x or y coordinates
361
for mouse movement events.
364
def QAdd (win, event, val, after = 0):
366
Add an event to some window's (actually called areas in Blender) event queue.
368
@param win: the window id, see L{GetScreenInfo}.
369
@type event: positive int
370
@param event: the event to add, see events in L{Draw}.
372
@param val: 1 for a key press, 0 for a release.
373
@type after: int (bool)
374
@param after: if nonzero the event is put after the current queue and added
380
Process immediately all pending events for the given window (area).
382
@param winId: the window id, see L{GetScreenInfo}.
383
@note: see L{QAdd} for how to send events to a particular window.
386
def GetMouseCoords ():
388
Get mouse's current screen coordinates.
389
@rtype: list with two ints
390
@return: a [x, y] list with the coordinates.
393
def SetMouseCoords (coords):
395
Set mouse's current screen coordinates.
396
@type coords: (list of) two ints
397
@param coords: can be passed as x, y or [x, y] and are clamped to stay inside
398
the screen. If not given they default to the coordinates of the middle
402
def GetMouseButtons ():
404
Get the current mouse button state (see / compare against L{MButs}).
406
@return: an or'ed flag with the currently pressed buttons.
409
def GetKeyQualifiers ():
411
Get the current qualifier keys state (see / compare against L{Qual}).
413
@return: an or'ed combination of values in L{Window.Qual}.
416
def SetKeyQualifiers (qual):
418
Fake qualifier keys state. This is useful because some key events require
419
one or more qualifiers to be active (see L{QAdd}).
421
@param qual: an or'ed combination of values in L{Window.Qual}.
423
@return: the current state, that should be equal to 'qual'.
424
@warn: remember to reset the qual keys to 0 once they are not necessary
430
Get the current area's ID.
435
Get the current area's size.
436
@rtype: list with two ints
437
@return: a [width, height] list.
438
@note: the returned values are 1 pixel bigger than what L{GetScreenInfo}
439
returns for the 'vertices' of the same area.
442
def GetScreenSize ():
444
Get Blender's screen size.
445
@rtype: list with two ints
446
@return: a [width, height] list.
451
Get the names of all available screens.
452
@rtype: list of strings
453
@return: a list of names that can be passed to L{SetScreen}.
456
def SetScreen (name):
458
Set as current screen the one with the given name.
460
@param name: the name of an existing screen. Use L{GetScreens} to get
461
a list with all screen names.
464
def GetScreenInfo (type = -1, rect = 'win', screen = ''):
466
Get info about the current screen setup.
468
@param type: the space type (see L{Window.Types}) to restrict the
469
results to. If -1 (the default), info is reported about all available
472
@param rect: the rectangle of interest. This defines if the corner
473
coordinates returned will refer to:
474
- the whole area: 'total'
475
- only the header: 'header'
476
- only the window content part (default): 'win'
478
@param screen: the name of an available screen. The current one is used by
480
@rtype: list of dictionaries
481
@return: a list of dictionaries, one for each area in the screen. Each
482
dictionary has these keys (all values are ints):
483
- 'vertices': [xmin, ymin, xmax, ymax] area corners;
484
- 'win': window type, see L{Types};
485
- 'id': this area's id.