Hi,
In the quest to find a way to get the overall dimensions of a sheet metal part, I came up with a potential solution. Basically, I wrote a macro to unfold the part, then create a plane parallel to [front, right or top] at the mass centre of the part. I then use a surface cut using the reference plane, then move the reference plane out until the mass of the resultant cut part is the same as the original uncut part. I then use a bisection method to get close to the side of the part (where close is sheet metal thickness / 4). Then I change directions, and repeat for the other side. Then I do the whole thing over again for each of the other [front, right, top] planes. It relies on the part when unfolded having its main axes parallel to the x, y and z vectors.
This works. I'm doing it in C#, in Solidworks 2009, SP4.1 (2010 will be rolled out when the other administrator is back from China. We like to wait for SP3.)
Except for one little thing. If I do enough calls to SolidWorks, it complains at me, giving a COM exception, stating that RPC_E_SYS_CALL_FAILED. Googling around, it appears that this error occurs when enough calls to a COM application interface have been made so that the application has too many messages in its queue. (http://ask.metafilter.com/73674/How-do-I-interpret-RPC-extended-error-information helped a lot in understanding what was going on). Apparently when you have queried SolidWorks enough times via its various interfaces, it gives up. I.e. when you move a plane, create a cut, find the mass of the part, any of these, it gets put into a queue, which doesn't get emptied very often.
I can flush this queue by calling SldWorks.SendMsgToUser2(...). This pops up a dialog box onto the screen. I have it set so that there's only the OK button to hit. The problem is that because this is yet another call to SolidWorks via COM, it can't do it after I get the error RPC_E_SYS_CALL_FAILED, because it gives the same error again; I can only do it before I get this error. With a sufficiently large part (on which I ran the macro to see how it would handle it), I can easily get this error before I've finished running the macro over all directions. To get around it, I can have SendMsgToUser2 called each time I find the overall size in one dimension (i.e. find the overall dimension in the x direction, pop up a dialog box that needs to be OKed, find dimension in y...). This is inconvenient, as I want to have the macro run automatically, eventually iterating over any sheet metal parts in an assembly.
Does anyone have any suggestions as to how to get around this problem? Are there any other functions in SolidWorks that will clear the COM message queue without causing issues?
Thanks and regards,
Daniel
SolidworksApi macros