Author Topic: Autocad 2016 with Cadworks 2016  (Read 2328 times)

0 Members and 1 Guest are viewing this topic.

WOWENS

  • Newt
  • Posts: 55
Autocad 2016 with Cadworks 2016
« on: March 07, 2016, 02:12:30 PM »
I have 2 drawings one with cadworks objects and one with only autocad objects.
The following code works for both drawings if you don't have cadworks installed
but with Cadworks installed an error pops on the drawings with cadworks objects.
anyone have any clues (it still does the save but the message box is a pain)

Code - Visual Basic: [Select]
  1. <CommandMethod("TESTCODE", "TESTCODE", "TESTCODE", CommandFlags.Session)> _
  2.         Public Sub TESTCODE()
  3.             Dim sFileName As String = "C:\Autodesk\test\test.dwg"
  4.  
  5.             Using db As New Database(False, True)
  6.                 db.ReadDwgFile(sFileName, IO.FileShare.ReadWrite, False, "")
  7.                 Dim workDb As Database = HostApplicationServices.WorkingDatabase
  8.  
  9.                 If HostApplicationServices.WorkingDatabase <> db Then
  10.                     HostApplicationServices.WorkingDatabase = db
  11.                 End If
  12.  
  13.                 '-----------------------------------------
  14.                'Write Code to do something here
  15.                '-----------------------------------------
  16.  
  17.                 If HostApplicationServices.WorkingDatabase <> workDb Then
  18.                     HostApplicationServices.WorkingDatabase = workDb
  19.                 End If
  20.  
  21.                 Try
  22.                     'Warning: An Error occurred during save.
  23.                    'We recommend that you run RECOVER on the drawing.
  24.                    db.SaveAs(sFileName, DwgVersion.Current)
  25.                 Catch e As Autodesk.AutoCAD.Runtime.Exception  '(no error to catch)
  26.                    db.CloseInput(True)
  27.                     Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message)
  28.                 End Try
  29.  
  30.                 db.Dispose()
  31.             End Using
  32.  
  33.         End Sub
« Last Edit: March 07, 2016, 02:19:02 PM by John Kaul (Se7en) »

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad 2016 with Cadworks 2016
« Reply #1 on: March 07, 2016, 02:42:51 PM »
What are you doing in the middle of setting your databases?

There is no need for the if statement when switching databases.  Just switch them as the WorkingDatabase will not be the new database that you create.  Additionally, once you switch it to the db database you know for a fact that it is not the workdb so switch it back.

Code - Visual Basic: [Select]
  1. HostApplicationServices.WorkingDatabase = db
  2.  
  3. '-----------------------------------------------
  4. 'Write Code to do something here
  5. '-----------------------------------------------
  6.  
  7. HostApplicationServices.WorkingDatabase = workDb


If you are for sure using 2016 you can use the new Audit function that came with 2015 and call it before you save the drawing.  That works for me sometimes.  Make sure you reference Autodesk.Autocad.ApplicationServices.DatabaseExtensions if your using VB.


I did have this issue in the past and will try to see if i can find what actually caused it.  I am pretty sure that it had something to do with me using the wrong database at somepoint while working in a side database.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad 2016 with Cadworks 2016
« Reply #2 on: March 07, 2016, 02:57:30 PM »
I also forgot to add that you are disposing your database twice.  Once with the dispose statement and again with the end using. 
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad 2016 with Cadworks 2016
« Reply #3 on: March 07, 2016, 03:00:07 PM »
Finally, one more thing.  Did you try reading your dwg with FileOpenMode.OpenForReadAndWriteNoShare instead of IO.FileShare.ReadWrite?  I seem to remember that it caused me this problem and I had to use the FileOpenMode instead.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WOWENS

  • Newt
  • Posts: 55
Re: Autocad 2016 with Cadworks 2016
« Reply #4 on: March 07, 2016, 03:38:47 PM »
your correct about the if statement not being needed as well as the double Dispose. I have never had a problem with IO.FileShare.ReadWrite. but with all that it still does not help with  db.SaveAs(sFileName, DwgVersion.Current)

WOWENS

  • Newt
  • Posts: 55
Re: Autocad 2016 with Cadworks 2016
« Reply #5 on: March 07, 2016, 04:14:46 PM »
After trying different things AutoCAD still pops up "Warning: An Error occurred during save. We recommend that you run RECOVER on the drawing."
only if you have Cadworx loaded.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad 2016 with Cadworks 2016
« Reply #6 on: March 07, 2016, 04:25:47 PM »
You never mentioned if you were doing any processing of the drawing and if so what you were doing.


I am doing work in AutoCAD 2016 with CadWorx 2016 in a side database and not having this issue.


My code for creating and opening the side database is identical to what you have posted.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WOWENS

  • Newt
  • Posts: 55
Re: Autocad 2016 with Cadworks 2016
« Reply #7 on: March 07, 2016, 04:48:24 PM »
The basic code I posted will pop up that message on my computer

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad 2016 with Cadworks 2016
« Reply #8 on: March 07, 2016, 05:41:04 PM »
A couple of observations.


1. It was not giving me an error in my code as I was creating a new drawing from a cadworx template and adding xrefs to it.
2. I was able to reproduce by opening up an existing drawing of mine.
3. Removing the database switching calls have no effect.
4. Opening up a drawing with just a very small run of pipe has no issues.


There is probably a specific cadworx entity that is causing the issue.  It is possible that cadworx is doing some things when the drawing closes that is causing the error when using a side database.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WOWENS

  • Newt
  • Posts: 55
Re: Autocad 2016 with Cadworks 2016
« Reply #9 on: March 07, 2016, 06:25:12 PM »
you are correct it is a specific cadworx entity after all
thank you for all your help.