1 Reply Latest reply on Jan 9, 2014 8:44 AM by Christoph Neundorf

    Open and save the part's journal from a drawing via C#

    Christoph Neundorf

      Hi all,

       

      i'd like to open the journal file of  part from a drawing using C#.

      Unfortunately the bool swViewStatus (SelectByID2) doesn't get true yet.

       

                  SolidWorks.Interop.sldworks.View swView = default(SolidWorks.Interop.sldworks.View);

                  swView = ActiveDrawing.GetFirstView();

                  swView = swView.GetNextView();

                  ModelDoc2 swModel = null;

                  int nDocType = 0;

                 

                  if (swView != null)

                  {

                      String strModelName = swView.GetReferencedModelName();

                      strModelName = strModelName.ToLower();

                      if (strModelName.Contains(".sldprt"))

                      {

                          nDocType = 1;

                          swModel = swApp.OpenDoc(strModelName, nDocType);

                          //swModel = swApp.OpenDoc6(strModelName, nDocType, (int)swOpenDocOptions_e.swOpenDocOptions_DontLoadHiddenComponents, "", 0, 0);

                      }

                      else

                      {

                          nDocType = 2;

                          swModel = swApp.OpenDoc(strModelName, nDocType);

                          //swModel = swApp.OpenDoc6(strModelName, nDocType, (int)swOpenDocOptions_e.swOpenDocOptions_DontLoadHiddenComponents, "", 0, 0);

                      }             

                                   

                      if (swModel != null)

                      {

                       bool mViewStatus = swModel.Extension.SelectByID2("Journal.doc", "JOURNAL", 0, 0, 0, false, 0, null, 0);

                      if (mViewStatus != true)

                      {

                          mViewStatus = swModel.Extension.SelectByID2("Journal.doc (Leer)", "JOURNAL", 0, 0, 0, false, 0, null, 0);

                      }

                      if (mViewStatus)

                      {

                          MessageBox.Show("Journal selected successfully");

                      }

                      }

                      swModel.Save3(1, 1, 1);

                  }

       

      Any thoughts?

       

      Thanks,

      Chris

        • Re: Open and save the part's journal from a drawing via C#
          Christoph Neundorf

          This code seems to work.

           

          swApp.ActivateDoc2(strModelName, false, 0);

          ModelDoc2 swDoc = ((ModelDoc2)(swApp.ActiveDoc));

          object[] oOleObjs = (object[])swDoc.Extension.GetOLEObjects(0);

          foreach (SwOLEObject oOLEObj in oOleObjs)

          {

              if (oOLEObj != null)

              {

                   Word.Document oDoc = (Word.Document)oOLEObj.SetActive(true);

                   oDoc.Application.Visible = true;

                   oDoc.Application.Documents.Add();

                   oDoc.SaveAs2(@"D:\journal.pdf", 17, 0);

                   oDoc = oOLEObj.SetActive(false);

               }

          }

           

          But how can i check if the OLE object really is the design journal?

          Additionally there seem to be a bug (SPR #386112) so that the OLE document is not opened correctly.