﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.5%2FSource%2FArchitecture%2FOperators</id>
	<title>Dev:2.5/Source/Architecture/Operators - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.5%2FSource%2FArchitecture%2FOperators"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Architecture/Operators&amp;action=history"/>
	<updated>2026-06-15T10:11:50Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Architecture/Operators&amp;diff=76967&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Architecture/Operators&amp;diff=76967&amp;oldid=prev"/>
		<updated>2018-06-28T18:36:06Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 18:36時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Architecture/Operators&amp;diff=76966&amp;oldid=prev</id>
		<title>2014年4月29日 (火) 19:51にwiki&gt;Ideasman42による</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Architecture/Operators&amp;diff=76966&amp;oldid=prev"/>
		<updated>2014-04-29T19:51:22Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Operators=&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Creating new tools in Blender 2.50 is done by defining a new &amp;lt;tt&amp;gt;wmOperatorType&amp;lt;/tt&amp;gt;. When running the tool, a &amp;lt;tt&amp;gt;wmOperator&amp;lt;/tt&amp;gt; is created, which will store temporary data while the operator is executing and after the tool finishes, everything needed to redo the operation in a different context&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 static void WM_OT_save_homefile(wmOperatorType *ot)&lt;br /&gt;
 {&lt;br /&gt;
 	ot-&amp;gt;name = &amp;quot;Save User Settings&amp;quot;;&lt;br /&gt;
 	ot-&amp;gt;idname = &amp;quot;WM_OT_save_homefile&amp;quot;;&lt;br /&gt;
 	&lt;br /&gt;
 	ot-&amp;gt;invoke = NULL; //WM_operator_confirm;&lt;br /&gt;
 	ot-&amp;gt;exec = WM_write_homefile;&lt;br /&gt;
 	ot-&amp;gt;poll = WM_operator_winactive;&lt;br /&gt;
 	&lt;br /&gt;
 	ot-&amp;gt;flag = OPTYPE_REGISTER;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each operator type has a human readable &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; for the user interface, and a unique &amp;lt;tt&amp;gt;idname&amp;lt;/tt&amp;gt; for identifying it. The &amp;lt;tt&amp;gt;idname&amp;lt;/tt&amp;gt; is formatted as &amp;lt;tt&amp;gt;PREFIX_OT_do_some_operation&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; represents an action and is capitalized, for example “Do Some Operation”.&lt;br /&gt;
&lt;br /&gt;
Operator types also define a number of [[Dev:2.5/Source/Architecture/RNA|RNA properties]]. These are the properties that can be set externally when calling the operator, and that get saved to redo the operator.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; callback is provided to run the operator without user interaction. Many operators will not need user interaction to begin with, but for the ones that do, there are three optional callbacks &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;modal&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;cancel&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt; callback will also execute the operator, but this time with an event available to get mouse coordinates for example. From the &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt; callback, the operator can add itself as a handler, and receive further events in the &amp;lt;tt&amp;gt;modal&amp;lt;/tt&amp;gt; callback. If the operator is cancelled due to some external reason (e.g. the program quitting), the &amp;lt;tt&amp;gt;cancel&amp;lt;/tt&amp;gt; callback is called. Every operator must define either &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt;, and only if &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; is provided can the operator be recorded for a macro.&lt;br /&gt;
&lt;br /&gt;
[[Image:Context-operator.png|thumb|320px|left]]&lt;br /&gt;
The &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; callback receives a context and its own operator. At this point, the operator may contain any subset of properties supported by this operator specified by the user calling the operator. Typically the code in this callback will first fill in any properties with their default values if they are not provided already, execute the operation and return. The properties filled in at the end of the execution must be sufficient to redo the operation.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt; callback is similar to &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt;, with as an additional function argument an event. It often only does initialization and handles further events in the &amp;lt;tt&amp;gt;modal&amp;lt;/tt&amp;gt; callback. Handling further events is done by registering the operator as a handler at the appropriate level. Since an operator implementing invoke must also implement &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt;, the code must be split up in order to avoid code duplication. It is advised to define internal &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;apply&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt; functions, that can be reused. The &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; callback will then typically use &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;apply&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt; callback will use &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;apply&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;modal&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;cancel&amp;lt;/tt&amp;gt; callbacks will use both &amp;lt;tt&amp;gt;apply&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt;. Often the &amp;lt;tt&amp;gt;customdata&amp;lt;/tt&amp;gt; pointer will be used to store data for the duration of the operation.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;modal&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;cancel&amp;lt;/tt&amp;gt; functions return one of four states: &amp;lt;tt&amp;gt;pass through&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;running modal&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;cancelled&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;finished&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;pass through&amp;lt;/tt&amp;gt; state means the operator passes on the event to other operators, as if the callback did not run. The &amp;lt;tt&amp;gt;running modal&amp;lt;/tt&amp;gt; state indicates that the operator is still running and has registered itself to receive &amp;lt;tt&amp;gt;modal&amp;lt;/tt&amp;gt; callbacks. The states &amp;lt;tt&amp;gt;cancelled&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;finished &amp;lt;/tt&amp;gt;mean the execution of the operator has ended, either unsuccessfully or successfully. The operator will be registered if it finishes successfully.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;poll&amp;lt;/tt&amp;gt; callback is used to verify if the operator can be executed in the current context. The operator may still fail to execute due to some more specific reason. The callback function used for this is often shared by multiple operators. The &amp;lt;tt&amp;gt;poll&amp;lt;/tt&amp;gt; function is always called before executing the operator to verify the context and it may be used to gray out or hide user interface elements that use this operator automatically.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;uiBlock&amp;lt;/tt&amp;gt; callback is used to provide a user interface to the operator, to redo or repeat it.&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
==Caveats==&lt;br /&gt;
* Note the distinction between &amp;lt;tt&amp;gt;RNA properties&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;customdata&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;properties&amp;lt;/tt&amp;gt; should only store public parameters as seen by the user, these are saved as part of macro's and written to file. The &amp;lt;tt&amp;gt;customdata&amp;lt;/tt&amp;gt; is an arbitrary pointer, typically to a C struct, that should only exist while the operator is running, an so it is not written to file.&lt;br /&gt;
* The &amp;lt;tt&amp;gt;invoke&amp;lt;/tt&amp;gt; callback also takes properties as inputs and should take those into account. For example a transform operator might have a &amp;lt;tt&amp;gt;mode=rotate&amp;lt;/tt&amp;gt; input, and should then start in rotation mode.&lt;br /&gt;
&lt;br /&gt;
==Conventions==&lt;br /&gt;
&lt;br /&gt;
* All operators should have an idname, name and description.&lt;br /&gt;
* Ordering for names: (context _OT_ subcontext) _ (operation) _ (optional operation info)&lt;br /&gt;
*  The reason is that a function beginning with 'copy' or 'add' doesn't  say much about the context it works in, especially when there's a subcontext. It also makes it a bit easier to locate. We always use the verb to separate the information in 'what it works on' and what it does. This gives straight information about what the operator needs as input.&lt;br /&gt;
* Examples:&lt;br /&gt;
** MESH_OT_faces_delete&lt;br /&gt;
** MESH_OT_faces_select_similar&lt;br /&gt;
** MESH_OT_add_primitive_monkey&lt;br /&gt;
** MESH_OT_edges_select_shortest_path&lt;br /&gt;
** MESH_OT_edges_select_sharp&lt;br /&gt;
** OBJECT_OT_modifier_delete&lt;br /&gt;
** OBJECT_OT_modifier_add&lt;br /&gt;
** OBJECT_OT_constraint_delete&lt;br /&gt;
** OBJECT_OT_constraint_add&lt;br /&gt;
* Classify operators well that heavily rely on mouse input, or cannot be redone or cannot be used for the py api.&lt;br /&gt;
&lt;br /&gt;
* Use enum and boolean properties instead of ints for things like modes and options.&lt;br /&gt;
* Use the float percentage subtype where applicable, with range 0.0-1.0 and do any necessary conversions in the operator.&lt;br /&gt;
* Define proper hard/soft limits.&lt;br /&gt;
&lt;br /&gt;
* Selection operators should use boolean properties &amp;quot;extend&amp;quot; and &amp;quot;deselect&amp;quot;.&lt;br /&gt;
* Toggle operators should have a standard enum with three options: set/clear/toggle, with toggle the default option.&lt;br /&gt;
&lt;br /&gt;
==Open Issues==&lt;br /&gt;
* Operators that depend on mouse coordinates, like moving areas or selecting in the 3d viewport, are problematic. How to redo such an operation? One possibility is to store the x and y coordinates, but this makes the operator quite useless as part of a macro. Another is to use the current mouse coordinates while the macro is running, but the macro may be run from a menu for example, in which case the mouse coordinate have little meaning. Maybe the latter is still the most useful option since it will support a macro like “mouse select face, delete selected face”, though then exec also depends on user input?&lt;br /&gt;
** Current solution: just don't bother supporting &amp;quot;modal&amp;quot; macros well. If an operator like this is recorded as part of a macro, it can just give a warning somewhere that this is not supported. If someone wants to make such a complex macro that depends on user interface interaction, it should become possible to do that by making an operator as a python script.&lt;br /&gt;
*** (Ton) We exclude for now selection (contextual changes) from operator storage or macros. In the case of &amp;quot;move edge&amp;quot;, you can store an (x,y) property close to the edge to indicate which, to prevent &amp;quot;Context&amp;quot; having to define such. That way the operator is re-usable via Python at least. Although, this isn't a very useful case. :)&lt;br /&gt;
* When an operator is executed a second time, should its properties be remembered for the next time the operator executes? If so, then it should not do this for all properties. For example a translation operator would not need to remember the translation vector, but an extrude operator should remember the extrusion type.&lt;br /&gt;
** This could also be remembered by the tool itself, saved in the tool settings or so.&lt;br /&gt;
*** (Ton) It is especially the purpose that its properties are remembered! A useful redo or repeat is based on having those properties, and make use of Context. Also using the same operator again will make use of that (like Add Sphere properties).&lt;br /&gt;
* While it is the intention that operators work based on redo rather than being modal, these operators might still want to use shortcut keys to set certain properties quickly. How does this fit in with the operator definition, or more generally, the event system, since these would not truly be modal and so conflict with other keys?&lt;br /&gt;
** More of a user interface discussion, though it can have an effect on the implementation, this can be added to the operator design if needed after experimenting with implementing some real operators.&lt;br /&gt;
*** (Ton) in the case of Macros, Redo or Repeat, such extra user input should not be a requirement. How to define a useful modal() callback for a Macro?&lt;br /&gt;
* Should supported properties be specified in the operator type register function? Such a specification is useful for generating docs, validating python function arguments or creating an automatic UI for the operator.&lt;br /&gt;
** Yes, this should be done somehow. The operator properties should, just like other properties in Blender, get a ui min/max, strict min/max, default, tooltip, .. . How this is defined exactly can be figured out as part of the &amp;quot;data access api&amp;quot; and implemented using the same mechanism.&lt;br /&gt;
*** (Ton) good idea... needs some figuring indeed!&lt;br /&gt;
* While operators are running modal, in theory the context could change arbitrarily, invalidating certain pointers the operator may store. Is this a practical problem, if so, how to avoid this?&lt;br /&gt;
** Probably best to tackle this problem when we get there. Any operation that depends on some window/object/image not being removed should either be blocking, or check that the data it is operating on still exists.&lt;br /&gt;
***(Ton) I don't see this happening, provided the poll() callback is correct, and modal() doesn't internally change context redically in internal subloops.&lt;br /&gt;
* The event handling code iterates over windows, areas, regions, handlers to execute operators. What happens if these operators remove one of these while it is iterating over them?&lt;br /&gt;
** If an operator runs at a level and it removes something above it, that should be done through a notifier rather than a direct function call.&lt;/div&gt;</summary>
		<author><name>wiki&gt;Ideasman42</name></author>
		
	</entry>
</feed>