I have a SW file opened assigned as ModelDoc2 swModel.
I do some stuff, and ultimately save it as x_t, then load that x_t with:
ModelDoc2 swModelImported = iSwApp.LoadFile4(tempfile, "i", null, errors);
I then copy the imported bodies to my original swModel as follows:
swFeatMgrImported = (FeatureManager)swModelImported.FeatureManager;
swFeatImported = (Feature)swModelImported.FirstFeature();
while ((swFeatImported != null))
{
FeatType = swFeatImported.Name;
FeatTypeName = swFeatImported.GetTypeName2();
if (FeatTypeName == "SolidBodyFolder" || FeatTypeName == "SurfaceBodyFolder")
{
swBodyFolder = (BodyFolder)swFeatImported.GetSpecificFeature2();
Bodies = (object[])swBodyFolder.GetBodies();
for (int bodyid = 0; bodyid <= (swBodyFolder.GetBodyCount() - 1); bodyid++)
{
swBody = (Body2)Bodies[bodyid];
swPart = (PartDoc)swModel;
swFeat = (Feature)swPart.CreateFeatureFromBody3(swBody, false, (int)swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck);
}
}
swFeatImported = (Feature)swFeatImported.GetNextFeature();
}
Everything works fine. But technically, after this, I'm essentially done with the imported file. So I want to close it:
iSwApp.CloseDoc(swModelImported.GetTitle());
From there, my original swModel is in a bad state (graphics area dead) and most of the time (but not always!?) SW will then crash.
If I avoid actually copying the solid/surface bodies from the imported file, everything is fine, and I can close the imported file OK.
So I assume it's some sort of cleanup i must be missing after I complete the CreateFeatureFromBody3. But it's unclear to me what it is.
Any ideas?
SolidworksApi macros