Message 1 of 6

Not applicable
10-16-2016
01:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Programatically, I am selecting multiple pairs of faces to then align
The function shown below is called many times in rapid succession and appeared to show inconsistent / wrong results
On my old slow laptop, it always worked correctly
In debug mode it always worked correctly
On my desktop machine it never worked
I concluded that the UI is lagging behind the script so put a blocking pause in place and that fixes it
Is there a better way to detremine if the UI has finished so it's safe to move on and get the next pair?
The code is commented to show the latest and best result so far but it's not a good solution
function alignFaces01(face1,face2) { // This function is called many times in rapid succession after programatically determining a // long series of faces to align. // // Without the time wasting loop, it appears to have non deterministic behaviour // and random faces will be aligned with each other // // It was confusing as in debug mode, it always worked correctly // and on my laptop (a much slower machine it also worked correctly) // // I concluded that the UI was not responding quick enough so put in the ui refresh // That didn't work // // The sleep function does force it to work but I can't consider that a good solution // Is there any good practise that will work reliably? var app = adsk.core.Application.get(); var ui = app.userInterface; // Add these faces to the active selection. var theseSelections = ui.activeSelections; // clear any selections pre existing theseSelections.clear; // add the 1st face to the selection theseSelections.add(face1); // add the 2nd face to the selection theseSelections.add(face2); // Get the Align Component command and execute it. var alignCommand = ui.commandDefinitions.itemById('AlignComponentsCmd'); alignCommand.execute(); // make sure the viewport has caught up with all the edits // this does not work app.activeViewport.refresh(); // create delay by pointlessly looping round // This works but is terrible practise!! // 100 milliseconds does the trick on my desktop machine // 50 milliseconds sometimes does it // 25 milliseconds does not do it sleepOMG(100); }
Solved! Go to Solution.