Before Save Event code not complete befor save

Esteemed Contributor
Esteemed Contributor

I have an add-in that sets a view rotation when the BeforeSave event happens to get a good Preview image however the view transition is still occuring after the code runs and SE saves the Preview, but not the file.  This leaves a bad Preview image and a fle that still prompts to save when closed.  How do I get everything to complete before control is returned to the Save command?

 

Code is attached...

 

 


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1
7 REPLIES

Re: Before Save Event code not complete befor save

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

Hi,

 

in your code you're using Application.StartCommand(...) methods which run asynchronously.

You've commented out the equivalent commands to apply a view style. Why? Did you try them instead of using StartCommand(...) and they didn't solve the problem?

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: Before Save Event code not complete befor save

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Try to avoid the StartCommand() calls, which should always be followed by an Application.DoIdle() call.

 

Especially, the change of the view orientation can be made easily by setting the camera in the View object without starting any command.

The same could also be done for the HideAllReferencePlanes command, but this could become slower and more complex, as you would need to traverse the entire assembly tree for assembly document.

 

Here are some code snippets which should replace the StartCommand to set the view orientation:

Dim eyeX As Double
Dim eyeY As Double
Dim eyeZ As Double
Dim targetX As Double
Dim targetY As Double
Dim targetZ As Double
Dim upX As Double
Dim upY As Double
Dim upZ As Double
Dim scaleOrAngle As Double
Dim perspective As Boolean

oWindow.View.GetCamera(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ, perspective, scaleOrAngle)

  ' Set LEFT view
	oWindow.View.SetCamera(-1,0,0, 0,0,0, 0,0,1, perspective, scaleOrAngle)

  ' Set FRONT view
	oWindow.View.SetCamera(0,-1,0, 0,0,0, 0,0,1, perspective, scaleOrAngle)

  ' Set TOP view
	oWindow.View.SetCamera(0,0,1, 0,0,0, 0,1,0, perspective, scaleOrAngle)

  ' Set ISO view
	oWindow.View.SetCamera(1,-1,1, 0,0,0, 0,0,1, perspective, scaleOrAngle)

Re: Before Save Event code not complete befor save

Esteemed Contributor
Esteemed Contributor

Still using ST6 and the View commands don't exist in the ST6 API.


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1

Re: Before Save Event code not complete befor save

Esteemed Contributor
Esteemed Contributor

Thanks for that Martin.  I was wondering how to do that via the API with ST6.

 

I originally tried "oWindow.View.ApplyNamedView("front")" which works great in ST8 but failed in ST6 as that was a new API added after ST6.

 

I also tried using the DoIdle command after the StartCommand lines, but it didn't make a difference.  They still ran after the save was already complete.

 

Thanks again Martin!


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1

Re: Before Save Event code not complete befor save

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Ken,

I actually don't have any VB.NET addin, but I was testing your code with my C++ test addin.

I could reproduce your problem, when using the StartCommand for the view orientation, but this could be solved with the code snippets from my previous post and a DoIdle call after the HideAllReferencePlanes command.

I believe, that the main problem was to do TWO StartCommand calls with only a single DoIdle call in your code. With only one call to StartCommand and DoIdle, SE saves the preview and the document correctly.

I tested this only on a simple part document and don't know, if this is also true for SheetMetal and Assembly.

Re: Before Save Event code not complete befor save

Esteemed Contributor
Esteemed Contributor

I did try the DoIdle after each StartCommand.  What is wierd is this worked at some point on some PC's but not others.

 

Your solution works like a charm though!


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1

Re: Before Save Event code not complete befor save

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

As I've mentioned in my answer above, due to the asynchronous execution of the Application.StartCommand() method, the program sequence is unpredictable. The Execution of Application.DoIdle() doesn't await the tasks initiated by Solid Edge to be performed before returning.

 

Seems you had the equivalent API commands, but they were available in version ST8 only, so you commented them out in your code. Bernhards alternative code gives a good workaround so.

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de