Author Topic: Getting the print of a brick as a "portable value"  (Read 412 times)

I'm working on something which involves saving various attributes about bricks, and since prints work with an ID which changes based on the number of prints and in which order they were loaded, I need to work with the actual "name" of the print.

I know you can convert from a name to a print ID as follows:

$printNameTable["Letters_Default/a"]

But how would I turn a print ID into a name like "Letters_Default/a"?

Er, nevermind, found a solution:

Code: [Select]
function printIdToName( %id )
{
%texture = getPrintTexture( %id );

%path = getSubStr( %texture, 14, strLen( %texture ) );
%path = getSubStr( %path, 0, strPos( %path, "/" ) );

return %path @ "/" @ fileBase( %texture );
}


Updated solution which actually works:

Code: [Select]
function printIdToName( %id )
{
%texture = getPrintTexture( %id );

%path = getSubStr( %texture, 14, strLen( %texture ) );
%path = getSubStr( %path, 0, strPos( %path, "/" ) );
%path = getSubStr( %path, 0, strPos( %path, "_" ) );

return %path @ "/" @ fileBase( %texture );
}

This is how the duplicator does it, prob same method
Code: [Select]
if(%this.getDataBlock().subCategory $= "Prints")
{
%texture = getPrintTexture(%this.getPrintId());
%path = filePath(%texture);
%underscorePos = strPos(%path, "_");
%name = getSubStr(%path, %underscorePos + 1, strPos(%path, "_", 14) - 14) @ "/" @ fileBase(%texture);
if($printNameTable[%name] !$= "")
%f = %name;
}