BlackBox Posted August 13, 2014 Posted August 13, 2014 I was thinking some like this. Public Sub CloseDWG1() Dim doc As Autodesk.AutoCAD.ApplicationServices.DocumentExten sion ' doc.CloseAndDiscard() End Sub What happens when you call CloseDWG1() method? Here's a hint... CloseAndDiscard() is an Extension Method to the Document Class. Quote
muck Posted August 14, 2014 Author Posted August 14, 2014 Blackbox, I looked your video link last night and notice that it is in C sharp. To answer your questions I don't know about extension methods are so I can't answer your question. I searched "Close and Discard" in the object browser and got the attached result. You said the the object browser is my friend. Ok how do I interpert my friend. So how do I interpret and produce the code I want from the result I have in he attached file? Thank you, Quote
muck Posted August 14, 2014 Author Posted August 14, 2014 The code I now have is Public Sub CloseDWG() Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acDocs As DocumentCollection = Application.DocumentManager 'Dim acdoce As DocumentExtension 'Dim acdoc As Application.DocumentManager.MdiActiveDocument 'acDocs.MdiActiveDocument DocumentExtension.CloseAndDiscard(acDocs.MdiActiveDocument) End Sub Seems to work Quote
BlackBox Posted August 14, 2014 Posted August 14, 2014 The code I now have is Public Sub CloseDWG() Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acDocs As DocumentCollection = Application.DocumentManager 'Dim acdoce As DocumentExtension 'Dim acdoc As Application.DocumentManager.MdiActiveDocument 'acDocs.MdiActiveDocument DocumentExtension.CloseAndDiscard(acDocs.MdiActiveDocument) End Sub Seems to work That may work fine for you... But again, CloseAndDiscard() is an Extension Method to the Document Class: Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.Runtime Imports System <Assembly: CommandClass(GetType(FOO.BAR))> Namespace FOO Public Class BAR <CommandMethod("BAZ")> _ Public Sub Baz() Dim doc As Document = Application.DocumentManager.MdiActiveDocument doc.CloseAndDiscard() End Sub End Class End Namespace Quote
muck Posted August 14, 2014 Author Posted August 14, 2014 I used your C sharp Code and VB intellisence to figure out my code but you said VB object browser is my friend. Is there any good beginner documents on learning AutoCAD VB.net object browser? This stuff seems somewhat overwhelming. I need a practical VB.net information for the AutoCAD user so I can start learning and sorting out this stuff. Thank you, Quote
muck Posted August 14, 2014 Author Posted August 14, 2014 I took put DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument) in a drawing open/close program loop. I get the error: "Check the Error Code property of the exception to determine HR Result returned by Com object" This error occurs when my program gets to the statement DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument) What is that error about and how do I solve this one? Thank you, Quote
BlackBox Posted August 14, 2014 Posted August 14, 2014 I used your C sharp Code and VB intellisence to figure out my code but you said VB object browser is my friend. Is there any good beginner documents on learning AutoCAD VB.net object browser? I say that Object Browser (OB) is your friend, because it is the key to your understanding the Object Model (and the Framework generally). It is impossible to memorize everything that the Framework provides, such as each-and-every-single-possible Overload, etc. Put simply, anything that can take a partial string and query the entirety of the Framework, and all assembly references for you, is most definitely your friend. Intellisense is a cornerstone of .NET development, as you can see in what feels like real-time what Properties, Methods, and Events are exposed to a given Type. This is useful in determining exactly what is (or sometimes what is not) available to the Type you're working at that moment. This stuff seems somewhat overwhelming. I need a practical VB.net information for the AutoCAD user so I can start learning and sorting out this stuff. Being completely honest, as someone who's still very much a student of .NET development... It _is_ overwhelming... At first. There's a reason why quality .NET development books frequently near +/- 2,000 page size, and a beginner is often reasonably informed that it will take them a year to become adept at .NET development concepts, IDE, and debugging. It's a challenge, that is often rewarding, and is incredibly powerful as compared to other lower level languages, but easy is not an adjective I'd every use to describe .NET development. Regurgitating the advice that was given me a year or two ago... Start teaching yourself how to develop for Windows, Forms, WPF, perhaps even a dabble in VSTO, and browser applications... Then, come back and start digging through AutoCAD's .NET API, which is a beast unto itself. Moving forward, in whichever direction you decide to go, just identify something that interests you (something fun if possible), and start reading everything you can on the topic of how to develop that. Code, and code, and code some more. Break it, and figure out what's wrong, and then learn how to fix it... It's the only way you're going to become proficient... And after you've seen some of the benefits of having done so, you'll be glad you did. HTH Quote
BlackBox Posted August 14, 2014 Posted August 14, 2014 I took put DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument) in a drawing open/close program loop. I get the error: "Check the Error Code property of the exception to determine HR Result returned by Com object" This error occurs when my program gets to the statement DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument) What is that error about and how do I solve this one? .NET Development rule #82376 - Read up on Try, Catch, Finally. Quote
Jeff H Posted August 15, 2014 Posted August 15, 2014 Where are you calling close and are in application context? Which can be set with CommandFlags.Session attribute <CommandMethod("Command", CommandFlags.Session)> The code needs to be ran in the context of the application instead of the document as default. If ran in the document context the method used to close the document is trying to run inside a document that you just made no longer exist. Quote
muck Posted August 15, 2014 Author Posted August 15, 2014 For reference my code is in the attached file. OSCLoop.txt Quote
muck Posted August 15, 2014 Author Posted August 15, 2014 I added CommandFlags Session to my command method and it seemed to solve that problem. Thanks Quote
BlackBox Posted August 15, 2014 Posted August 15, 2014 Where are you calling close and are in application context? Which can be set with CommandFlags.Session attribute <CommandMethod("Command", CommandFlags.Session)> The code needs to be ran in the context of the application instead of the document as default. If ran in the document context the method used to close the document is trying to run inside a document that you just made no longer exist. Well explained, as always, Jeff. Quote
muck Posted August 15, 2014 Author Posted August 15, 2014 My code has changed. Now I am try to save the drawing(s) in a loop. in the attached code I am having problems saving my file with the statement acDoc.Database.SaveAs(strFileName, True, DwgVersion.Current, _ acDoc.Database.SecurityParameters) I get file write errors. Code is include in attachment. For some reason this thread will not allow me to drag code text on the # icon to place code tags in thread. OpenSaveCloseLoop.txt Quote
BlackBox Posted August 15, 2014 Posted August 15, 2014 Shucks - if only there were another extension method, that would close and save. Quote
muck Posted August 15, 2014 Author Posted August 15, 2014 Ok, Change code to Save & Close and got another error. See attachment. Quote
muck Posted August 16, 2014 Author Posted August 16, 2014 The code works off of my data drive. It did not work off of my C drive because win 7 does not give me permission to use my C drive. Thank you, Quote
muck Posted August 17, 2014 Author Posted August 17, 2014 How find out what error message mean during debug run sessions?. For example I added a page setup routine to my loop programs and got the error "EnotFromtheDocument" What is that mean and how do I look that errors up other that using google? Does Autodesk document these errors? Thank you, Quote
muck Posted August 17, 2014 Author Posted August 17, 2014 In quick reply why does the thread not allow me to drag my code onto #icon to post it? Code is in shown in attachment. OpenWithPageSetup.txt Quote
BlackBox Posted August 18, 2014 Posted August 18, 2014 In quick reply why does the thread not allow me to drag my code onto #icon to post it? Code is in shown in attachment. I've never heard of someone doing that... Just hit the "#" code button, and paste your code between the code tags. Since we're briefly discussing post formatting; why are all of your posts manually broken into certain lengths, instead of normal sentencing? Cheers Quote
muck Posted August 18, 2014 Author Posted August 18, 2014 It seems like Net might be a little overwheming for the AutoCAD operator that just wants quick routines to get something done. Maybe VBA & lisp is a better fit but I want to stay in the programming main stream with AutoCAD. The fact that AutoDesk plans to drop VBA is another reason to keep plugging at this. I guess the main thing to do is keep plugging and don't give up. I think the biggest gain I made last week was to convince my company's network administrator to put the VS Express on my machine at work. Now I have excess to vb.net and AutoCAD at my workstation. Thank you, 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.