3 Replies Latest reply on Nov 24, 2015 4:19 AM by roberto gennari

    Save PDF -> DrawingDoc_FileSavePostNotify Loop problem

    roberto gennari

      Hello to all,

      I am creating an addin where every time you save a drawing'm going to create the pdf file, so it is always updated.

      This is my problem:

      I entered my code saving pdf event

      DrawingDoc_FileSavePostNotify () As Integer

      but the event is unleashed every even when the PDF is saved, creating a loop.

       

      Below I report my code contained in the event DrawingDoc_FileSavePostNotify () As Integer, I do not know if you can solve with a flag or if it moved to another event.

       

       

      Thank you all

       

       

          Function DrawingDoc_FileSavePostNotify() As Integer

       

              Dim PathFile As String = System.IO.Path.GetDirectoryName(iDrawing.GetPathName)

              Dim Myfile As String = PathFile & "\" & System.IO.Path.GetFileNameWithoutExtension(iDrawing.GetPathName)' Senza estensione

       

              Dim swExportPDFData As ExportPdfData

              Dim swDrawDoc As DrawingDoc

              Dim MyModel As ModelDoc2

              Dim swModExt As ModelDocExtension

              Dim boolstatus As Boolean

              Dim filename As String

              Dim errors As Integer

              Dim warnings As Integer

              Dim objs() As Object

              Dim obj As Object

       

              MyModel = iSwApp.ActiveDoc

              swModExt = MyModel.Extension

       

              If mTaskpaneHost_1.cb_Salva_Tavola.Checked = True And mTaskpaneHost_1.cb_Pdf.Checked = True Then

                  swExportPDFData = iSwApp.GetExportFileData(swExportDataFileType_e.swExportPdfData)

                  ' Get the names of the drawing sheets in the drawing

                  ' to get the size of the array of drawing sheets

                  swDrawDoc = MyModel

                  obj = swDrawDoc.GetSheetNames

       

                  Dim count As Integer

                  count = UBound(obj)

                  ReDim objs(count)

                  Dim arrObjIn(count) As DispatchWrapper

       

                  Dim i As Integer

                  'Activate each drawing sheet, except the last drawing sheet, for

                  'demonstration purposes only and add each sheet to an array

                  ' of drawing sheets

                  For i = 0 To count - 1

                      boolstatus = swDrawDoc.ActivateSheet(obj(i))

                      Dim swSheet As Sheet

                      swSheet = swDrawDoc.GetCurrentSheet

                      objs(i) = swSheet

                      arrObjIn(i) = New DispatchWrapper(objs(i))

                  Next i

       

                  ' Save the drawings sheets to a PDF file

                  boolstatus = swExportPDFData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets,(arrObjIn)).

                  ''''''''''''''''''''''''''''''''''

                  ''''''HERE START THE LOOP'''''''''

                  ''''''''''''''''''''''''''''''''''

                  swExportPDFData.ViewPdfAfterSaving= False

                  Debug.Print(swExportPDFData.ViewPdfAfterSaving)

                  boolstatus = swModExt.SaveAs(Myfile & ".pdf", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent,swExportPDFData,errors,warnings)

                  If boolstatus = True Then

                      MyNode = mTaskpaneHost_1.Tv.Nodes.Find("Oggi",True)

                      MyNode(0).Nodes.Add("", Myfile & ".pdf", 1)

                  Else

                      MyNode = mTaskpaneHost_1.Tv.Nodes.Find("Oggi",True)

                      MyNode(0).Nodes.Add("", Myfile & ".pdf", 4)

                  End If

              End If

       

          End Function