ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MWMary West17/12/2012

I am hoping there is an answer to this.

In my code below, the user is prompted to select a part or assembly to open. 

Once opened, it loops through all loaded models and exports each to STEP.

For a PART, I get the result I want, which is just the geometry of that PART saved in a same-named STEP file.

For ASSEMBLY, it always puts all the “child” geometry into the STEP, when I just want references to the PARTs.

Am I missing a preference setting?  Or is this even possible?  Any workaround?

public static void saveSample()

{

   object[] models;

   swApp.Command((int)swCommand_e.swFileOpen, null);

   models = (object[])swApp.GetDocuments();

   int count = swApp.GetDocumentCount();

   swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swStepExportSplitPeriodic, false);

   //walk the list of models

   for (int index = 0; index < count; index++)

   {

      bool stepsaved = false;

      modDoc = (ModelDoc2)models[index];

      modDoc.Rebuild(0);

      modDocExt = modDoc.Extension;      

      //compose path name based on original file name

      string stNewPath = modDoc.GetPathName();

      stNewPath = stNewPath.Remove(stNewPath.Length - 7);    

  

      if (modDoc.GetType() == (int)swDocumentTypes_e.swDocPART)

      {

         string stPathStep = stNewPath + ".step";

         int errors = 0, warnings = 0;

         stepsaved = modDocExt.SaveAs(stPathStep, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, 0, null, ref errors, ref warnings);

         //This works nicely

      }

      else

      {

         //compose path name based on original file name

         string stPathStep1 = stNewPath + "_1.step";

         string stPathStep2 = stNewPath + "_2.step";

         int errors = 0, warnings = 0;

         //Both of these save the entire assembly into one step file

         stepsaved = modDocExt.SaveAs(stPathStep1, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, 0, null, ref errors, ref warnings);

         stepsaved = modDocExt.SaveAs(stPathStep2, (int)swSaveAsVersion_e.swSaveAsCurrentVersion (int)swSaveAsOptions_e.swSaveAsOptions_DetachedDrawing, null, ref errors, ref warnings);

      }

   }

}