Add-in - Create pdf from dft of the current assembly document

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hi all,

 

I need to create a pdf from the draft document of an open assembly and all the draft of the occurrences of this assembly.

 

I have no problem to find the draft, since we only get the draft that have the same name in the same folder as the 3D component, but next action doesn't seems to work properly.

 

I open the draft, update the view and text then save as pdf.

            MyAddIn.Instance.Application.DisplayAlerts = False
            MyAddIn.Instance.Application.SetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnlyDftFile, True) 'Ouvrir en lecture seule
            MyAddIn.Instance.Application.SetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalSessionDraftOpenInactive, False)

            ObjDFT.UpdatePropertyTextCacheAndDisplay()
            MyAddIn.Instance.Application.StartCommand(DetailCommandConstants.DetailDrawingViewsUpdateViews)
            MyAddIn.Instance.Application.DoIdle()

            File.Delete(Path.ChangeExtension(ObjDFT.FullName, "pdf"))

            ObjDFT.SaveAs(Path.ChangeExtension(ObjDFT.FullName, "pdf"))
            PdfList.Add(Path.ChangeExtension(ObjDFT.FullName, "pdf"))
            'CLOSE
            MyAddIn.Instance.Application.DisplayAlerts = True
            MyAddIn.Instance.Application.SetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnlyDftFile, False) 'Ouvrir en lecture seule
            MyAddIn.Instance.Application.SetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalSessionDraftOpenInactive, False)

This works fine with macro but can't make it work in add-in. There is no error but the document is not updated, as if the command MyAddIn.Instance.Application.StartCommand(DetailCommandConstants.DetailDrawingViewsUpdateViews) doesn't finish before going to the next step.

 

Please help Smiley Mad


Romuald BERTIN
2 REPLIES

Re: Add-in - Create pdf from dft of the current assembly document

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

StartCommand() is always tough because it's an asynchronous operation and there is no way to really know when the command is complete. In this particular case though, I believe you do have an option. Rather than calling the DetailDrawingViewsUpdateViews command, you could just find all of the drawing views yourself and call Update() on each one. Should eliminate your issue if you do it this way.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Add-in - Create pdf from dft of the current assembly document

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Thanks Jason I works perfectly now.


Romuald BERTIN