Share

Python tools: best practices

Frequently-used tools can be started from the startup directory; but if rarely used, start them by dragging into the scene.

Do not create a tool twice

  • Do not confuse creating a tool with showing a tool.
  • Use the startup directory to create a tool, and then show it with the Tool Manager.
  • If you prefer to show a tool by dragging a script into the viewer, use the code in SafeToolCreationExample.py. This tests if a tool exists to avoid creating it again.

If all tools in the startup directory are created like SafeToolCreationExample.py, you have the best of both worlds: a tool is executed once and can be dragged and dropped in the viewer when needed.

Rather than using FBTool, you should use pyfbsdk_additions::CreateUniqueTool or pyfbsdk_additions::CreateTool which ensure that the tools are added to the tool list and that the Tool Manager knows about them.

Unlike FBTool, CreateUniqueTool and CreateTool use the Tool Manager.

pyfbsdk_additions::CreateUniqueTool

Recommended: checks whether a tool with a similar name exists, and if so, it destroys that tool. It then creates a new tool with the same name. So each time you re-execute your script during testing, there is only one tool instantiated.

pyfbsdk_additions::CreateTool

Recommended: creates a tool without destroying the previous tool.

pyfbsdk::FBTool

Not recommended, as it does not register your tool with the Tool Manager.

Was this information helpful?