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.


Re: Application.StartCommand(CommandID)

I know I've seen Jason Newell rant against the StartCommand function because it operates differnently than all the other commands. (I want to say that it runs asyncronsly in another thread, versus in series--maybe?) To get around that you would need to have the main code pause and then restart once the flat pattern is done.

However, have you tried any of the object methods related to the flat patterns listed in the SDK? I see there's a SolidEdgePart.FlatPatterns.Add method that might be an easy-ish way. The challenge might be identifying the reference edge, face, and vertex.

I'd really hope there'd be some advancement in the API since 2009, but who knows.

Re: Application.StartCommand(CommandID)

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.

Re: Application.StartCommand(CommandID)

bnemec wrote:

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 ?



My other Post

Re: Application.StartCommand(CommandID)

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

Re: Application.StartCommand(CommandID)

This is my code. I took bits of some other macros.  I´m sure you could use it as a start point. 



Re: Application.StartCommand(CommandID)

Thank you @RamonRuiz, I had to install Win rar and started looking through this. It always takes me a while to wrap my head around the process flow when looking at someone else's code.

If I understand your previous post you are describing the same behavior I was noticing. If there is not a flattened body, then it tries to make one, trouble is often it picks an edge face for some reason, which of course fails. I too noticed that the dxf file did not display in a viewer even though there are lines in the file.

I do like the option of just picking the largest face and longest edge, but to keep the option open I wanted to give the user the option to pick which face and edge to use. I see you are doing some other work there with maximum cut lengths, what is that about?

Re: Application.StartCommand(CommandID)


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


Best Regards