sanderson Posted March 5, 2012 Posted March 5, 2012 Hi: After spending much of the morning here http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html and getting nowhere, I am posting this thread. I am trying to point to an AutoCAD drawing and get some system variable information from it to apply to an external SQL Server database. The code is really quite simple, and looks like this: [font=Courier New]GetInternalACADData(fil)[/font] fil is the filename with its full path. When I run the code (I will show that at the end), I get a FileNotFoundException was unhandled - The specified module could not be found. (Exception from HRESULT: 0x8007007E). The strange thing is that this error occurs before anything about a file is even attemped to be done in this subsequent code: [size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]Imports[/font][/color][/size][/color][/size][size=2][font=Courier New] Autodesk.AutoCAD.ApplicationServices[/font][/size] [size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]Imports[/font][/color][/size][/color][/size][size=2][font=Courier New] Autodesk.AutoCAD.DatabaseServices[/font][/size] [size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]Imports[/font][/color][/size][/color][/size][size=2][font=Courier New] Autodesk.AutoCAD.EditorInput[/font][/size] [size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]Imports[/font][/color][/size][/color][/size][size=2][font=Courier New] Autodesk.AutoCAD.Runtime[/font][/size] [size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]Module[/font][/color][/size][/color][/size][size=2][font=Courier New] ACAD_Functions[/font][/size] [font=Courier New][size=2][color=#0000ff][size=2][color=#0000ff] Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size][size=2] GetInternalACADData([/size][size=2][color=#0000ff][size=2][color=#0000ff]ByVal[/color][/size][/color][/size][size=2] fil [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][/font][size=2][font=Courier New])[/font][/size] [font=Courier New][size=2][color=#0000ff][size=2][color=#0000ff] Dim[/color][/size][/color][/size][size=2] acCurDb [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Database = [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] Database([/size][size=2][color=#0000ff][size=2][color=#0000ff]False[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][/font][size=2][font=Courier New])[/font][/size] [size=2][font=Courier New] acCurDb.ReadDwgFile(fil, System.IO.FileShare.Read, [/font][/size][font=Courier New][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][size=2], [/size][size=2][color=#a31515][size=2][color=#a31515]""[/color][/size][/color][/size][/font][size=2][font=Courier New])[/font][/size] [font=Courier New][size=2][color=#0000ff][size=2][color=#0000ff] Dim[/color][/size][/color][/size][size=2] strString [/size][size=2][color=#0000ff][size=2][color=#0000ff]As [/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][/font][size=2][font=Courier New] = acCurDb.Tdupdate.ToString[/font][/size] [font=Courier New][size=2][color=#0000ff][size=2][color=#0000ff] End[/color][/size][/color][/size][/font][size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]Sub[/font][/color][/size][/color][/size] [size=2][color=#0000ff][size=2][color=#0000ff][font=Courier New]End[/font][/color][/size][/color][/size][font=Courier New][size=2][color=#0000ff][size=2][color=#0000ff]Module[/color][/size][/color][/size][/font] Please let me know if you have any thoughts on this, and any additional information on using the AutoCAD API. Thank you. Quote
fixo Posted March 5, 2012 Posted March 5, 2012 Try to add class to your project like this Just change project name and class name in the next 3 lines: <Assembly: CommandClass(GetType([color=red]MyProject.MyClass[/color]))> Namespace [color=red]MyProject[/color] Public Class [color=red]MyClass[/color] Change the file name within the code code: Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry <Assembly: CommandClass(GetType(MyProject.MyClass))> Namespace MyProject Public Class MyClass <CommandMethod("ReadFileTest", "rft", CommandFlags.Session Or CommandFlags.Modal)> _ Public Sub TestInternalData() GetInternalACADData([color=red]"C:\Test\WorkingDrawing.dwg"[/color]) End Sub Public Sub GetInternalACADData(ByVal fil As String) Dim acCurDb As Database = New Database(False, True) acCurDb.ReadDwgFile(fil, System.IO.FileShare.Read, True, "") Dim strString As String = acCurDb.Tdupdate.ToString acCurDb.CloseInput(True) acCurDb.Dispose() MsgBox(strString) End Sub End Class End Namespace ~'J'~ Quote
sanderson Posted March 5, 2012 Author Posted March 5, 2012 Thanks, but no help there. The class is already in its own module anyhow. I am wondering if there is an issue with the dlls not being properly mapped, though I can produce the error botn in Windows 7-64 bit and Windows XP-32 bit. The imports all work fine. The file references I used for AutoCAD 2010 are acdbmgd.dll and acmgd.dll. Not sure if this is correct, though I read somewhere that it was. There may be an issue where I need more dll's which are dependent. If you know what those might be, please let me know. Thanks again! Quote
fixo Posted March 6, 2012 Posted March 6, 2012 Sorry friend, I have no ideas about this issue Maybe somebody else will be explain you better I'm afraid that with my bad English I will lead you in the wrong direction Regards, ~'J'~ Quote
SEANT Posted March 6, 2012 Posted March 6, 2012 The description for this thread, “Get drawing attributes externally – Issues”, means what exactly? The reason I ask is that an external .NET exe has to interface with AutoCAD with a different toolset that a .NET dll running within AutoCAD. During debugging, an exe would likely throw an exception immediately, similar to what you describe. Quote
sanderson Posted March 6, 2012 Author Posted March 6, 2012 So then, what references should I be using? Its strantge, because the intellisense comes up great and shows all the system variables and other things one would expect to see in AutoCAD? Currently I am using acdbmgd and acmgd, and the Imports I need SEEM to work. Are there more references required, or arwe these the wrong ones? Thanks Quote
SEANT Posted March 6, 2012 Posted March 6, 2012 The image below shows the references needed to access AutoCAD from an outside EXE. The screenshot was captured while I had the solution file from post #17 of this thread opened in Visual Studio 2010 (actually, some of the references had to be updated from that attachment). http://www.cadtutor.net/forum/showthread.php?39166 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.