0

Ok, so as usual Autodesk has little to no documentation on the subject so I'm trying to glean from my seniors here. I'm attempting to write a bit of code that will perform a WBlock operation on a List of xrefs in a file. When I try to go through the WBlock process though Autocad raises an error stating there's an invalid key. I have no idea how to handle this particular exception and autodesk has no documentation on it. Anyone have any ideas?

            foreach (BlockTableRecord x in xlist)
            {
                ......

                //if the Xref doesn't already exist...
                if (!File.Exists(Path.Combine(FilePath, NewXrefs, XrName)))
                {
                    try
                    {
                        //write the file out to a base location with its same name
                        Database xdata = x.GetXrefDatabase(true);
                        Database NewXref = Adbase.Wblock(x.ObjectId);
                        NewXrPath = Path.Combine(FilePath, NewXrefs, XrName);
                        NewXref.SaveAs(NewXrPath, DwgVersion.AC1021);
                    }

                    catch (Autodesk.AutoCAD.Runtime.Exception aex)
                    {
                        if (aex.ErrorStatus == ErrorStatus.InvalidKey)
                        {
                            //what do I do here?? or how do I prevent this exception?
                        }
                    }
                }
prestonsmith
  • 758
  • 1
  • 9
  • 29
  • also! i you know of any documentation on the error status' themselves - i'll take that as well. I've already looked through the autodesk docs and the helpviewer – prestonsmith Sep 24 '13 at 21:32
  • What line of code throws the error? – Trae Moore Sep 25 '13 at 01:13
  • @TraeMoore thanks for responding - I believe the error is thrown once the debugger leaves the line "Database NewXref = Adbase.Wblock(x.ObjectId);" - previously I had the WBlock method look at the id of x and the same error was produced. – prestonsmith Sep 25 '13 at 12:33
  • I'm looking over the Wblock method and I see it has a few overloads. Have you had any luck implementing those? Also, is your Database class referring to Autodesk.AutoCAD.DatabaseServices.Database? The ambiguity of the name database really makes a strong case for adding something like this at the top of your solution: using AcDatabase = Autodesk.AutoCAD.DatabaseServices.Database; – Parrish Husband Sep 25 '13 at 13:30
  • 1
    Also, I see that the Wblock method you're invoking indicates the Autodesk.AutoCAD.DatabaseServices.ObjectId parameter is a blockId. I don't see where your object 'x' is defined, but I'm assuming its a BlockTableRecord. So when you create your database 'XData', why are you not running WBlock from that directly? I haven't tested any of this yet, but I'm tempted to now. – Parrish Husband Sep 25 '13 at 13:40
  • Good point @Locke, I should have thought to add more of the code to make that clear. I had tried using the "xdata" database originally but it automatically registered a fatal error every time I debugged so I assumed that it was improper syntactically. also, thanks for those comments; I've already used a few of the other overloads but since I didn't fully understand some of the other parameters I don't think it worked out quite correctly. The database is referenced earlier in the code correctly though and is coming from the active document so maybe my understand of how WBlock works is wrong? – prestonsmith Sep 25 '13 at 16:10

0 Answers0