Embedding a script inside a Blender document is useful for some special purposes, but often you want to be able to reuse an addon across any number of Blender documents, and perhaps distribute it to others for use with their Blender projects. To do this, you will need to save the script as a text file that can be copied into your Blender user preferences. It will also need to have some additional information inserted.
::在Blender文档中嵌入脚本对于某些特殊目的是有用的,但通常你希望能够在任意数量的Blender文档中重复使用一个附加组件,并可能将其分发给其他人使用他们的Blender项目.为了做到这一点,你需要将脚本保存为文本文件,可以复制到你的Blender用户偏好.它还需要插入一些额外的信息.

The Addon Info Dictionary
::添加信息字典

In order for the addon to be installable by Blender, it will need to define a global called  bl_info , the value of which is a dictionary. This contains various information about compatibility with versions of Blender, and also descriptive information to be shown to the user as they browse through the list of installable addons.
::为了使该附加程序可由Blender安装,它需要定义一个称为bl_info的全局值,其值是字典.它包含有关Blender版本兼容性的各种信息,以及在浏览可安装附加程序列表时向用户显示的描述信息.

Here’s what the info should look like:
::信息应该是这样的:

bl_info = \
    {
        "name" : "Tetrahedron Maker",
        "author" : "J Random Hacker <jrhacker@example.com>",
        "version" : (1, 0, 0),
        "blender" : (2, 5, 7),
        "location" : "View 3D > Edit Mode > Tool Shelf",
        "description" :
            "Generate a tetrahedron mesh",
        "warning" : "",
        "wiki_url" : "",
        "tracker_url" : "",
        "category" : "Add Mesh",
    }

Most of the fields are informational. The “category” value must be one of the predefined ones that you will see listed in Blender’s User Preferences window when you switch to the “Add-Ons” tab; the addon display is sorted by category and by name within category, and the user can list scripts in all categories or in just one category.
::大多数字段都是信息的. 类别值必须是预定义的值之一,当您切换到附加项选项卡时,您将在Blender的用户偏好窗口中看到列出的值; 附加项显示按类别和类别内名称排序,用户可以列出所有类别或仅在一个类别中的脚本.

The “version” field indicates the version of your script, and can be a tuple of any number of integers; the numbers are shown to the user joined with decimal points (e.g. “(1, 0, 0)” is displayed as “1.0.0”). The “blender” field indicates compatibility with versions of Blender; Blender versions older than this are supposed to reject the script. (Though what happens when a  newer  version introduces a backward-incompatible API change is not quite clear...)
::version字段表示脚本的版本,并且可以是任意数量的整数;数字显示给用户连接小数点 (例如,(1, 0, 0) 显示为1.0.0). blender字段表示与Blender的版本兼容;比此更旧的Blender版本应该拒绝脚本. (尽管当新版本引入向后不兼容的API更改时会发生什么,并不完全清楚...)

Making The Addon Installable
::让添加程序可以安装

The contents of your addon script are now complete. In the Text Editor, find the “Save As” option under the “Text” menu, and choose a filename for saving your script—perhaps call it  TetrahedronMaker.py .
::现在你的附加脚本的内容已经完成. 在文本编辑器中,在"文本"菜单下找到"保存为"选项,然后选择保存脚本的文件名,也许叫它为TetrahedronMaker.py.

That’s it. This saved text file is your complete addon, ready for installation into your Blender user settings, or distribution to others for installation in their settings.
::已完成. 已保存的文本文件是您的完整的附加程序, 准备安装到您的Blender用户设置中, 或向他人发行以安装其设置.

Installing The Addon
::安装添加程序

To install the addon into your Blender user settings, go to the User Preferences, and bring up the Add-Ons tab. (It doesn’t matter what document you might have open at this stage.) In the window header, click the “Install Add-On...” button, and find the  TetrahedronMaker.py  file you previously saved; select that, and click the “Install Add-On” button in the file selector. This copies the script file into your personal addons directory, which in Unix/Linux is  ~/.blender/2.5 x /scripts/addons/ . You can also directly copy your script file into this directory, instead of using the “Install Add-On...” button. To uninstall an addon, use the Remove button that appears in its info panel (see below) or delete the script from this directory, together with its  .pyc  (compiled) version (which you will find in the  __pycache__  subdirectory).
::要将附加程序安装到您的Blender用户设置中,请进入用户偏好,并打开附加程序选项卡. (在此阶段您可能已经打开了什么文档并不重要.) 在窗口标题中,点击"安装附加程序..."按,并找到您先前保存的TetrahedronMaker.py文件;选择该文件,然后点击"文件选择器中的"安装附加程序"按.此将脚本文件复制到您的个人附加程序目录中,在Unix/Linux中是~/.blender/2.5x/scripts/addons/.您也可以直接将脚本文件复制到该目录中,而不是使用"安装附加程序..."按. 要卸载附加程序,请使用"删除该

Using The Installed Addon
::使用已安装的附加程序

To make use of the installed addon, open a new Blender document. Go to the User Preferences window, and bring up the Add-Ons tab. Browse through the list of addons (feel free to restrict the display to the “Add Mesh” category as specified above) until you find your Tetrahedron Maker. You can click the white triangle to the left of the name to expand the list item display to show all the details:
::要使用已安装的附加程序,请打开一个新的Blender文档.进入用户偏好窗口,并打开附加程序选项卡.浏览附加程序列表 (随意限制显示到上述"添加网格"类别),直到找到您的四面体制造器.您可以点击名称的左边白色三角形来扩展列表项显示以显示所有细节:

Note the buttons that may appear along the bottom: the “Remove” button appears for your own user-installed scripts, not for ones installed systemwide; the “Link to the Wiki” button is only visible if you provided a URL in the “ wiki_url ” field of your bl_info; and “Report a Bug” comes up only if there is something in the “ tracker_url ” field.
::注意可能出现在底部的按: Remove按显示您自己的用户安装脚本,而不是系统安装的脚本; 链接到Wiki按只有在您在bl_info的wiki_url中提供了URL时才可见; 报告Bug只有在tracker_url中出现了一些东西.

Click the checkbox in the top right corner of the item display to enable the addon for this document.
::单击项目显示的右上角的选项框, 启用此文档的附加功能.

Now switch to the 3D View, bring up the Tool Shelf if it’s not already visible, and you should see that familiar panel appear:
::现在切换到3D视图, 带上工具架如果它没有已经可见, 你应该看到熟悉的面板出现:

You know what to do next...
::你知道接下来要做什么...


Last modified: Monday, 17 March 2025, 2:50 PM