Migrating old vb.net to AutoCAD 2013
All of my older programs were written in visual studio 2008 express and worked great for years. I recompiled all of them with 2010 express and 4.0 framework using the new accoremgd.dll as well as the old ones (newer version of them though). All seems to work great with loading the program and the graphics and such but as soon as I try to programmatically insert a block from a specific directory I get multiple errors. One error is the "eHadMultipleReaders" and then a fatal error and the other states "eOutOfRange". This error seems random because I can insert some drawing files from a directory list within the program but the drawing file listed right below it in the list gives these errors. From a list of about 25 files, only 10 or so will insert without error and the rest just crash. Where these are in the list is ramdon also. All of my problems appear for now to be the insertion of external drawing files. Some insert, some don't with the exact same procedure. Any ideas? Why would the very same code work great for years and now not work at all?
Re: Migrating old vb.net to AutoCAD 2013
Have you done any debugging to find out what line the code errors on? Can you post the code in question?
Re: Migrating old vb.net to AutoCAD 2013
Re: Migrating old vb.net to AutoCAD 2013
What IDE are you using? One of the express versions? To find out what the error means, you need to look it up in the arx.chm found in the sdk. This is from the help for the ObjectID.UpgradeOpen method.
Quote:
If the object is currently open AcDb::kForRead with only one reader, then this function upgrades the object to open AcDb::kForWrite. In the process of changing to open for write, the object is closed, thus triggering any pertinent notification.
Returns Acad::eOk if successful. If the object has more than one reader, then the open status is not changed and Adesk::eHadMultipleReaders is returned. If the object is already open AcDb::kForWrite, then Acad::eWasOpenForWrite is returned. If the object is currently sending notification, then the open status is not changed and Acad::eWasNotifying is returned.
Re: Migrating old vb.net to AutoCAD 2013
VS has allows you to set a property in your project settings for dll type projects that specifies which program to run the dll in. But the Express versions do not have this option. However, you can manually edit your project file to set this up. You can edit your Project.csproj file or it is reccommended to edit the Project.csproj.user file. Here is a sample. You need to add the PropertyGroup to the end of your user file. Of course, you need to change the path to where you have acad installed.
Code:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files\AutoCAD Map 3D 2010\acad.exe</StartProgram>
<StartArguments></StartArguments>
<StartWorkingDirectory>C:\Program Files\AutoCAD Map 3D 2010</StartWorkingDirectory>
</PropertyGroup>
</Project>
After you set up your project, hit F5 and after acad starts, netload your dll. Then you can set a breakpoint and run a command to step through the code to see what line gives you the error.
Since you haven't posted any code, its kind of hard/impossible to tell you're getting eOutOfRange from. But that usually comes from requesting an index number from a list/array that is out of bounds.
Re: Migrating old vb.net to AutoCAD 2013
I've never actually debugged any of my programs and wouldn't even know how to since it runs within AutoCAD. Is it easy?
What does the "eHadMultipleReaders" even suggest? Internet and forum searches for "eHadMultipleReaders" don't really tell me much or are too broad of an answer.
Re: Migrating old vb.net to AutoCAD 2013
I'm using Visual Basic 2010 Express to make all of this. I was using 2008 but went to 2010 for the 4.0 framework.
With a little debugging myself I found that when I changed the Boolean from False to True for the preserveSourceDatabase property in
Dwg.Insert(Filenamestring, DwgDatabase, True)
... that most of my external drawings will insert now and the error "eHadMultipleReaders" doesn't pop up anymore. However, a couple of external drawings still give a "eOutOfRange" error and won't insert the file. I feel like I'm getting there but jut don't know how or why.
Re: Migrating old vb.net to AutoCAD 2013
Thanks for the debugging info. I'll give it a try.
As for the "OutOfRange" errors... Turns out there's something wrong with the files I'm trying to insert with my program. They're older files from older versions and have never given me any trouble before but 2013 seems to not like them. I manually inserted them into a blank drawing and then WBLOCKed them back out by selecting the block definition from the list and simply overwrote the old file by the same name. By doing this, no errors occur and the files block in beautifully. Of course my old method of viewing the thumbnail of the drawing file doesn't work now....
Re: Migrating old vb.net to AutoCAD 2013
FWIW -
I use Visual Studio 2010 Express, and used to manually edit project files as Ed has described to be able to debug, but it is just _so_ much simpler to use one of the .NET Wizards instead:
AcadNetAddinWizard by SpiderInNet1
AutoCAD .NET Wizard by Autodesk Developer Network
... Or other.
HTH