HDK
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
ObjNode_setSelectable.C
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024
3
* Side Effects Software Inc. All rights reserved.
4
*
5
* Redistribution and use of Houdini Development Kit samples in source and
6
* binary forms, with or without modification, are permitted provided that the
7
* following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. The name of Side Effects Software may not be used to endorse or
11
* promote products derived from this software without specific prior
12
* written permission.
13
*
14
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*
25
*----------------------------------------------------------------------------
26
*/
27
28
//****************************************************************************
29
//****************************************************************************
30
//****************************************************************************
31
//
32
// WARNING
33
//
34
// This example is deprecated, and is largely replaced by the inlinecpp
35
// Python module. Except for the ability to raise exceptions, you can
36
// implement this example with the following Python code:
37
//
38
// inlinecpp.extendClass(
39
// hou.ObjNode,
40
// "node_methods",
41
// includes="#include <UT/UT_UndoManager.h>",
42
// function_sources=["""
43
// void setSelectable(OBJ_Node *obj_node, int selectable)
44
// {
45
// if (!obj_node->canAccess(PRM_WRITE_OK))
46
// return;
47
//
48
// UT_AutoUndoBlock undo_block("Setting selectable flag", ANYLEVEL);
49
// obj_node->setPickable(selectable != 0);
50
// }
51
// """])
52
//
53
//****************************************************************************
54
//****************************************************************************
55
//****************************************************************************
56
57
// This sample shows how to extend HOM using C++. It adds a
58
// hou.ObjNode.setSelectable method that makes an object node selectable/
59
// unselectable in the viewport.
60
//
61
// NOTE: The _hdk_sample_hom_extensions extension module must first be built.
62
// _hdk_sample_hom_extensions.C, which is located in the same
63
// directory as this file, contains the module source.
64
//
65
// You can build the extension module using hcustom:
66
// hcustom -I <hfs_python_include_dir> -i $HOME/houdini20.5/pythonX.Ylibs _hdk_sample_hom_extensions.C
67
//
68
// where:
69
// - "X" is the Python major version that Houdini is built against.
70
// - "Y" is the Python minor version that Houdini is built against.
71
// - <hfs_python_include_dir> is:
72
// - $HFS/python/include/python2.Y for a Python 2 build on Linux.
73
// - $HFS/python/include/python3.Ym for a Python 3 build on Linux.
74
// - $HFS/Frameworks/Python.framework/Versions/Current/include/python2.Y for a Python 2 build on macOS.
75
// - $HFS/Frameworks/Python.framework/Versions/Current/include/python3.Ym for a Python 3 build on macOS.
76
// - %HFS%/pythonXY/include for a Python 2 or 3 build on Windows.
77
//
78
// For example, to build the module for a Python 2.7 build on Linux, do:
79
// hcustom -I $HFS/python/include/python2.7 -i $HOME/houdini20.5/python2.7libs _hdk_sample_hom_extensions.C
80
//
81
// Another example, to build the module for a Python 3.7 build
82
// on macOS, do:
83
// hcustom -I $HFS/Frameworks/Python.framework/Versions/Current/include/python3.7m -i $HOME/houdini20.5/python3.7libs _hdk_sample_hom_extensions.C
84
//
85
86
87
// This file is needed for all HDK plugins:
88
#include <
UT/UT_DSOVersion.h
>
89
90
// We include this file only to get the forward declaration for
91
// HOMextendLibrary(). See below for details.
92
#include <
HOM/HOM_Module.h
>
93
94
// This file contains functions that will run arbitrary Python code:
95
#include <
PY/PY_Python.h
>
96
97
void
98
HOMextendLibrary
()
99
{
100
// When the hou module is first imported, Houdini will call functions named
101
// HOMextendLibrary in HDK dso's. This function is declared in an extern
102
// "C" in HOM_Module.h.
103
104
// Run some Python code to add a method to the hou.ObjectNode class that
105
// will call our custom function. We create a Python function
106
// that takes in a hou.ObjNode instance. That function calls path()
107
// on the instance to get the full path to the object node, and passes
108
// that path and other arguments to the function in the _hom_extensions
109
// module. Then that function is assigned to a method in hou.ObjNode
110
// and the function's name is removed from the global dictionary.
111
PYrunPythonStatementsAndExpectNoErrors
(
112
"def _setSelectable(self, selectable):\n"
113
" '''Make this node selectable/unselectable in the viewport\n"
114
" and network editor.'''\n"
115
" import _hdk_sample_hom_extensions\n"
116
" _hdk_sample_hom_extensions.ObjNode_setSelectable(\n"
117
" self.path(), selectable)\n"
118
"__import__('hou').ObjNode.setSelectable = _setSelectable\n"
119
"del _setSelectable\n"
);
120
}
121
PY_Python.h
HOM_Module.h
PYrunPythonStatementsAndExpectNoErrors
PY_API bool PYrunPythonStatementsAndExpectNoErrors(const char *python_code, const char *heading=NULL, PY_EvaluationContext *context=NULL, const char *as_file=nullptr)
HOMextendLibrary
void HOMextendLibrary()
Definition:
ObjNode_setSelectable.C:98
UT_DSOVersion.h
samples
HOM
ObjNode_setSelectable.C
Generated on Thu Nov 7 2024 03:04:10 for HDK by
1.8.6