muck Posted August 8, 2014 Posted August 8, 2014 Is there a way to open and close an AutoCAD drawing with VB.net so that the code can placed in a loop to read names off of a file list to load & Remove drawings in AutoCAD editor? I also need VB.net to save the drawing with before it closes the drawing from the editor. I am attempting to make a program loop that reads a file list then opens saves & closes each drawing read from that list. Once I have that program I can insert code for various batch routines in AutoCAD. Thank you, Quote
BlackBox Posted August 8, 2014 Posted August 8, 2014 Firstly, you're going to want to utilize the .NET Developer Guide applicable for the version(s) you are developing for... Here's one for 2013. Is there a way to open and close an AutoCAD drawing with VB.net so that the code can placed in a loop to read names off of a file list to load & Remove drawings in AutoCAD editor? I also need VB.net to save the drawing with before it closes the drawing from the editor. I am attempting to make a program loop that reads a file list then opens saves & closes each drawing read from that list.... You're going to have to familiarize yourself with the API, and Object Model either using the online/offline documentation. Object Browser and Intellisense are your friends. To get your started, here's a link to the documentation on adding a Document to the DocumentManager (aka openning a drawing). ... Once I have that program I can insert code for various batch routines in AutoCAD. Actually, you may be approaching this task in reverse order... First you should determine the specified tasks needing to be performed, then you can determine which method of manipulating your list of drawings is best suited for the task. More specifically, the link above shows you how to add a Document to the DocumentManager, which opens said Document in the Editor. One can also, depending on the task, access a given Document's Database outside of the Editor using the ReadDwgFile() Method as example (there's also Core Console, etc.). Presuming the task(s) being performed are capable of being performed outside of the Editor, the latter is going to offer you vastly superior processing times as there's inherently less 'overhead' in modifying Document as a side Database. Fully identifying the end goal, will help you to backwards plan, and save you time invested in this initiative in the end. HTH Quote
BIGAL Posted August 9, 2014 Posted August 9, 2014 Have you considered using a script very simple but would require more than likely opening the dwg then you can do what ever lisp VBA .Net etc. Open dwg1 do something close Y Open dwg2 do something close Y Quote
muck Posted August 11, 2014 Author Posted August 11, 2014 I want is a script to open, save and close a drawing in VB.net. That was simple to do in VBA but I don't know about VB.net. Thank you, Quote
BlackBox Posted August 11, 2014 Posted August 11, 2014 I want is a script to open, save and close a drawing in VB.net. For clarity, as we're talking about multiple APIs, one does not technically 'script' in an API that requires compiling... One develops a plug-in/add-on, application, etc. Script, in the context of AutoCAD APIs, is used to indicate an actual "Script" with .SCR file extension. Interchanging them, particularly in a .NET discussion, will only introduce confusion. That was simple to do in VBA but I don't know about VB.net. It is still quite simple in .NET API; the syntax, and especially the IDE are different as .NET is a higher level language with a much, much steeper learning curve. VBA has nothing to do with VB... It may read similar, but it has substantially different syntax at times (i.e., inheritance, events, etc.), and follows .NET rules, not ActiveX rules (while VB can access ActiveX controls, etc.)... You'd do well to approach this as if you knew nothing of VBA. You may find the .NET development concepts easier to understand that way. If you're continuously having trouble distinguishing between VBA & VB, then consider learning C#, which has all of the functionality of other .NET languages (i.e., VB, F#, etc.) and you'll have no issues distinguishing the syntax. Cheers Quote
muck Posted August 11, 2014 Author Posted August 11, 2014 I am looking for VB.net code that opens, saves and closes a single drawing in the AutoCAD editor. Thank you, Quote
BlackBox Posted August 11, 2014 Posted August 11, 2014 I am looking for VB.net code that opens, saves and closes a single drawing in the AutoCAD editor. ... That is why I provided you the link to documentation in post #2 of this thread. Quote
muck Posted August 11, 2014 Author Posted August 11, 2014 I have opened a drawing with code but only code to close a drawing I have found is: DocumentCollectionExtension.CloseAll(acDocMgr) It appears to close the editor and all drawings in it. I guess there is not a way to close a single drawing without closing the editor. Thank you, Quote
BlackBox Posted August 11, 2014 Posted August 11, 2014 I have opened a drawing with code but only code to close a drawing I have found is: DocumentCollectionExtension.CloseAll(acDocMgr) It appears to close the editor and all drawings in it. I guess there is not a way to close a single drawing without closing the editor. Your're _so_ close to figuring this out for yourself too... Here's a hint: Object Browser is your friend. [Edit] - Spoilers: Consider the Document Type's CloseAndDiscard(), or CloseAndSave() extension methods. Quote
muck Posted August 11, 2014 Author Posted August 11, 2014 I know Object browser is helpful but I have not used it very much. I there any tutorials on it? Well, I did figure out that F2 brings up the object browser in net. Thank you, Quote
muck Posted August 11, 2014 Author Posted August 11, 2014 I though it might be something like this acDocMgr.MdiActiveDocument.Editor.Document.Dispose() but I guess not. Quote
BIGAL Posted August 12, 2014 Posted August 12, 2014 I know very little about .NET but surely there is a syntax for close current doc v's closeall 2nd go close active ? Quote
BlackBox Posted August 12, 2014 Posted August 12, 2014 I know very little about .NET but surely there is a syntax for close current doc v's closeall 2nd go close active ? See the spoilers in my earlier post. :wink: Quote
BlackBox Posted August 12, 2014 Posted August 12, 2014 I though it might be something like thisacDocMgr.MdiActiveDocument.Editor.Document.Dispose() but I guess not. That calls the Dispose() Method of the parent Document, of the Editor, of the ActiveDocument, of the DocumentManager (Which is the ActiveDocument)... And not what you're after. Try storing MdiActiveDocument, and check the intellisence. Quote
muck Posted August 12, 2014 Author Posted August 12, 2014 Seems like since I have started debugging/Using VS10 that AutoCAD 2013 has slowed down. Has using VS10 with AutoCAD caused this slow down? Thank you, Quote
muck Posted August 12, 2014 Author Posted August 12, 2014 Public Sub CloseDwg() Dim strFileName As String = "C:\Test.dwg" Dim acDocMgr As DocumentCollection = Application.DocumentManager acDocMgr.MdiActiveDocument.???? End Sub ??? So how do I use object browser/Intellisence to sort this out? Quote
muck Posted August 12, 2014 Author Posted August 12, 2014 Object Browser. There is a closeAndDiscard feature but I don't know how to use it. See attachment. Quote
BlackBox Posted August 12, 2014 Posted August 12, 2014 Public Sub CloseDwg() Dim strFileName As String = "C:\Test.dwg" Dim acDocMgr As DocumentCollection = Application.DocumentManager acDocMgr.MdiActiveDocument.???? End Sub ??? So how do I use object browser/Intellisence to sort this out? I don't know how to answer a question that includes the answer... Either use Object Browser (in a separate window) or intellisense (as you type code) in order to identify the Property, Extension Method, Method, or Event you're after. Here's a quick video demonstration. Also, please use [code ] Tags. Quote
SLW210 Posted August 13, 2014 Posted August 13, 2014 Please read the Code Posting Guidelines and use Code Tags for your Code. Quote
muck Posted August 13, 2014 Author Posted August 13, 2014 I don't have rights to check out the video right now. I will check it out when I get to another computer. I was thinking some like this. Public Sub CloseDWG1() Dim doc As Autodesk.AutoCAD.ApplicationServices.DocumentExten sion ' doc.CloseAndDiscard() End Sub I think this follows code posting guidelines. 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.