Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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. :thumbsup:

 

Cheers

Posted

obviously I need to spend more time reading....

 

Looks like I have a few things to try next week.

Thank you again both.

Posted

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). :rofl: :beer:

Posted
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.
Posted (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 by BlackBox
  • 2 weeks later...
Posted

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?

Posted

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*

Posted

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).

Posted

*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.

 

:beer:

Posted

more reading to do then :rtfm:

 

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.

Posted

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. :)

Posted

BRILLIANT!!!

 

:beer: :celebrate:

 

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).

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...