Problem scripting a 'trim' operation

 From:  Dave Morrill (DMORRILL)
3541.1 
Michael,

I'm having some difficulty using the MoI API to programmatically perform a 'trim' operation. The error I get is: "Invalid pointer" when I attempt to execute 'trimmer.generateFragments();', where 'trimmer' is a trim factory object I created previously.

I'm assuming the error is being generated by some internal C++ code catching a bad input to one of the trim factory object inputs, but I've been scratching my head trying to figure out which one is causing it fits. The actual code I'm trying to execute is:

function trim ( objects, cutters, extend_lines, project_intersections ) {
var trimmer = factory( 'trim', as_list( objects ), as_list( cutters ), null,
'keep', arg( extend_lines, false ),
arg( project_intersections, true ) );
trimmer.generateFragments();
trimmer.setInput( 2, object_list() );
trimmer.finishedPickingFragments();

return trimmer.calculate()
}

Now obviously it is difficult for you to tell what this code is doing without access to the rest of the code, but basically, each argument to the 'factory' function results in a 'setInput' call on the factory object being created, a 'null' argument means skip setting that positional input, the 'as_list' function makes sure its input argument is a MoI ObjectList, and the 'arg' function returns either the first argument (if it is specified by the caller), or the second argument (if it is not).

In this case, I have verified that the 'objects' and 'cutters' arguments are lists ('objects' is a list of 3 'curve' objects, and 'cutters' is a list containing a single 'curve' object).

I've studied the MoI 'Trim.js' file and I can't see any significant difference between what I am trying to do and what you are doing (excluding all the interactive picking logic).

In general, I have used this 'factory' method successfully in a lot of other procedural code to do various boolean and geometry creation operations, so I know that the basic premise it uses is more or less correct. The main difference is that after the setup step I usually just call 'calculate' on the factory object to produce the resulting geometry.

In the case of 'trim', that was not doing anything useful. So I studied 'Trim.js' in more detail and saw the call to 'generateFragments', which I assume is calculating the trim fragments both to allow further user picking and to produce the final result set. And that's where the trouble began :-)

On a related note, I'm not too clear on the subtleties of the factory 'calculate', 'update' and 'commit' methods. I've been working on the assumption that 'calculate' causes the factory to use its inputs to calculate a set of geometry objects, but does not update the screen or commit the results to the MoI geometry database. The 'update' method does something similar but does update the screen to show the user what the factory is currently producing, and that 'commit' adds the results that the factory produces to the MoI geometry database.

I bring this up because I've noticed that sometimes after performing a procedural operation that creates some (later discarded) intermediate geometry (using the factory 'calculate' method) on the way to producing a final result, the intermediate geometry will sometimes show up on the display at the end of the script, but will often disappear once you start manipulating the display view in various ways. This leads me to believe that my above assumptions are somewhat flawed, since there seems to be some cases where the geometry has not been committed to the database, but can still show up on the display. In some of these cases, I've also noticed that I often get the 'wait' hourglass cursor for a while as well.

Finally, another question I have is whether factory methods can only work on 'committed' geometry, or can they also work on any valid geometry passed to them. I've been assuming they can work on any geometry, but would like to have that point clarified.

Sorry for the long post, but if you can provide any answers, I'll make sure that they are used to improve the API documentation I've been working on for a while...

- Dave Morrill