ChangeRenderFrameRange Script

From The Foundry MODO SDK wiki
Jump to: navigation, search

This simple script changes the first frame, last frame and frame step of the first render item in the scene. This is a bit easier than calling three separate item.channel commands and making sure that the first render item is actually selected.

<tabber>

Perl=@ChangeRenderFrameRange.pl first last <step>

|-|

LUA=@ChangeRenderFrameRange.lua first last <step>

|-|

Python=@ChangeRenderFrameRange.py first last <step>

</tabber>

The first and last frame arguments are required, while the frame step is optional. This sets the first frame to 1 and the last frame to 60.

<tabber>

Perl=@ChangeRenderFrameRange.pl 1 60

|-|

LUA=@ChangeRenderFrameRange.lua 1 60

|-|

Python=@ChangeRenderFrameRange.py 1 60

</tabber>

This script could be simplified by directly selecting the render items with Select.itemType, but this extended version can be used as a framework for other scripts that operate on item types.

<tabber>

Perl=
  1. # perl
  2. #
  3. # ChangeRenderFrameRange.pl
  4. #  Joe Angell, Luxology LLC
  5. #  Copyright (c) 2008 Luxology, LLC. All Rights Reserved.
  6. #   Patents pending.
  7. #
  8. # Changes the render frame range for the first render item
  9. #  in the scene.
  10.  
  11. # Make sure we have our arguments
  12. if( ($#ARGV != 1) && ($#ARGV != 2) ) {
  13.     lxout( "Usage: \@ChangeRenderFrameRange.pl first last <step>" );
  14.     lxout( "Changes the render frame range for the first render item in the scene." );
  15.     lxout( "First and last frame are required; frame step is optional." );
  16.     die( "Missing required first and last frame arguments" );
  17. }
  18.  
  19. # Get the item count
  20. my $n = lxq( "query sceneservice item.N ?" );
  21.  
  22. # Loop through the items in the scene, looking for output items
  23. for( $i=0; $i < $n; $i++ ) {
  24.     my $type = lxq( "query sceneservice item.type ? $i" );
  25.     if( $type eq "polyRender" ) {
  26.         # Get the item ID
  27.         $itemID = lxq( "query sceneservice item.id ? $i" );
  28.         #lxout( "Item ID:  $itemID" );
  29.  
  30.         # Select the item
  31.         lx( "select.item $itemID" );
  32.  
  33.         # Set the first frame
  34.         lx( "item.channel polyRender\$first $ARGV[0]" );
  35.  
  36.         # Set the last frame
  37.         lx( "item.channel polyRender\$last $ARGV[1]" );
  38.  
  39.         if($#ARGV==3){
  40.             # Set the frame step
  41.             lx( "item.channel polyRender\$step $ARGV[2]" );
  42.         }
  43.  
  44.         break;
  45.     }
  46. }

|-|

LUA=
  1. -- lua
  2. --
  3. -- ChangeRenderFrameRange.lua
  4. --  Joe Angell, Luxology LLC
  5. --  Copyright (c) 2008 Luxology, LLC. All Rights Reserved.
  6. --   Patents pending.
  7. --
  8. -- Changes the render frame range for the first render item
  9. --  in the scene.
  10.  
  11. -- Make sure we have our arguments
  12. if( (#arg != 1) && (#arg != 2) ) {
  13.     lxout( "Usage: @ChangeRenderFrameRange.lua first last <step>" );
  14.     lxout( "Changes the render frame range for the first render item in the scene." );
  15.     lxout( "First and last frame are required; frame step is optional." );
  16.     error( "Missing required first and last frame arguments" );
  17. }
  18.  
  19. -- Get the item count
  20. n = lxq( "query sceneservice item.N ?" );
  21.  
  22. -- Loop through the items in the scene, looking for output items
  23. for i=0,n do
  24.     type = lxq( "query sceneservice item.type ? "..i );
  25.     if type == "polyRender" then
  26.         -- Get the item ID
  27.         itemID = lxq( "query sceneservice item.id ? "..i );
  28.         -- lxout( "Item ID:  "..itemID );
  29.  
  30.         -- Select the item
  31.         lx( "select.item "..itemID );
  32.  
  33.         -- Set the first frame
  34.         lx( "item.channel polyRender$first "..arg[1] );
  35.  
  36.         -- Set the last frame
  37.         lx( "item.channel polyRender$last "..arg[2] );
  38.  
  39.         if #arg==3 then
  40.             -- Set the frame step
  41.             lx( "item.channel polyRender$step "..arg[3]" );
  42.         end
  43.  
  44.         break;
  45.     end
  46. end

|-|

Python=
  1. #python
  2. #
  3. # ChangeRenderFrameRange.py
  4. #  Joe Angell, Luxology LLC
  5. #  Copyright (c) 2008 Luxology, LLC. All Rights Reserved.
  6. #   Patents pending.
  7. #
  8. # Changes the render frame range for the first render item
  9. #  in the scene.
  10.  
  11. # Make sure we have our arguments
  12. args = lx.args()
  13. if not (len(args) == 2 or len(args) == 3):
  14.     lx.out( "Usage: @ChangeRenderFrameRange.py first last <step>" )
  15.     lx.out( "Changes the render frame range for the first render item in the scene." )
  16.     lx.out( "First and last frame are required; frame step is optional." )
  17.     sys.exit( "LXe_INVALIDARG:Missing required first and last frame arguments" )
  18.  
  19. # Get the item count
  20. n = lx.eval1( "query sceneservice item.N ?" )
  21.  
  22. # Loop through the items in the scene, looking for output items
  23. for i in range(n):
  24.     itemtype = lx.eval( "query sceneservice item.type ? %s" % i )
  25.  
  26.     if itemtype == "polyRender":
  27.         # Get the item ID
  28.         itemID = lx.eval( "query sceneservice item.id ?")
  29.         # lx.out( "Item ID:  ", itemID )
  30.  
  31.         # Select the item
  32.         lx.command( "select.item", item=itemID )
  33.  
  34.         # Set the first frame
  35.         lx.command( "item.channel", name="polyRender$first", value=args[0] )
  36.  
  37.         # Set the last frame
  38.         lx.command( "item.channel", name="polyRender$last", value=args[1] )
  39.  
  40.         if len(args) == 3:
  41.             # Set the frame step
  42.             lx.command( "item.channel", name="polyRender$step", value=args[2] )

</tabber>

More Information