MoI discussion forum
MoI discussion forum

Full Version: assert failed - error handing in scripted process

From: 9krausec
12 Jul 2019   [#1]
All,

I'm scripting up a batch process that imports a bunch of .STEP files and translate them out to OBJ. During the process, Moi3D doesn't crash, but it just stops translating and hangs.

I tried import the same files via the GUI and am getting a "Unexpected condition (assert failed)" warning dialog that stops the process until user input to "Report", "Ignore" or "Ignore All".

Two questions. What would be causing this (step file attached that's crashing)? How do you handle this exception when it happens during as jScript run? Below is the function that I'm running all my .STP files through (if it has pertinent information in it). Attached is the actual .STEP file that's throwing the "error".

Thank you,
Clayton

/////////

function AdaptiveMesh( OutPath, StepArray)
{
var gd = moi.geometryDatabase;

gd.fileNew( true )

for ( var i = 0; i < StepArray.length; ++i )
gd.fileImport(StepArray[i]);

gd.deselectAll();
gd.getObjects().getBReps().setProperty( 'selected', true );


gd.saveAs( OutPath, 'NoUI=true; Output=ngons;Angle=32;' );
gd.fileNew( true );
}

//////////

Attachments:
GM105-C18_3D_2.stp


From: Michael Gibson
12 Jul 2019   [#2] In reply to [#1]
Hi Clayton, sorry there is not currently any way to turn off the release mode assert dialog, but they will be disabled in the next beta and also in the final release. I'll also put in something to avoid throwing them in the future when you're doing an automated processing run with a startup script.

The warning/error is related to 2 factors in the file, one is that it has offset surface types in it, and also the object is at an exceedingly tiny scale, just 0.0002 units across. I think this is causing problems with the methods that are trying to replace the offset surface with a regular NURBS surface since it is far below the fitting tolerance that it ends up using. I'll investigate it some to see if this can be tuned up but in general it's good to avoid having objects at such an extreme tiny scale.


Thanks,
- Michael
From: rand (RANDALL)
27 Aug 2020   [#3] In reply to [#1]
Clayton,
Would you mind sharing your script? I am trying to do something similar but I am not sure how to create the array of file paths. I am new to javascript and everything online says it is not possible to access the file system in javascript.
Thanks!
Randall
From: Michael Gibson
27 Aug 2020   [#4] In reply to [#3]
Hi Randall - yes that's true that there isn't anything built directly into the core JavaScript language itself for accessing the file system, but it is possible for the environment that the script is running inside of to provide that. In MoI functions for these can be accessed under the moi.filesystem object.

The functions available are (I think one of them maybe dirExists will be in the next v4 beta not the current one) :

moi.filesystem.incrementFileName( filename );
Increment a file name. For example File01.txt becomes File02.txt .
Arg1 = input filename.
Return value = incremented filename.

moi.filesystem.getCompactPath( filename );
Arg1 = Input filename.
Arg2 = Target number of characters to try and fit.
Return value = filename with paths removed if full path exceeds target limit.

moi.filesystem.getFileNameFromPath( fullpath );
Arg1 = filename with full path
Return value = just the file name portion of the path, no directory.

moi.filesystem.getOpenFileName( DialogTitle, Filters );
Function for a script to be able to show the open file name dialog.
The filter string has entries separated by the pipe | character, with
the entries in pairs with a label first and then a filter next, for example:
'Point files (*.txt, *.xyz, *.csv)|*.txt;*.xyz;*.csv|All files (*.*)|*.*'
returns filename or empty string if dialog was canceled.

moi.filesystem.getSaveFileName( DialogTitle, Filters );
Function for a script to be able to show the save file name dialog.
The filter string has entries separated by the pipe | character, with
the entries in pairs with a label first and then a filter next, for example:
'Point files (*.txt, *.xyz, *.csv)|*.txt;*.xyz;*.csv|All files (*.*)|*.*'
returns empty string if dialog was canceled.

moi.filesystem.getPathDelimiter();
Returns the native path delimiter for the OS. For Windows it's \ on Mac it's /.
It's usually possible to write cross platform code without using this because
on Mac script functions that take file names will accept Windows like path names
using z:\

moi.filesystem.processFileNameToUI( scriptpath );
Given a script path, return the native path to be used for showing in any UI controls.

moi.filesystem.processFileNameFromUI( nativepath );
Given a native path, return the script path.

moi.filesystem.openFileStream( filename, mode );
Creates a file stream object that can read or write content to the given filename.
Mode can be 'r' for read, or 'w' for write.

moi.filesystem.getFiles( path, filter );
Given a directory name and a filter string, return a list of files within that directory.
For example: var files = moi.filesystem.getFiles( 'c:\\scripts\\iges', '*.igs' );
Filter can be a semi-colon delimited list of filters.

moi.filesystem.getDirs( path, filter );
Given a directory name and an optional filter string, return a list of sub-directories within that directory.
For example: var dirs = moi.filesystem.getDirs( 'c:\\', 'p*' );
Filter can be a semi-colon delimited list of filters.

moi.filesystem.fileExists( filename );
Returns true if the given file exists.

moi.filesystem.dirExists( filename );
Returns true if the given directory exists.

moi.filesystem.shellExecute( Path, Parameters, WaitForFinished );
Arg 1 (required) - path to file. Could be an executable or a data file which will
then open it up in whatever the OS has registered to handle that file extension type.
If given an executable program file, command line parameters can be given by
optionsl Arg2, and if Arg3 is true it will wait for the launched program to finish
before returning from shellExecute(). When using WaitForFinished, the return value
is a dictionary object with exitCode and output properties on it. exitCode contains
the numeric exit code value and output contains any text written to stdout.

moi.filesystem.deleteFile( path );
Deletes the given file.

moi.filesystem.copyFile( ExistingPath, NewPath, FailIfExists );
Required Args 1 and 2 give the path to the existing file, and the
path to the new file. FailIfExists is an optional value, if set to
true the operation will not overwrite an existing file. Default is false.

moi.filesystem.getProcessDir();
Returns path to where application binaries are installed. On Windows returns the path
to where MoI.exe is located. On Mac, returns the full path to /Contents/Resources/
inside the app bundle.

moi.filesystem.getTempDir();
Returns path to the TEMP folder.

moi.filesystem.getAppDataDir();
Returns path to the Moi AppData folder. On Windows this is: %AppData%\Moi, on Mac
it's ~/Library/Application Support/Moi.

moi.filesystem.getUIDir();
Returns path to the UI folder inside the install dir.

moi.filesystem.getCommandsDir();
Returns path to the Commands folder inside the install dir.

moi.filesystem.toNativePath( filename );
Given a script path (using z:\ on Mac) returns native OS path.

moi.filesystem.toScriptPath( filename );
Given a native OS path converts it to a script path.



The Filestream object has these functions:

.readLine() - reads a line of text from the stream, the text is the return value of the function.

.writeLine( text ) - writes a line of text to the stream.

.atEOF property - returns true if the stream is at the end with nothing more to read from it.

.close() - closes the stream.

.setWriteBOM( ) - sets whether to write the byte order mark at the front of the text file, default is no BOM.

.setCodec( name ) - controls the encoding to use for reading or writing. Supported codecs are listed here: http://doc.qt.io/qt-5/qtextcodec.html#details