Hello all, I am working on our add-in to generate a the dxf flat whenever a .psm is saved. All is well so far, used code from @jnewell and @JanWillem and Solid Edge .NET programmers guide and some pointers from @mpowers here too. The goal here was for this to be a silent addin, there is a situation when the sheet metal is not flat and does not have a flattened body. I found the StartCommand function, and it works to call it like so:
It is not acting like I want though. This is called from a save document event when I want the user to create the flat pattern, trouble is the event handler finishes before the focus is shifted back to solid edge and that is when the flat pattern environment is started and it asks for the face, line, vertex etc. By then it’s too late and the dxf is saved, incorrectly.
I’m probably missing something obvious and simple, but how do I switch focus back to SE for the remainder of the command I called and then let my event handler finish?
I could just call StartCommand and then bail out and make the user save again, but I would like a smooth, polished solution.
lastly, there is this old thread that shows how to automatically select face and edge to create a flatened body with no user intervention. But it sounds a little tough to implement to me.
I would agree that it acts like it's running in another thread. I'm thinking there is a way to have the event handler (my code) wait until that is done, but I'm not sure how to know when that is. Maybe just loop until the sheetMetalDocument.FlatPatternModels > 0 ? I found an application.IsIdling but light on documentation that might work, but I've spun my wheels going down and back out of rabbit holes before. When I finally get an acceptable solution it tends to be messy code and messy process. It's hard to follow good programming processes when you cannot see the end from the beginning, 99% of functions and libraries I use are in the "unknown domain" until I poke around and find them. Just a lack of experience I suppose.
I ran across some code doing as you suggest, linked to it in the op. I'm on the fence if I want it done automatically or with user input. Both have pros and cons.
Lastly but more importantly, I listed where I found most of the help but forgot to say thank you. So thank you to all of you who share experience and skills here.
I would agree that it acts like it's running in another thread. I'm thinking there is a way to have the event handler (my code) wait until that is done, but I'm not sure how to know when that is.
Maybe, this can help a little ?
I developed a macro to make some similar and It really took me a lot of time to consider all the conditions. Flat not generated and worse flat body generated but with a Solid Edge version so old the dxf is blank. As soon as posible I will post the procedure code
First of all, sorry for my code but I´m a newbie, and not programmer, so I´m sure a professional will do a better job
Yes I make the flat model if it´s not done based on largest face and largest edge, I took that code from a post here in the forum.
I´m also adding the sheet cut lenghts, but it was kind of nightmare to do it, there are a lot of cases where setcutlength fails, when that happens the flat model is redone using the same parameters when it was done, face and edge. There are other cases where the flat model can´t be redone because there is no face to do it, the reference is lost and you only have a couple of edges as references (you could use Solid Edge SPY to check it), this was the hardest part, but I found a way to also redo the flat model on those cases and recover the face and edge references.
At the beginning, I also thought of letting the user to pick a face and edge to make the flat model, but I was having problems to do it with startcommand, and forgot about it when I found the code using Largest Edge and Face