dbroada Posted March 22, 2013 Posted March 22, 2013 Our drawings are named using incremental numbers, . I have a VBA routine that opens the next sequential drawing firstly incrementing the sheet number until the last sheet is found and then the next series number after resetting sheet to 0. All of this works well in VBA as I construct the file name and then supply that to AutoCAD via SendCommand. If the next file exists the drawing is openned without the dialogue box and if it doesn't exist the open file dialogue box is displayed. The beauty of this is AutoCAD handles all the "do you want to save changes" bit before actually openning the next file or displaying the dialogue. Now I am moving this routine to VB.Net. Is there an equivalent of SendCommand or do I have to build everything from scratch? If I have to build everything how do I open a file I know exists without using the dialogue box? And finally for now, what is the best way to check if the drawing has changed. Is checking DBMOD=0 still the best way? Quote
Tyke Posted March 22, 2013 Posted March 22, 2013 I'm just leaving for the weekend, but you could try " ...using the SendCommand method that is a member of the ActiveDocument property of the AcadApplication." Taken from the "AutoCAD .NET Developers Guide that is a free download from Autodesk. Have a good weekend. B. Quote
BlackBox Posted March 22, 2013 Posted March 22, 2013 Now I am moving this routine to VB.Net. Is there an equivalent of SendCommand or do I have to build everything from scratch? If I have to build everything how do I open a file I know exists without using the dialogue box? And finally for now, what is the best way to check if the drawing has changed. Is checking DBMOD=0 still the best way? The .NET equivillent for VBA's (COM's) SendCommand() is Document.SendStringToExecute()... Consider this from the docs: Access the AutoCAD Command Line However, you can still use COM from VB.NET, so you can still call SendCommand() if you like. The link above should help to clarify the differences. When opening a drawing (using .NET API), consider the DocumentManager.Add() Method... Again, from the docs: Create and Open a Drawing As for checking if a Drawing has been modified, DBMOD is what I use as well. Cheers Quote
dbroada Posted March 22, 2013 Author Posted March 22, 2013 obviously I need to spend more time reading.... Looks like I have a few things to try next week. Thank you again both. Quote
BlackBox Posted March 22, 2013 Posted March 22, 2013 obviously I need to spend more time reading.... You and me both, my friend, you and me both! Please do not misinterpret my being short on time, as being all RTFM on you - I'm not, I assure you... More often than I'd like I personally have to read the documentation (or Object Browser) before I can attempt a response. One of the few benefits of being so new to development, is that I'm constantly learning new things (too many to keep it all sorted, but still). Quote
dbroada Posted March 22, 2013 Author Posted March 22, 2013 Please do not misinterpret my being short on time, as being all RTFM on you - I'm not, I assure you...hadn't even crossed my mind. As I implied in one of the other threads I have to account for all my hours and they have to be booked to projects. I can only slip in a few hours of study a month without PMs getting upset so progress is slow and a few tips here and there work wonders. Quote
BlackBox Posted March 22, 2013 Posted March 22, 2013 (edited) hadn't even crossed my mind. As I implied in one of the other threads I have to account for all my hours and they have to be booked to projects. I can only slip in a few hours of study a month without PMs getting upset so progress is slow and a few tips here and there work wonders. Sadly, all of my development (both study and practice as it were) are solely done in my own time. Edited March 23, 2013 by BlackBox Quote
dbroada Posted April 2, 2013 Author Posted April 2, 2013 Its revive an old thread day! I have a few minutes spare to try and get my "open next numeric file" routine working. I decided that this was the way forwards. When opening a drawing (using .NET API), consider the DocumentManager.Add() Method... Again, from the docs: Create and Open a Drawing Apart from some (many) logic errors I got as far as reconstructing the file name and checking that it exists and then acDocMgr.Open(strFileName, False) tells me I cannot open a file in SDI mode. anyone know how I should be opening a file in SDI? Quote
BlackBox Posted April 2, 2013 Posted April 2, 2013 Perhaps instead use SendStringToExecute()... First check the active Document's DBMOD, and call Save if needed, then call Open supplying your new Document's file path? *untested* Quote
BlackBox Posted April 2, 2013 Posted April 2, 2013 Looks like this other poor chap has the same issue. Quote
dbroada Posted April 2, 2013 Author Posted April 2, 2013 Looks like this other poor chap has the same issue. I've come across him before - doesn't even search to see if the question has already been asked! Mind you, I didn't realise he had tried VB.Net back then. Probably tried it once and didn't like it. I will try the Send string to execute next (probably tomorrow now). Quote
BlackBox Posted April 2, 2013 Posted April 2, 2013 *Looks for my 'Easy Button'* using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using acApp = Autodesk.AutoCAD.ApplicationServices.Application; [assembly: CommandClass(typeof(CADTutor.Sample.OpenDocInSdiMode.Commands))] namespace CADTutor.Sample.OpenDocInSdiMode { public class Commands { [CommandMethod("FOO")] public void FOO() { Document doc = acApp.DocumentManager.MdiActiveDocument; // if document has not been titled, if (System.Convert.ToInt16(acApp.GetSystemVariable("DWGTITLED")) != 1 // or has unsaved changes | System.Convert.ToInt16(acApp.GetSystemVariable("DBMOD")) != 0) // save the document doc.SendStringToExecute("._QSAVE\n", false, false, true); // then prompt to open another document doc.SendStringToExecute("._OPEN\n", false, false, true); } } } ** Note - I left the echoCommand parameter of the SendStringToExecute() Method = true, as I found it potentially confusing when the Open dialog is displayed which only states "Select File." Given that your file name for the document to be opened is known, you may want to change this to false, so nothing is echoed at the Command Line. Quote
dbroada Posted April 2, 2013 Author Posted April 2, 2013 more reading to do then I have tried a couple of things before your post came along and it does seem to be the way to go. I don't have to add the "save?" stage as the open dialogue takes care of it for me. If the drawing has changed you are asked if you want to save it or not and since saving isn't always wanted that works for me. What I can't see is how to build the string given that I know the file name I want. If I use "open " & FileName; I get the open dialogue box. My best work around so far is to set FILEDIA to 0 before starting the command (while still in AutoCAD atm). I'm hoping I don't have to do that long term though. I haven't tried it with "._OPEN" yet. Quote
BlackBox Posted April 2, 2013 Posted April 2, 2013 Actually, DocumentManager.Open() works just fine... Even in SDI = 1. using Autodesk.AutoCAD.Runtime; using acApp = Autodesk.AutoCAD.ApplicationServices.Application; [assembly: CommandClass(typeof(CADTutor.Sample.OpenDocInSdiMode.Commands))] namespace CADTutor.Sample.OpenDocInSdiMode { public class Commands { [CommandMethod("CADTutor", "FOO", [color="red"]CommandFlags.Session[/color])] public void FOO() { string dwg = "[color="blue"]YourFilePath[/color]\\[color="blue"]YourFileName[/color].dwg"; acApp.DocumentManager.Open(dwg); } } } ... The crux to this, is the CommandFlags.Session attribute, which I learned from Tony in this post, after some Googling on the topic. Quote
dbroada Posted April 3, 2013 Author Posted April 3, 2013 BRILLIANT!!! I missed this yesterday as I left early for a Melody Gardot concert (also brilliant which is just as well as we are off to see her in Paris next week). I've now seen it and it works. Just a bit more logic to work out and I'm there. I can use the .Open method if the file exists and the .SendStringToexecute("Open "), if it doesn't. Thank you yet again. (It appears I don't need to read much as BB does such a good job for me). 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.