├── LICENSE ├── README.md ├── snippets ├── addVrayMaterialIds.py ├── addVrayObjectIds.py ├── addVraySubdivisionAttributes.py ├── autoRenderViewMinimize.py ├── forceHideRenderView.py └── vrayFrameBufferFix.py └── tutorials ├── 01_gettingStarted.py ├── 02_deeperIntoVrayAttributes.py └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mayaVrayCommandDocs 2 | =================== 3 | 4 | Documentation & Code Snippets for Maya's V-Ray commands. 5 | 6 | This was originally designed to be a place to find commonly used functions from the V-Ray for Maya plug-in along with documentation about their usage and functionality. With V-Ray 3.0 for Maya being released alongside its documentation many of the features are currently clearly documentation in Chaosgroup's [official documentation for V-Ray 3.0](http://docs.chaosgroup.com/display/VRAY3MAYA/V-Ray+3.0+for+Maya+Help+Home). 7 | 8 | Unfortunately functionality of the commands available to you in Maya are still hard to find in the documentation (if even documented). This means there's still plenty here to find that could be a treasure of information to many. I hope to update it soon with some of the new commands featured in V-Ray 3.0+. 9 | 10 | With V-Ray 3.0 the commands in Maya also can present you with information, for example try running (Python): 11 | ```python 12 | import maya.cmds as mc 13 | mc.vray() 14 | ``` 15 | 16 | 17 | ###See the [Maya V-ray Commands Wiki](https://github.com/BigRoy/mayaVrayCommandDocs/wiki) for documentation. 18 | 19 | We're trying to build up documentation for V-ray for Maya's code base. 20 | 21 | First focusing on all the built-in commands that come with a V-ray for Maya installation, like the extremely bad documented `vray` command. 22 | 23 | This documentation can be found in this repository's Wiki (see link above). 24 | 25 | If you're working extensively with Maya and are scripting a lot for it have a look at the framework/library that we 26 | developed for working with V-ray for Maya: 27 | 28 | - [vrayformayaUtils repository on GitHub](https://github.com/BigRoy/vrayformayaUtils/) 29 | 30 | The `vrayformayaUtils` could first be found directly in this repository. But since it's growing into a bigger code 31 | library/framework we've decided to seperate it into its own repository. 32 | 33 | 34 | ###Snippets 35 | 36 | On the other hand there are the `snippets`. You could consider that the quick stop for finding your script to deal witha certain repetitive tasks. This is where you should go if you want to get started quickly. 37 | 38 | I'll add some more example functions in the repository over time. 39 | With this we hope to share some of the knowledge that we've gained from using V-ray over time and the increasing need we had to improve the efficiency of our workflow. 40 | 41 | Getting to a higher level of automatisation is closely related to understanding how to script your way through the basics. 42 | We are trying to help out on that part by sharing small code snippets focused on getting tasks done. 43 | By making this open-source we also hope to learn a lot from others and their ideas on the V-ray for Maya workflow. 44 | 45 | *In the snippets section you can find some very useful code to help with fixing the v-ray for maya framebuffer bug.* 46 | 47 | 48 | ###Snippets (Quick Start) 49 | 50 | If you don't have a Technical Director in the studio or you're just looking for some quick and dirty scripts to help 51 | you out in your V-ray for Maya workflow this is where you start. Welcome! 52 | 53 | Most likely the code snippets are the most interesting thing here if you're looking to get started quickly. 54 | You can find them in the repository in the snippets directory. These are small scripts that don't require 55 | any of the dependencies other than a standard Maya installation with V-ray for Maya. 56 | 57 | 58 | ####[Use the snippets](snippets) 59 | 60 | In short, you could copy the raw code of one of the snippets and paste it into the Maya script editor. 61 | Note that all scripts here are written in **Python**, so make sure to run it in a Python tab. 62 | 63 | 64 | ####Get the scripts into your shelve. 65 | 66 | You can middle-mouse drag the script from your script editor onto your Maya shelf to create an icon for it. You can 67 | easily label, annotate and customize it by clicking on the small triangle on the shelf at the left of the screen, click 68 | _Shelf Editor..._ 69 | 70 | 71 | ###Tutorials 72 | 73 | Along the way I'll try to add more and more very simple introductory tutorials to get anyone who wants to delve into 74 | Python scripting for V-ray for Maya. 75 | 76 | *The tutorials can be found in the ``tutorials`` directory in the repository.* 77 | 78 | 79 | ###Help the Vray for Maya community 80 | 81 | If you have any good documentation, tips or code snippets for Vray for Maya feel free to fork the repository and start adding away. 82 | 83 | Note that this is a personal/community project so we can't deliver 24-hour support, but whenever you have some questions feel free to contact me at roy@colorbleed.nl 84 | 85 | And if it's really V-ray related (and not to the code provided here) make sure to contact Chaosgroup support. 86 | 87 | -------------------------------------------------------------------------------- /snippets/addVrayMaterialIds.py: -------------------------------------------------------------------------------- 1 | import maya.cmds as mc 2 | 3 | 4 | def addVrayMaterialIds(materials=None): 5 | """ Add a vray_material_id attribute to selected materials (and related materials from objects) 6 | 7 | :param materials: Materials to apply the attribute to. If materials is None it will get 8 | the materials related to the current selection. 9 | """ 10 | if materials is None: 11 | # Get selected materials 12 | materials = mc.ls(sl=1, mat=1) 13 | 14 | # Get materials related to selection (material from object) 15 | # And add those materials to the material list we already have 16 | sel = mc.ls(sl=1) 17 | if sel: 18 | sel_history = mc.listHistory(sel,f=1) 19 | if sel_history: 20 | sel_connections = mc.listConnections(sel_history) 21 | if sel_connections: 22 | connected_materials = mc.ls(sel_connections, mat=True) 23 | if connected_materials: 24 | materials = set(materials) 25 | materials.update(connected_materials) 26 | materials = list(materials) 27 | else: 28 | # filter input to materials only 29 | materials = mc.ls(materials, mat=1) 30 | 31 | if not materials: 32 | raise RuntimeError("No materials found") 33 | 34 | if materials: 35 | result = mc.promptDialog(title='Material ID value', 36 | message='Material ID:', 37 | button=['OK', 'Cancel'], 38 | defaultButton='OK', 39 | cancelButton='Cancel', 40 | dismissString='Cancel') 41 | 42 | if result == 'OK': 43 | value = int(mc.promptDialog(query=True, text=True)) 44 | for mat in materials: 45 | mc.vray("addAttributesFromGroup", mat, "vray_material_id", 1) 46 | mc.setAttr("{0}.{1}".format(mat, 'vrayMaterialId'), value) 47 | 48 | 49 | if __name__ == "__main__": 50 | addVrayMaterialIds() -------------------------------------------------------------------------------- /snippets/addVrayObjectIds.py: -------------------------------------------------------------------------------- 1 | import maya.cmds as mc 2 | 3 | 4 | def addVrayObjectIds(shapes=None): 5 | """ Add a vray_objectID attribute to selected meshes 6 | 7 | :param shapes: Shapes to apply the attribute to. If shapes is None it will get 8 | the shapes related to the current selection. 9 | """ 10 | if shapes is None: 11 | shapes = mc.ls(sl=1, s=1, dag=1, lf=1, o=1, long=True) 12 | 13 | if shapes: 14 | # Can only add objectIds to mesh, nurbsSurface so lets filter it 15 | shapes = mc.ls(shapes, type=("mesh", "nurbsSurface")) 16 | 17 | if shapes: 18 | result = mc.promptDialog(title='Object ID value', 19 | message='Object ID:', 20 | button=['OK', 'Cancel'], 21 | defaultButton='OK', 22 | cancelButton='Cancel', 23 | dismissString='Cancel') 24 | 25 | if result == 'OK': 26 | value = int(mc.promptDialog(query=True, text=True)) 27 | 28 | for shape in shapes: 29 | mc.vray("addAttributesFromGroup", shape, "vray_objectID", 1) 30 | mc.setAttr("{0}.{1}".format(shape, 'vrayObjectID'), value) 31 | 32 | 33 | if __name__ == "__main__": 34 | addVrayObjectIds() -------------------------------------------------------------------------------- /snippets/addVraySubdivisionAttributes.py: -------------------------------------------------------------------------------- 1 | import maya.cmds as mc 2 | 3 | 4 | def addVraySubdivisionAttribute(shapes=None): 5 | """ Add a v-ray subdivision attribute to selected meshes 6 | 7 | :param shapes: Shapes to apply the attribute to. If shapes is None it will get 8 | the shapes related to the current selection. 9 | """ 10 | 11 | if shapes is None: 12 | shapes = mc.ls(sl=1, s=1, dag=1, lf=1, o=1, long=True) 13 | 14 | if shapes: 15 | # Only apply to mesh or nurbsSurface (other shapes can't contain the vray_subdivision attribute) 16 | shapes = mc.ls(shapes, type=("mesh", "nurbsSurface")) 17 | 18 | if shapes: 19 | for shape in shapes: 20 | mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 1) 21 | else: 22 | raise RuntimeError("No shapes found to apply the vray_subdivision attribute group to.") 23 | 24 | 25 | if __name__ == "__main__": 26 | addVraySubdivisionAttribute() -------------------------------------------------------------------------------- /snippets/autoRenderViewMinimize.py: -------------------------------------------------------------------------------- 1 | import maya.cmds as mc 2 | 3 | 4 | def autoRenderViewMinimize(state=None, renderView="renderViewWindow"): 5 | """ Overrides the renderView's restore command so that it directly minimizes again. 6 | 7 | This is especially useful when rendering with V-ray Framebuffer enabled, 8 | because on rendering it 'pops up' the default maya render view (which is extremely annoying). 9 | Enabling this autoRenderViewMinimize will directly minimize the render view window when the render starts. 10 | 11 | Default value for state is None. This means the value will depend on user input during the execution of the script. 12 | If the user holds any of the following keys the autoRenderViewMinimize will be disabled: Shift, Alt, Control. 13 | This makes it an easy to use shelf button script. :) 14 | 15 | Note: You should leave the render view window open, but minimized. Because Maya's render view code has been hard 16 | coded this to re-open and resize this is really the only viable way to hide it without breaking stuff. 17 | Until chaosgroup overrides the functionality - eg. hiding the render view when their renderer (or 18 | framebufffer) kicks in - this is a neat solution. 19 | 20 | Note: Another way might be to dock the renderView window to your interface and hide it. This way it will not pop up. 21 | But because Maya (auto-)resizes the top window if the view is too small when pressing the render button in the 22 | UI it will resize Maya's main window (because that is then the top window.) 23 | A reference to this method can be found here: http://polygonspixelsandpaint.tumblr.com/post/68136553566 24 | 25 | :param state: The state to set the autoRenderViewMinimize to. 26 | 27 | A True value will open and minimize the render view and override the minimize/restore state functionality. 28 | A False value will make sure the functionality is removed. 29 | 30 | If None it will default to True, 31 | unless during the run of the script the user pressed (hold it to be sure) any of the following keys: 32 | - Shift 33 | - Alt 34 | - Control. 35 | 36 | :type state: bool or None 37 | 38 | :param renderView: The name of the renderView window object to act upon. 39 | 40 | The maya default renderView window object is called: "renderViewWindow". This is the default value. 41 | :type renderView: str 42 | 43 | :rtype: bool 44 | :return: The resulting state 45 | """ 46 | 47 | if state is None: 48 | # If state is None we allow the user to set the state by whether they have pressed a modifier button during execution. 49 | # If any modifier key is pressed when the script is running then the RenderView minimize override is disabled. (force removed) 50 | # So to disable the functionality run this script while holding: Shift, Alt and/or Control. Else it will enable 51 | # the functionality. 52 | state = not (mc.getModifiers()) 53 | print "Setting the override render view minimize to: {0}".format(state) 54 | 55 | if state: 56 | if not mc.window(renderView, q=1, exists=True): 57 | mc.RenderViewWindow() # RuntimeCommand (to force create the renderView) 58 | 59 | renderViewMinimize = lambda: mc.window(renderView, e=True, i=True) 60 | renderViewMinimize() # Minimize the renderView 61 | mc.window(renderView, e=True, restoreCommand=renderViewMinimize) # Override the renderView restore command 62 | else: 63 | if mc.window(renderView, q=1, exists=True): 64 | mc.deleteUI(renderView) 65 | mc.RenderViewWindow() 66 | 67 | return state 68 | 69 | 70 | if __name__ == "__main__": 71 | autoRenderViewMinimize() -------------------------------------------------------------------------------- /snippets/forceHideRenderView.py: -------------------------------------------------------------------------------- 1 | import maya.cmds as mc 2 | import maya.utils as mutils 3 | 4 | 5 | def getRenderSize(): 6 | return mc.getAttr("defaultResolution.width"), mc.getAttr("defaultResolution.height") 7 | 8 | 9 | def forceHideRenderView(state=None, renderViewWindow="renderViewWindow", renderView="renderView", 10 | min_size=(999999, 999999), label="CLICK HERE TO KILL HIDE RENDER VIEW"): 11 | """ Hides the renderView in a dock control. 12 | 13 | This (force) hides the renderView in a dockControl in the right area of you Main Window. 14 | By doing that the renderView doesn't pop-up when you use the V-ray Framebuffer, sweet! 15 | 16 | HOW TO DISABLE: 17 | To disable just run this again with state=None (toggles), or force it by state=False. 18 | You could also right mouse click on the draggable part of that dockControl area, 19 | (which is normally the attribute editor / channel box area) and then click on the label: 20 | "CLICK HERE TO KILL HIDE RENDER VIEW" 21 | 22 | Note: 23 | This hack might spit out the following errors: 24 | // Error: line 1: No window found. // 25 | Yet as far as I know it's never doing any harm. 26 | 27 | A workaround for that error is depicted here: http://polygonspixelsandpaint.tumblr.com/post/68136553566 28 | 29 | -- warning -- 30 | The code snippet on that website seems to be problematic under Windows, as it resizes the main 31 | window even with Auto Resize set to False. (tested on Maya 2014 ext 1, Windows 7 64 bit) This function has 32 | a work-around for that. Though the work-around should work similarly. :) 33 | 34 | 35 | :param state: The state to enable/disable the forceHideRenderView functionality. 36 | 37 | A True value will enable the hiding functionality 38 | A False value will disable the hiding functionality. 39 | A None value will toggle the hiding functionality. 40 | 41 | :type state: bool or None 42 | 43 | :param renderViewWindow: The name of the renderView window object to act upon. 44 | The maya default renderView window object is called: "renderViewWindow". 45 | This is the default value; normally this requires no changes. 46 | :type renderViewWindow: str 47 | 48 | 49 | :param renderView: The name of the renderView object to act upon. 50 | The maya default renderView object is called: "renderView". 51 | This is the default value; normally this requires no changes. 52 | :type renderViewWindow: str 53 | 54 | :param min_size: The minimum size enforced for the controls. Setting this very high avoids the main window being 55 | resized when rendering high resolution images. (A workaround for stupid Autodesk UI functionality.) 56 | :type min_size: (int, int) 57 | 58 | :param label: The label that will show in the dock control right menu as a label. 59 | :type label: str 60 | 61 | :rtype: bool 62 | :return: The resulting state 63 | 64 | """ 65 | UI_OBJ = "rendEditorDC" 66 | 67 | if state is None: 68 | state = not mc.dockControl(UI_OBJ, q=1, exists=True) 69 | 70 | if mc.dockControl(UI_OBJ, q=1, exists=True): 71 | mc.deleteUI(UI_OBJ) 72 | 73 | if state: 74 | # Show the render view so we can parent it to our dock control 75 | if not mc.window(renderViewWindow, q=1, exists=True): 76 | mc.RenderViewWindow() 77 | 78 | # Uses either the minimum size or the size of the render settings + 250 (just to be sure) 79 | size = [max(x, y+250) for x, y in zip(min_size, getRenderSize())] 80 | 81 | def __deleteRenderViewHideDockControl(*args): 82 | # If it's made visible we hide it and delete it. 83 | # We use executeDeferred because otherwise we'll get a fatal error. :) 84 | if mc.dockControl(UI_OBJ, q=1, visible=True): 85 | mc.dockControl(UI_OBJ, e=1, visible=False) 86 | mutils.executeDeferred(lambda: mc.deleteUI(UI_OBJ)) 87 | 88 | 89 | if not mc.dockControl(UI_OBJ, q=1, exists=True): 90 | lyt = mc.scrollLayout() 91 | dock = mc.dockControl(UI_OBJ, area="right", content=renderViewWindow, 92 | visible=False, epo=True, manage=False, vcc=__deleteRenderViewHideDockControl, 93 | label=label) 94 | 95 | # This is the same control the renderWindowPanel.mel script checks for the size . 96 | # We just need to make it big enough so it doesn't call a resize of the top UI element. 97 | renderWindowControl = mc.scriptedPanel(renderView, q=True, control=True) 98 | mc.control(renderWindowControl, e=1, w=size[0], h=size[1], visible=False) 99 | 100 | print "ENABLED HIDE RENDER VIEW" 101 | else: 102 | print "DISABLED HIDE RENDER VIEW" 103 | 104 | 105 | if __name__ == "__main__": 106 | forceHideRenderView() -------------------------------------------------------------------------------- /snippets/vrayFrameBufferFix.py: -------------------------------------------------------------------------------- 1 | import maya.cmds as mc 2 | import os 3 | 4 | 5 | def vrayFrameBufferFix(): 6 | """ Fixes missing V-ray FrameBuffer 7 | 8 | It happens from time to time that the V-ray frame buffer just disappears and won't pop up. 9 | In that scenario it's probably the good old V-ray for Maya framebuffer bug striking again. 10 | When that happens this script will come to the rescue. 11 | 12 | It will save your file as a temporary .ma file, removes the buggy ASCII code of the 13 | framebuffer, reopens the temp file and internally renames it to your original file. 14 | 15 | Note: It doesn't automatically save it over your original file even though it might 16 | look like it because it shows the original filename at the top. 17 | Save your scene when it worked. :) 18 | """ 19 | current_dir = os.path.dirname(mc.file(query=True, sceneName=True)) 20 | current_name, current_ext = os.path.splitext(mc.file(query=True, sceneName=True)) 21 | fix_file_suffix = "_temp_vrayfb_fix.ma" 22 | confirm = mc.confirmDialog(title='O RLY?', message='Did you backup your file already?', button=['Yes', 'No'], 23 | defaultButton='Yes', cancelButton='No', dismissString='No') 24 | 25 | if confirm == "Yes": 26 | # Save file 27 | path_current_file = mc.file(force=True,save=1,options="v=0") 28 | 29 | # Save Ma file to fix it (if it's not yet a fix .ma file 30 | if path_current_file.endswith(fix_file_suffix): 31 | raise RuntimeError("You're already working in the _temp_vrayfb_fix file?") 32 | 33 | mc.file(rename="%s%s" % (current_name,fix_file_suffix)) 34 | path_fix_save = mc.file(force=True, save=1, options="v=0", type="mayaAscii") 35 | 36 | # Change .ma file 37 | fin = open(path_fix_save, "r") 38 | mafile = fin.readlines() 39 | fin.close() 40 | fixed_mafile = [] 41 | 42 | remove = 0 43 | foundEOL = 0 44 | for line in mafile: 45 | if 'setAttr ".vfbSA"' in line: 46 | remove = 1 47 | 48 | if remove == 1: 49 | if ';' in line: 50 | foundEOL = 1 51 | if 'setAttr' in line and not 'setAttr ".vfbSA"' in line: 52 | remove = 0 53 | 54 | if remove == 0: 55 | fixed_mafile.append(line) 56 | 57 | if foundEOL == 1: 58 | remove = 0 59 | 60 | fout = open(path_fix_save, "w") 61 | fout.writelines(fixed_mafile) 62 | fout.close() 63 | print path_fix_save 64 | 65 | # Open fixed file 66 | mc.file(path_fix_save, f=True, options="v=0", typ="mayaAscii", o=1) 67 | 68 | # Rename scene to original (without saving) 69 | mc.file(rename=path_current_file) 70 | 71 | os.remove(path_fix_save) 72 | print "Fixed!" 73 | 74 | 75 | if __name__ == "__main__": 76 | vrayFrameBufferFix() -------------------------------------------------------------------------------- /tutorials/01_gettingStarted.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | This **gettingStarted** tutorial should allow you to get up on your feet quickly to work with Chaosgroup's ``vray`` 4 | command in Maya with Python. 5 | 6 | For a very short overview of the tutorials have a look at the README that resides in the tutorials directory. 7 | 8 | """ 9 | 10 | # To start we need to import the maya commands. Because everyone likes short names it's often imported as ``mc``. 11 | # So let's do that: 12 | 13 | import maya.cmds as mc 14 | 15 | # This allows us to use Maya's command features in our code. 16 | # For example we can list all mesh shapes in our scene, like: 17 | 18 | print mc.ls(type="mesh") 19 | 20 | # But hey, you came here to do some v-ray for maya magic. 21 | # 22 | # This is the moment where you make sure the vrayformaya.mll is loaded in your Plug-in Manager. 23 | # You can find it in: Window > Settings/Preferences > Plug-in Manager 24 | # Search for the vrayformaya.mll and make sure the loaded checkbox is checked. 25 | # 26 | # Basically most of the stuff you can do with commands provided from the V-ray for Maya plug-in is done through a 27 | # command called ``vray``. Commands created by plug-ins are available in the maya.cmds namespace. 28 | # In short we can do something like: 29 | 30 | mc.vray() 31 | 32 | # Note that this doesn't give any errors, but it doesn't do anything either. 33 | # By having a look at the wiki documentation on this repository you'll find what you can provide as arguments: 34 | # https://github.com/BigRoy/mayaVrayCommandDocs/wiki 35 | # 36 | # Many people getting started with v-ray for maya scripting are doing it to help ease the adding of v-ray attributes. 37 | # So let's start there. Adding v-ray attributes is done through the ``vray`` command with the action 38 | # ``addAttributesFromGroup``. More information here: 39 | # https://github.com/BigRoy/mayaVrayCommandDocs/wiki/vray-addAttributesFromGroup 40 | # 41 | # The example on that page shows us: 42 | 43 | shapes = mc.ls(sl=1, dag=1, lf=1, s=1) 44 | for shape in shapes: 45 | mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 1) 46 | 47 | # So what does that do? 48 | # First it gets all shapes from the current selection. 49 | # Then we loop over all of these shapes, 50 | # To add a ``vray_subdivision`` attribute to every single on of them. 51 | # EASY! 52 | # 53 | # So the command to add the attributes is basically in the format of: 54 | # 55 | # mc.vray("addAttributesFromGroup", node, attr, state) 56 | # 57 | # Where: 58 | # `node` is the node to apply the command to. (this should be of the correct type) 59 | # `attr` is the attribute type/group to create. (some variations can be found in the wiki documentation) 60 | # `state` is an integer (1 or 0) to either create or remove the attributes. (note: True or False don't work correctly!) 61 | # 62 | # Now let's remove it again by changing the state parameter. 63 | 64 | shapes = mc.ls(sl=1, dag=1, lf=1, s=1) 65 | for shape in shapes: 66 | mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 0) 67 | 68 | # This should get you up and running with interpreting the WIKI documentation and writing your own code. 69 | # Play around with creating different types of v-ray attributes. -------------------------------------------------------------------------------- /tutorials/02_deeperIntoVrayAttributes.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | This **deeperIntoVrayAttributes** tutorial will help you delve deeper into the 4 | ``mc.vray("addAttributesFromGroup",..)`` command. 5 | 6 | For a very short overview of the tutorials have a look at the README that resides in the tutorials directory. 7 | 8 | """ 9 | 10 | # So you've gone through tutorial 01 and want to go a bit further. You can't do much automatisation in Maya with V-ray 11 | # if you don't have a grasp on how to write small scripts for Maya. So let start with some tips. 12 | 13 | # 1. The script editor is useful to have a look at what commands maya performs when you do something in Maya. 14 | # 15 | # For example select something in the viewport and you'll set something like: 16 | # 17 | # select -r pSphere1 ; 18 | # 19 | # The commands that maya will spit out in the script editor are in MEL. So there might be some syntax adjustments 20 | # required to do the same magic in Python, but in general you can use it as a good learning resource. 21 | 22 | 23 | # 2. If you use the script editor and the command doesn't show up, try turning on "Echo all commands" in the "History" 24 | # menu in the script editor. 25 | # 26 | # This will show all mel commands (and sourced script commands) that Maya runs when performing actions. Though note 27 | # that leaving this on during normal operations Maya might slow down a bit (as it's printing more into the script 28 | # editor.) Turning this off after using it is a good habit. 29 | 30 | 31 | # 3. The Python/Mel Command Reference (Help > Python Command Reference) 32 | # 33 | # The command reference shows a list of all built-in maya commands. They come with a brief explanation and with 34 | # some examples as well. Useful! :) 35 | 36 | # One important command is ``mc.ls()`` 37 | # It's essentially a **list** command and returns a list of node names. Either from selection, or by name or type, etc. 38 | 39 | # To get the current selection: 40 | import maya.cmds as mc 41 | print mc.ls(selection=True) 42 | 43 | 44 | # Or with the short hand flag for selection (-sl): 45 | import maya.cmds as mc 46 | print mc.ls(sl=True) 47 | 48 | 49 | # Now let's say we wanted to get all transform nodes in our current selection: 50 | import maya.cmds as mc 51 | print mc.ls(sl=True, type="transform") 52 | 53 | 54 | # Or only the polygon meshes: 55 | import maya.cmds as mc 56 | print mc.ls(sl=True, type="mesh") 57 | 58 | 59 | # Play around with the mesh version. You'll see that when you select the object in your viewport (what you might think 60 | # is the mesh) and run this it will return an empty list. Nothing? 61 | 62 | # That's because you're essentially selecting the transform node of the object. The transform node is that thing that 63 | # tells maya where it is positioned in the scene. You see this behaviour for all shape nodes, they are parented under 64 | # a transform node. For example a camera is under a transform. It's the same for a nurbsSurface, or nurbsCurve, etc. 65 | 66 | # This is a KEY thing to remember: The shape node is seperate from the transform. It's literally it's child. 67 | 68 | # The transform node itself is essentially a group, to show this let's make a polygon cube. 69 | # Select it in the viewport and press the down arrow on the keyboard. 70 | # This will pickwalk down from that node onto its child node, that is the shape! 71 | # Press delete. 72 | # The shape will be gone, but the transform will still be there. Look at the icon of the node of the transform that is 73 | # still there in the outliner. Looks familiar? It should, because it's exactly the icon of a group (NULL). 74 | 75 | # To get the shape from your selected transforms you need to do exactly that: Go one down in the hierarchy. Or we could 76 | # say: Get its children. In Maya we did that by using ``listRelatives``. 77 | 78 | import maya.cmds as mc 79 | selection = mc.ls(sl=1) 80 | print selection 81 | if selection: 82 | children = mc.listRelatives(selection, children=True) 83 | print children 84 | 85 | 86 | # Let's say we wanted to have all mesh shapes of our currently selected transforms, we can do: 87 | import maya.cmds as mc 88 | selection = mc.ls(sl=1) 89 | print selection 90 | if selection: 91 | meshes = mc.listRelatives(selection, children=True, type="mesh") 92 | print meshes 93 | 94 | 95 | # Or all shapes: 96 | import maya.cmds as mc 97 | selection = mc.ls(sl=1) 98 | print selection 99 | if selection: 100 | shapes = mc.listRelatives(selection, children=True, shapes=True) 101 | print shapes 102 | 103 | # More information about the ls command and listRelatives command can be found in the Python command reference. 104 | # See point 3 at the start of this tutorial for more information about the Python command reference. 105 | # Play around with mc.ls and mc.listRelatives until you feel somewhat familiar. 106 | 107 | # To be continued. :) 108 | # Now you should know the difference between transforms and their children shapes. 109 | # Let's get all transform nodes that end with "*_SMOOTH" and add a subdivision attribute to it's children mesh shapes. 110 | 111 | import maya.cmds as mc 112 | # Get all transform nodes that end with _SMOOTH 113 | nodes = mc.ls("*_SMOOTH", type="transform") 114 | if nodes: 115 | # Get the children shapes of type mesh 116 | meshes = mc.listRelatives(nodes, children=True, shapes=True, type="mesh") 117 | # If we found children meshes, then for every mesh shape node add the vray_subdivision attribute. 118 | if meshes: 119 | for mesh in meshes: 120 | mc.vray("addAttributesFromGroup", "vray_subdivision", mesh, 1) 121 | 122 | # We can do something similar for all nurbsCurves that we want to make renderable. If we have given a specific suffix 123 | # to the nodes we can easily address them. 124 | # So I've discussed with the team and we went for "_EXTREMELY_RENDERABLE_CURVE" as a suffix on the transform node of 125 | # the nurbsCurves. 126 | 127 | # Ah yeah, let's get those transforms! 128 | import maya.cmds as mc 129 | nodes = mc.ls("*_EXTREMELY_RENDERABLE_CURVE", type="transform") 130 | print nodes 131 | 132 | # So we play around and test if it is giving us the nodes. Did you try it? 133 | # Then go on and get the children nurbsCurve shape nodes. 134 | 135 | if nodes: 136 | nurbsCurves = mc.listRelatives(nodes, children=True, shapes=True, type="nurbsCurve") 137 | print nurbsCurves 138 | 139 | # Still looking good? 140 | # All we need to do now is add the ``vray_nurbscurve_renderable`` attribute. 141 | # It's very similar to what we did so far. Easy! 142 | 143 | for shape in nurbsCurves: 144 | mc.vray("addAttributesFromGroup", "vray_nurbscurve_renderable", shape, 1) 145 | 146 | # Simple as that! 147 | # To make sure you understand correctly try adding the ``vray_skip_export`` to selected transform nodes. 148 | # Then maybe try adding ``vray_objectID`` attributes to all children shapes of your selection. :) 149 | -------------------------------------------------------------------------------- /tutorials/README.md: -------------------------------------------------------------------------------- 1 | mayaVrayCommandDocs Tutorials 2 | ============================= 3 | 4 | These tutorials are meant to help anyone getting up to speed to writing some scripts for v-ray for maya. 5 | 6 | The easiest way is to start at the beginning and use the [wiki page](https://github.com/BigRoy/mayaVrayCommandDocs/wiki) 7 | as complementary information when working through some functions. For example when you start using 8 | `mc.vray("addAttributesFromGroup", ..)` also have a look at the ["vray addAttributesFromGroup documentation"](https://github.com/BigRoy/mayaVrayCommandDocs/wiki/vray-addAttributesFromGroup). 9 | 10 | 11 | 01. Getting Started 12 | ------------------- 13 | 14 | This will very quickly introduce you on how to import maya commands into Python and call the mc.vray() command. 15 | Then we hop into adding the `vray_subdivision` attribute to mesh nodes. 16 | 17 | 18 | 02. Deeper into V-ray Attributes 19 | -------------------------------- 20 | 21 | This chapter will go a tiny bit deeper (but still very basic level) into adding v-ray attributes to only the nodes you 22 | want it to. We will get children shapes from transform and apply the `vray_subdivision` and `vray_nurbscurve_renderable` 23 | attributes. At the end you should have a good grasp on adding any v-ray attribute you need to exactly the object you 24 | want in your maya scene. 25 | 26 | 27 | Have some ideas? 28 | ---------------- 29 | 30 | We're doing these tutorials on the side so it'll likely evolve a bit slower then someone might want. 31 | If you're looking for something specific or have cool ideas to be added in here give me a heads up at roy@colorbleed.nl. 32 | Then I'll see what I can do. Or you can fork and branching the repository and start building on it. :) --------------------------------------------------------------------------------