Author Topic: Anyone here using RealDWG (2013) need help to track an error...  (Read 8796 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
I have an individual web-service and i am getting a crash - and has not been able to resolve it.

Have the sample Visual Studio 10 solution and needs to be build with RealdDWG 2013 32-bit libs.

Anyone? - and I can post the solution here and steps or PM me and can send the files your way.


Thanks,
Luis.

LE3

  • Guest
Re: Need help to track an error...
« Reply #1 on: May 12, 2012, 09:29:36 AM »
OK, I think it is going to be difficult to have RealDWG (I changed the subject, so it can be a general .NET question), let me post the function where the error occurs, the error and one of the files.

Now, the error does not happen if we use drawings that do not include 3D solids, is this could be a *bug* on RealDWG 2013? or?

Code - C#: [Select]
  1.         public static void Draw(string outputFile)
  2.         {
  3.             string acadTemplateFile = @"C:\hotfiles\CAD_Templates\Common\acad.dwt";
  4.             using (Host host = new Host())
  5.             {
  6.                 using (Autodesk.AutoCAD.DatabaseServices.Database db = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
  7.                 {
  8.                     File.Copy(acadTemplateFile, outputFile, false);
  9.                     db.ReadDwgFile(outputFile, System.IO.FileShare.ReadWrite, false, null);
  10.                     HostApplicationServices.WorkingDatabase = db;
  11.  
  12.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  13.                     {
  14.                         BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  15.                         BlockTableRecord iModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  16.  
  17.  
  18.                         ObjectId blockId = ObjectId.Null;
  19.  
  20.                         using (Transaction tran = db.TransactionManager.StartTransaction())
  21.                         {
  22.                             using (Autodesk.AutoCAD.DatabaseServices.Database sdb = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
  23.                             {
  24.                                 string file = @"C:\hotfiles\CAD_Templates\Ductwork\3D\Elbow 45\DW1645ASY.dwg";
  25.                                 sdb.ReadDwgFile(file, System.IO.FileShare.ReadWrite, false, "");
  26.  
  27.                                 blockId = db.Insert(file, sdb, true);
  28.                             }
  29.                             HostApplicationServices.WorkingDatabase = db;
  30.                             tran.Commit();
  31.  
  32.                         }
  33.  
  34.  
  35.                         BlockReference blockRef = new BlockReference(Point3d.Origin, blockId);
  36.                         iModelSpace.AppendEntity(blockRef);
  37.                         tr.AddNewlyCreatedDBObject(blockRef, true);
  38.  
  39.                         tr.Commit();
  40.                     }
  41.  
  42.                     db.SaveAs(outputFile, DwgVersion.AC1015);
  43.                 }
  44.             }
  45.         }
  46.  

Thanks!
LE
« Last Edit: May 12, 2012, 10:11:13 AM by LE »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #2 on: May 12, 2012, 12:31:50 PM »
Hi Luis,
I was able to run this inside of AutoCAD2012, the drawing is saved, but then I get a Fatal Error as the command ends.

LE3

  • Guest
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #3 on: May 12, 2012, 01:09:31 PM »
Hi Luis,
I was able to run this inside of AutoCAD2012, the drawing is saved, but then I get a Fatal Error as the command ends.

Hi Jeff,
Did you use the function I posted? and modified to make it work on your end?

Thanks.

The same code, BTW works using RealDWG 2009...

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #4 on: May 12, 2012, 01:32:38 PM »
I took the code you posted, modified to only remove the lines with Host (I couldn't find what assembly I needed to reference for this). I created the same folder structure you have, so the only difference is that I'm running it inside of Autocad, without the using(Host....).

The Fatal Error I get does not return any information as to what triggered it. But I can open the newly created dwg without a problem.

LE3

  • Guest
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #5 on: May 12, 2012, 01:45:51 PM »
I took the code you posted, modified to only remove the lines with Host (I couldn't find what assembly I needed to reference for this). I created the same folder structure you have, so the only difference is that I'm running it inside of Autocad, without the using(Host....).

The Fatal Error I get does not return any information as to what triggered it. But I can open the newly created dwg without a problem.

Good!

The outPutFile argument it is the name of the temp file that it is created on the File.Copy() call.

The function it is tested with this:
Code - C#: [Select]
  1.         [WebMethod]
  2.         public string DrawTest()
  3.         {
  4.             string file1 = @"C:\hotfiles\CADTemp\firstfile.dwg";
  5.             string file2 = @"C:\hotfiles\CADTemp\seconfile.dwg";
  6.             string file3 = @"C:\hotfiles\CADTemp\thridfile.dwg";
  7.  
  8.             if (File.Exists(file1))
  9.             {
  10.                 File.Delete(file1);
  11.             }
  12.  
  13.             if (File.Exists(file2))
  14.             {
  15.                 File.Delete(file2);
  16.             }
  17.  
  18.             if (File.Exists(file3))
  19.             {
  20.                 File.Delete(file3);
  21.             }
  22.  
  23.             try
  24.             {
  25.                 Draw(file1);
  26.                 Draw(file2);
  27.                 Draw(file3);
  28.             }
  29.             catch
  30.             {
  31.  
  32.             }
  33.             return "Any luck?";
  34.         }
  35.  

So my guess it was also to the remove the inner transaction call with something like:
Code - C#: [Select]
  1.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  2.                     {
  3.                         BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  4.                         BlockTableRecord iModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  5.  
  6.                         ObjectId blockId = ObjectId.Null;
  7.                         db.ReadDwgFile(file.FullName, System.IO.FileShare.ReadWrite, false, "");
  8. string file = @"C:\hotfiles\CAD_Templates\Ductwork\3D\Elbow 45\DW1645ASY.dwg";
  9.                         blockId = db.Insert(file, db, true);
  10.                         if (blockId != ObjectId.Null)
  11.                         {
  12.                             BlockReference blockRef = new BlockReference(Point3d.Origin, blockId);
  13.                             iModelSpace.AppendEntity(blockRef);
  14.                             tr.AddNewlyCreatedDBObject(blockRef, true);
  15.                         }
  16.                         tr.Commit();
  17.                     }
  18.                     db.SaveAs(outputFile, DwgVersion.AC1015);
  19.  
The above works on RealDWG 2009 but still breaks on the SaveAs....

Here it is the whole .cs file that it is use for this test job for your reference:
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Services;
  6. using Autodesk;
  7. using Autodesk.AutoCAD;
  8. using Autodesk.AutoCAD.DatabaseServices;
  9. using Autodesk.AutoCAD.Runtime;
  10. using Autodesk.AutoCAD.Geometry;
  11. using System.Reflection;
  12. using System.IO;
  13.  
  14.  
  15. namespace RealDWGService
  16. {
  17.     /// <summary>
  18.     /// Summary description for Service1
  19.     /// </summary>
  20.     [WebService(Namespace = "http://tempuri.org/")]
  21.     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  22.     [System.ComponentModel.ToolboxItem(false)]
  23.     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  24.     // [System.Web.Script.Services.ScriptService]
  25.     public class Service1 : System.Web.Services.WebService
  26.     {
  27.         class Host : HostApplicationServices
  28.         {
  29.             public Host()
  30.             {
  31.                 RuntimeSystem.Initialize(this, 1033);
  32.             }
  33.  
  34.             public override ModelerFlavor ModelerFlavor { get { return ModelerFlavor.Full; } }
  35.  
  36.             private string SearchPath(string fileName)
  37.             {
  38.                 // check if the file is already with full path
  39.                 if (System.IO.File.Exists(fileName))
  40.                     return fileName;
  41.  
  42.                 // check application folder
  43.                 string applicationPath =
  44.                 Path.GetDirectoryName(
  45.                     Assembly.GetExecutingAssembly().Location
  46.                 );
  47.                 if (File.Exists(applicationPath + "\\" + fileName))
  48.                     return applicationPath + "\\" + fileName;
  49.  
  50.                 // search folders in %PATH%
  51.                 string[] paths =
  52.                 Environment.GetEnvironmentVariable(
  53.                     "Path").Split(new char[] { ';' }
  54.                 );
  55.                 foreach (string path in paths)
  56.                 {
  57.                     // some folders end with \\, some don't
  58.                     string validatedPath = "C:\\Program Files (x86)\\Autodesk\\RealDWG 2013\\" + fileName;
  59.                     //= Path.GetFullPath(path + "\\" + fileName);
  60.                     if (File.Exists(validatedPath))
  61.                         return validatedPath;
  62.                 }
  63.  
  64.                 // check the Fonts folders
  65.                 string systemFonts =
  66.                 Environment.GetEnvironmentVariable(
  67.                     "SystemRoot"
  68.                 ) + "\\Fonts\\";
  69.                 if (File.Exists(systemFonts + fileName))
  70.                     return systemFonts + fileName;
  71.  
  72.                 string rdwgFonts =
  73.                 "C:\\Program Files\\Autodesk RealDWG 2007\\Fonts\\";
  74.                 if (File.Exists(rdwgFonts + fileName))
  75.                     return rdwgFonts + fileName;
  76.  
  77.                 return "";
  78.             }
  79.  
  80.             public override string FindFile(
  81.                 string fileName,
  82.                 Database database,
  83.                 FindFileHint hint
  84.             )
  85.             {
  86.                 // add extension if needed
  87.                 if (!fileName.Contains("."))
  88.                 {
  89.                     string extension;
  90.                     switch (hint)
  91.                     {
  92.                         case FindFileHint.CompiledShapeFile:
  93.                             extension = ".shx";
  94.                             break;
  95.                         case FindFileHint.TrueTypeFontFile:
  96.                             extension = ".ttf";
  97.                             break;
  98.                         case FindFileHint.PatternFile:
  99.                             extension = ".pat";
  100.                             break;
  101.                         case FindFileHint.ArxApplication:
  102.                             extension = ".dbx";
  103.                             break;
  104.                         case FindFileHint.FontMapFile:
  105.                             extension = ".fmp";
  106.                             break;
  107.                         case FindFileHint.XRefDrawing:
  108.                             extension = ".dwg";
  109.                             break;
  110.                         // Fall through. These could have
  111.                         // various extensions
  112.                         case FindFileHint.FontFile:
  113.                         case FindFileHint.EmbeddedImageFile:
  114.                         default:
  115.                             extension = "";
  116.                             break;
  117.                     }
  118.  
  119.                     fileName += extension;
  120.                 }
  121.  
  122.                 return SearchPath(fileName);
  123.             }
  124.         }
  125.  
  126.  
  127.  
  128.         public static void Draw(string outputFile)
  129.         {
  130.             string acadTemplateFile = @"C:\hotfiles\CAD_Templates\Common\acad.dwt";
  131.             using (Host host = new Host())
  132.             {
  133.                 using (Autodesk.AutoCAD.DatabaseServices.Database db = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
  134.                 {
  135.                     File.Copy(acadTemplateFile, outputFile, false);
  136.                     db.ReadDwgFile(outputFile, System.IO.FileShare.ReadWrite, false, null);
  137.                     HostApplicationServices.WorkingDatabase = db;
  138.  
  139.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  140.                     {
  141.                         BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  142.                         BlockTableRecord iModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  143.  
  144.  
  145.                         ObjectId blockId = ObjectId.Null;
  146.  
  147.                         using (Transaction tran = db.TransactionManager.StartTransaction())
  148.                         {
  149.                             using (Autodesk.AutoCAD.DatabaseServices.Database sdb = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
  150.                             {
  151.                                 string file = @"C:\hotfiles\CAD_Templates\Ductwork\3D\Elbow 45\DW1645ASY.dwg";
  152.                                 sdb.ReadDwgFile(file, System.IO.FileShare.ReadWrite, false, "");
  153.  
  154.                                 blockId = db.Insert(file, sdb, true);
  155.                             }
  156.                             HostApplicationServices.WorkingDatabase = db;
  157.                             tran.Commit();
  158.  
  159.                         }
  160.  
  161.  
  162.                         BlockReference blockRef = new BlockReference(Point3d.Origin, blockId);
  163.                         iModelSpace.AppendEntity(blockRef);
  164.                         tr.AddNewlyCreatedDBObject(blockRef, true);
  165.  
  166.                         tr.Commit();
  167.                     }
  168.  
  169.                     db.SaveAs(outputFile, DwgVersion.AC1015);
  170.                 }
  171.             }
  172.         }
  173.  
  174.         [WebMethod]
  175.         public string DrawTest()
  176.         {
  177.             string file1 = @"C:\hotfiles\CADTemp\firstfile.dwg";
  178.             string file2 = @"C:\hotfiles\CADTemp\seconfile.dwg";
  179.             string file3 = @"C:\hotfiles\CADTemp\thridfile.dwg";
  180.  
  181.             if (File.Exists(file1))
  182.             {
  183.                 File.Delete(file1);
  184.             }
  185.  
  186.             if (File.Exists(file2))
  187.             {
  188.                 File.Delete(file2);
  189.             }
  190.  
  191.             if (File.Exists(file3))
  192.             {
  193.                 File.Delete(file3);
  194.             }
  195.  
  196.             try
  197.             {
  198.                 Draw(file1);
  199.                 Draw(file2);
  200.                 Draw(file3);
  201.             }
  202.             catch
  203.             {
  204.  
  205.             }
  206.             return "Any luck?";
  207.         }
  208.     }
  209. }
  210.  
« Last Edit: May 12, 2012, 01:53:18 PM by LE »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #6 on: May 13, 2012, 10:11:23 AM »
Well, Luis, I can run this latest code inside AutoCAD2012 and get all 3 new drawings created. I do get a crash after all is done, but I've solved that by removing all of these lines: 
                   HostApplicationServices.WorkingDatabase = db;
You may need to use those when working with RealDWG, I've never worked in that environment so really don't know. But by not returning the WorkingDatabase back to the current dwg in AutoCAD it causes the crash.

As to why it throws an exception for you when opening a DB, it sounds like it's limited to RealDWG. I will try to get this tested in AutoCAD2013 later on today....I jut noticed that it looks like this is the version you are working with.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #7 on: May 13, 2012, 10:25:22 AM »
That didn't take as long as I thought. I get the same results using the 2013 libraries. One thing I did notice was that the exact same code runs at least twice as fast in 2012 as it does in 2013.

LE3

  • Guest
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #8 on: May 13, 2012, 10:27:28 AM »
Well, Luis, I can run this latest code inside AutoCAD2012 and get all 3 new drawings created. I do get a crash after all is done, but I've solved that by removing all of these lines: 
                   HostApplicationServices.WorkingDatabase = db;
You may need to use those when working with RealDWG, I've never worked in that environment so really don't know. But by not returning the WorkingDatabase back to the current dwg in AutoCAD it causes the crash.

As to why it throws an exception for you when opening a DB, it sounds like it's limited to RealDWG. I will try to get this tested in AutoCAD2013 later on today....I jut noticed that it looks like this is the version you are working with.

edit:
That db line (HostApplicationServices.WorkingDatabase = db;) it is required in RealDWG.... This it is a test before trying to upgrade the modules to use RealDWG 2013.

Excellent Jeff and thank you so much for your help - Let me know the results you get on A2013.

LE.
« Last Edit: May 13, 2012, 12:06:17 PM by LE »

LE3

  • Guest
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #9 on: May 13, 2012, 10:28:28 AM »
That didn't take as long as I thought. I get the same results using the 2013 libraries. One thing I did notice was that the exact same code runs at least twice as fast in 2012 as it does in 2013.

Do you mean, the code breaks on the same line and with the same error? (i think you mean that works also with 2013 libs, but it is slower = got it - need my first coffee).
« Last Edit: May 13, 2012, 10:39:50 AM by LE »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #10 on: May 13, 2012, 12:23:32 PM »
Sorry, Luis. I meant that it works just fine, just as it does in 2012 for me, albeit a bit slower.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #11 on: May 14, 2012, 07:33:43 AM »
Usually when I'm crashing at SaveAs() I move that line above my Transaction.Commit() and everything works.  Why?  I have no idea.
Revit 2019, AMEP 2019 64bit Win 10

LE3

  • Guest
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #12 on: May 14, 2012, 10:43:15 AM »
Usually when I'm crashing at SaveAs() I move that line above my Transaction.Commit() and everything works.  Why?  I have no idea.

Thanks.

We think this is a *bug* on RealDWG 2013.
Now let's see if any of the adesk guys that frequent here, end up looking into this issue.

edit: I just opened a new topic about this on the adesk .NET forum to see if I can confirm if it is a bug... or our code.

LE!
« Last Edit: May 14, 2012, 11:04:37 AM by LE »

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #13 on: May 14, 2012, 11:41:01 AM »
You mentioned about 3D objects.  Could this have something to do with the 3D local caching features introduced in 2013?
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

LE3

  • Guest
Re: Anyone here using RealDWG (2013) need help to track an error...
« Reply #14 on: May 14, 2012, 11:52:11 AM »
You mentioned about 3D objects.  Could this have something to do with the 3D local caching features introduced in 2013?

I just read about this BTW.

These files are saved as A2007 and when they are placed into the new sheets/drawings are again saved as A2007...