Need help about scatter from Maya to standalone

Generic forum to discuss Octane Render, post ideas and suggest improvements.
Forum rules
Please add your OS and Hardware Configuration in your signature, it makes it easier for us to help you analyze problems. Example: Win 7 64 | Geforce GTX680 | i7 3770 | 16GB
spark31
Licensed Customer
Posts: 6
Joined: Sat May 23, 2015 7:57 pm
Location: LOS ANGELES
Contact:

It's not in a special folder, I have it by itself in a "octaneInstancer" folder inside another folder with all my maya scripts, on a separate drive. I just source it: "File"/"Source Script..." in the script editor, then select objets then run "octaneInstancer;" in a MEL shelf.
I can do a movie but not sure tonight I have to download a software for that.
Rikk The Gaijin
Licensed Customer
Posts: 1528
Joined: Tue Sep 20, 2011 2:28 pm
Location: Japan

It doesn't work for me, I tried also from Maya 2014, same error line 43: Cannot find procedure "octaneInstancerFile". :(
spark31
Licensed Customer
Posts: 6
Joined: Sat May 23, 2015 7:57 pm
Location: LOS ANGELES
Contact:

Sorry to hear I send you a pm with the screen grab movie
Rikk The Gaijin
Licensed Customer
Posts: 1528
Joined: Tue Sep 20, 2011 2:28 pm
Location: Japan

Thanks spark, but no luck for me. :(
Where are the devs when you need them? :x
Rikk The Gaijin
Licensed Customer
Posts: 1528
Joined: Tue Sep 20, 2011 2:28 pm
Location: Japan

UPDATE: THIS SCRIPT WORKS!
For some reason, it's different from the one you send me, but this one works like a charm! :lol:

Code: Select all

/*
Script : octaneInstancer.mel
Date : 05/12/2012
Version : 0.5
About : write a .csv file with matrices coming from selected transforms
and/or particleInstancers
Usage : mel command 'octaneInstancer'
Author : francois aka tchoa
with improvement since v0.5 of Clinton
http://www.scaphandrier.net/?p=303#comment-388 
Contact : [email protected] 
Copyrights(C)TreeX-2012
*/


global proc octaneInstancer()
{
if (!`window -ex octaneInstancer`){
window -s 1 -rtf 1 -tlb 1 -t "Octane Instancer" octaneInstancer;
columnLayout -adj 1;
floatSliderGrp -l "Scale" -cw3 30 50 30 -cal 3 "right" -ad3 3 -f 1 -pre 4 -min 0.01 -max 1 -fmn 0.0001 -fmx 10000 -v 1 octaneInstanceScale;
checkBox -l "Hierarchy" -v 1 octaneInstanceHi;
checkBox -l "Meshes Only" -v 0 octaneInstanceMo;
button -l "Export" -c "octaneInstancerDialog";
}
showWindow octaneInstancer;
}

global proc octaneInstancerDialog()
{
string $version = `about -v`;
string $buffer[];
tokenize $version " " $buffer;
int $year = $buffer[0];
if ($year < 2011){
string $path = `fileDialog -m 1 -dm "*.csv" -t "Export"`;
if ($path != "")
octaneInstancerFile($path);
}
else{
string $paths[] = `fileDialog2 -fm 0 -ff "octaneInstancerFile (*.csv)" -sff "Octane" -cap "Export"`;
if (`size $paths`)
octaneInstancerFile($paths[0]);
}
}

proc string getInstancesAttribute(string $attributes[], string $search)
{
string $attribute = "";
int $count = size($attributes); 
for ($i = 0; $i < $count; $i += 2){
if ($attributes[$i] == $search){
$attribute = $attributes[$i+1];
break;
}
}
return $attribute;
}

proc int getInstancerId(string $connection)
{
string $buffer[];
tokenize $connection "." $buffer;
tokenize $buffer[1] "[" $buffer;
tokenize $buffer[1] "]" $buffer;
return $buffer[0];
}

proc string getInstanceMatrix(string $transform)
{
float $scaleFactor = `floatSliderGrp -q -v octaneInstanceScale`;
string $data;
float $matrix[16] = `xform -q -ws -m $transform`;
for ($mid = 12; $mid < 15; $mid++)
$matrix[$mid] *= $scaleFactor;
$data += $matrix[0] + " " + $matrix[4] + " " + $matrix[8] + " " + $matrix[12] + " ";
$data += $matrix[1] + " " + $matrix[5] + " " + $matrix[9] + " " + $matrix[13] + " ";
$data += $matrix[2] + " " + $matrix[6] + " " + $matrix[10] + " " + $matrix[14] + "\n";
return $data;
}

proc getInstances(string $path, string $instancer)
{
float $scaleFactor = `floatSliderGrp -q -v octaneInstanceScale`;
string $particles = plugNode(`connectionInfo -sfd ($instancer + ".inputPoints")`);
string $instancerId = getInstancerId(`connectionInfo -sfd ($instancer + ".inputPoints")`);
string $attributes[] = `getAttr ($particles + ".idt["+ $instancerId +"].iam")`;
string $objects[];
int $num = `getAttr ($instancer + ".hierarchyCount")`;
for ($i = 0; $i < $num; $i++)
$objects[$i] = plugNode(`connectionInfo -sfd ($instancer + ".inputHierarchy[" + $i + "]")`);
string $ids = getInstancesAttribute($attributes, "objectIndex");
string $position = getInstancesAttribute($attributes, "position");
string $rotation = getInstancesAttribute($attributes, "rotation");
string $scale = getInstancesAttribute($attributes, "scale");
int $count = `getAttr ($instancer + ".instanceCount")`;
string $temp = `createNode "transform"`;
int $id = 0;
// Use integers for testing the existance of an attributes value (faster than comparing string
// values on every loop).
int $doPos = 0;
int $doScale = 0;
int $doRot = 0;
int $doIds = 0;
if ($position != "") $doPos = 1;
if ($rotation != "") $doRot = 1;
if ($scale != "") $doScale = 1;
if ($ids != "") $doIds = 1;

global string $gMainProgressBar;
progressBar -e -bp -ii 1 -max ($num * $count) -st "Parsing…" $gMainProgressBar;
for ($object in $objects){
string $_path = plugNode($path) + "_" + $object + ".csv";

// Build the particle data once, not every loop. This will have issues with massive data sets, though
// has been tested on 100,000 particles.
float $rotArray[];
float $posArray[];
float $scaleArray[];
if ($doRot)
$rotArray = `getParticleAttr -at $rotation -array true ($particles+".pt[0:"+$count+"]")`;
if ($doPos)
$posArray = `getParticleAttr -at $position -array true ($particles+".pt[0:"+$count+"]")`;
if ($doScale)
$scaleArray = `getParticleAttr -at $scale -array true ($particles+".pt[0:"+$count+"]")`;

$fileId = `fopen $_path "w"`;
for ($i = 0; $i < $count; $i++){
int $current = 0;
if ($doIds){
$tmpId = `particle -or $i -at $ids -q $particles`;
$current = $tmpId[0];
}
if ($id == $current){
if ($doPos)
setAttr ($temp + ".translate") $posArray[$i*3] $posArray[($i*3)+1] $posArray[($i*3)+2];
else
setAttr ($temp + ".translate") 0 0 0;

if ($doRot)
setAttr ($temp + ".rotate") $rotArray[$i*3] $rotArray[($i*3)+1] $rotArray[($i*3)+2];
else
setAttr ($temp + ".rotate") 0 0 0;

if ($doScale)
setAttr ($temp + ".scale") $scaleArray[($i*3)] $scaleArray[($i*3)+1] $scaleArray[($i*3)+2];
else
setAttr ($temp + ".scale") 1 1 1;

// Do the matrix construction in local scope.
float $matrix[16] = `xform -q -ws -m $temp`;
for ($mid = 12; $mid < 15; $mid++)
$matrix[$mid] *= $scaleFactor;
string $data = $matrix[0] + " " + $matrix[4] + " " + $matrix[8] + " " + $matrix[12] + " ";
$data += $matrix[1] + " " + $matrix[5] + " " + $matrix[9] + " " + $matrix[13] + " ";
$data += $matrix[2] + " " + $matrix[6] + " " + $matrix[10] + " " + $matrix[14] + "\n";

fprint $fileId $data;
}
if (`progressBar -q -ic $gMainProgressBar`)
break;
// Limit the progressBar updates (speeds up execution by 15%).
if ($i % 1000 == 0)
progressBar -e -s 1000 $gMainProgressBar;
}
fclose $fileId;

$id++;
if (`progressBar -q -ic $gMainProgressBar`)
break;
}
progressBar -e -ep $gMainProgressBar;
delete $temp;
}

proc string getInstance(string $path, string $transform)
{
if (`nodeType $transform` == "instancer"){
getInstances($path, $transform);
return "";
}
else{
if (`checkBox -q -v octaneInstanceMo`){
string $childs[] = `listRelatives -c -type "mesh" $transform`;
if (size($childs))
return getInstanceMatrix($transform);
}
else
return getInstanceMatrix($transform);
}
return "";
}

global proc octaneInstancerFile(string $path)
{
int $hi = `checkBox -q -v octaneInstanceHi`;
string $data;
string $sel[] = `ls -sl -tr`;
$fileId = `fopen $path "w"`;
for ($obj in $sel){
fprint $fileId (getInstance($path, $obj));
$items = `listRelatives -c -ad -type "transform" $obj`;
if ($hi){
for ($item in $items)
fprint $fileId (getInstance($path, $item));
}
} 
fclose $fileId;
}
spark31
Licensed Customer
Posts: 6
Joined: Sat May 23, 2015 7:57 pm
Location: LOS ANGELES
Contact:

I just remove some old part of the script but maya should have skip it :? ;)
tchoa
Licensed Customer
Posts: 189
Joined: Thu Jul 01, 2010 12:33 pm
Location: Montpellier

Hi there,

Just in case, I've moved the original old mel script here: octaneInstancer_mel
You got its latest version as v0.5 @ 05/12/2012
Anyway, glad you solved your issue and get it working.

Since then, I wrote a python script that exports Maya instancing to other softwares.
It's a way faster at exporting instancer nodes as it's calling api methods.
I extracted the function that outputs csv for octane and left 2 others: instances to instancer and instancer to meshes.
Feel free to test/use it: octaneInstancer_py
Its simple UI can be called like that:

Code: Select all

import octaneInstancer
octaneInstancer.ui()
As the old one it works regarding selected nodes.

Cheers
Win XP x64 | Q6600 2.40GHz | 8Go | GTX470 1.28Go // Win 7 x64 | I7 Q740 1.73Ghz | 6Go | GTX460m 1.5Go
p3taoctane
Licensed Customer
Posts: 1418
Joined: Mon Jan 25, 2010 12:53 am

This looks like a great script.

I may be doing something wrong but I am getting a couple of line errors.

I made a sphere, special duplicated it into 5 instances. Selected just the instances.

Sourced and loaded the octaneInstancer.mel (that I created by copy and pasting the text into a text file and saving it by that name.)

Up came the little Gui box... and exported the hierarchy (not meshes) gave an interface to save a octaneInstancerFile.

gave it the name test and get these errors


Cannot find procedure "octaneInstancerFile".
Start of trace: (command window: line 43).
octaneInstancerFile (command window: line 43).
octaneInstancerDialog (command window: line 1).


Any ideas
Windows 7 Pro_SP 1_64 bit_48 GB Ram_Intel Xeon X5660 2.80 GHZ x2_6 580GTX_1 Quadra 4800
p3taoctane
Licensed Customer
Posts: 1418
Joined: Mon Jan 25, 2010 12:53 am

OK got it to work if I run it from a directory called octaneInstancer

many Thanks

Peter
Windows 7 Pro_SP 1_64 bit_48 GB Ram_Intel Xeon X5660 2.80 GHZ x2_6 580GTX_1 Quadra 4800
tchoa
Licensed Customer
Posts: 189
Joined: Thu Jul 01, 2010 12:33 pm
Location: Montpellier

About the mel script, no need to rename it or put it into some unsual place.
Just place it in your scripts folder. In case you don't know where it is you can run this command and get the standard place for scripts:

Code: Select all

internalVar -usd
(-usd flag stands for User Script Directory)
Then if you don't want to relaunch maya, so it knows there is some new script, run this command:

Code: Select all

rehash
If you don't rehash, maya won't be able to source the script and catch all procedures inside unless you restart it.
Usually it's a good idea for mel scripts to give to the main global proc the same name as the file so i.e. octaneInstancer.mel has a main global proc called octaneInstancer.
In case you want to define more mel/python scripts directories, create or extend variables into the maya.env file (MAYA_SCRIPT_PATH / PYTHONPATH and read the docs ;))
Win XP x64 | Q6600 2.40GHz | 8Go | GTX470 1.28Go // Win 7 x64 | I7 Q740 1.73Ghz | 6Go | GTX460m 1.5Go
Post Reply

Return to “General Discussion”