Help in maya import code


#1

Hi I wanna write a code to not to get error if I don’t have file on my computer
For example: This code is for not to get error from the object which is not is scene:
string $sel[] = ls "nj_liberty01_Mesh";
int $selsize = size($sel);
if ($selsize > 0){
select -r “nj_liberty01_Mesh”;
print “Model was in scene so it’s now selected”;
}else{
print “Model wan’t in scene :|”;
}
Now I wanna use it for import code which is as you know:
file -import -type “OBJ” -ra true -mergeNamespacesOnClash false -rpr “nj_liberty01” -options “mo=1” -pr -loadReferenceDepth “all” “C:/Users/Sherlock/Desktop/work/map/nj_liberty01.obj”;
Okay so what do I use instead of
string $sel[] = ls "nj_liberty01_Mesh";
int $selsize = size($sel);
if ($selsize > 0){
I mean $selsize help me plz


#2

You can use the file -exists option to check if a file exists.

Something like this


string $filename = "C:/Users/Sherlock/Desktop/work/map/nj_liberty01.obj";
bool $exists = `file -exists $filename`;
if ($exists) {
    file -import -type "OBJ" -ra true -mergeNamespacesOnClash false
         -rpr "nj_liberty01" -options "mo=1" -pr -loadReferenceDepth "all" $filename;
}
else {
    print "This file does not exist:";
    print $filename;
}


#3

:keenly: TNX