HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM/ObjNode_setSelectable.C
/*
* Copyright (c) 2024
* Side Effects Software Inc. All rights reserved.
*
* Redistribution and use of Houdini Development Kit samples in source and
* binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*----------------------------------------------------------------------------
*/
//****************************************************************************
//****************************************************************************
//****************************************************************************
//
// WARNING
//
// This example is deprecated, and is largely replaced by the inlinecpp
// Python module. Except for the ability to raise exceptions, you can
// implement this example with the following Python code:
//
// inlinecpp.extendClass(
// hou.ObjNode,
// "node_methods",
// includes="#include <UT/UT_UndoManager.h>",
// function_sources=["""
// void setSelectable(OBJ_Node *obj_node, int selectable)
// {
// if (!obj_node->canAccess(PRM_WRITE_OK))
// return;
//
// UT_AutoUndoBlock undo_block("Setting selectable flag", ANYLEVEL);
// obj_node->setPickable(selectable != 0);
// }
// """])
//
//****************************************************************************
//****************************************************************************
//****************************************************************************
// This sample shows how to extend HOM using C++. It adds a
// hou.ObjNode.setSelectable method that makes an object node selectable/
// unselectable in the viewport.
//
// NOTE: The _hdk_sample_hom_extensions extension module must first be built.
// _hdk_sample_hom_extensions.C, which is located in the same
// directory as this file, contains the module source.
//
// You can build the extension module using hcustom:
// hcustom -I <hfs_python_include_dir> -i $HOME/houdini20.0/pythonX.Ylibs _hdk_sample_hom_extensions.C
//
// where:
// - "X" is the Python major version that Houdini is built against.
// - "Y" is the Python minor version that Houdini is built against.
// - <hfs_python_include_dir> is:
// - $HFS/python/include/python2.Y for a Python 2 build on Linux.
// - $HFS/python/include/python3.Ym for a Python 3 build on Linux.
// - $HFS/Frameworks/Python.framework/Versions/Current/include/python2.Y for a Python 2 build on macOS.
// - $HFS/Frameworks/Python.framework/Versions/Current/include/python3.Ym for a Python 3 build on macOS.
// - %HFS%/pythonXY/include for a Python 2 or 3 build on Windows.
//
// For example, to build the module for a Python 2.7 build on Linux, do:
// hcustom -I $HFS/python/include/python2.7 -i $HOME/houdini20.0/python2.7libs _hdk_sample_hom_extensions.C
//
// Another example, to build the module for a Python 3.7 build
// on macOS, do:
// hcustom -I $HFS/Frameworks/Python.framework/Versions/Current/include/python3.7m -i $HOME/houdini20.0/python3.7libs _hdk_sample_hom_extensions.C
//
// This file is needed for all HDK plugins:
// We include this file only to get the forward declaration for
// HOMextendLibrary(). See below for details.
#include <HOM/HOM_Module.h>
// This file contains functions that will run arbitrary Python code:
#include <PY/PY_Python.h>
void
{
// When the hou module is first imported, Houdini will call functions named
// HOMextendLibrary in HDK dso's. This function is declared in an extern
// "C" in HOM_Module.h.
// Run some Python code to add a method to the hou.ObjectNode class that
// will call our custom function. We create a Python function
// that takes in a hou.ObjNode instance. That function calls path()
// on the instance to get the full path to the object node, and passes
// that path and other arguments to the function in the _hom_extensions
// module. Then that function is assigned to a method in hou.ObjNode
// and the function's name is removed from the global dictionary.
"def _setSelectable(self, selectable):\n"
" '''Make this node selectable/unselectable in the viewport\n"
" and network editor.'''\n"
" import _hdk_sample_hom_extensions\n"
" _hdk_sample_hom_extensions.ObjNode_setSelectable(\n"
" self.path(), selectable)\n"
"__import__('hou').ObjNode.setSelectable = _setSelectable\n"
"del _setSelectable\n");
}