VBA ExportLayout & How To Skip Open Message Box

VBA ExportLayout & How To Skip Open Message Box

Anonymous
Not applicable
4,664 Views
16 Replies
Message 1 of 17

VBA ExportLayout & How To Skip Open Message Box

Anonymous
Not applicable

Hi yall,

 

Created an "Export Layout" snippet of code.

My code below works, however how do stop/disable the "Open Message Box" prompt from popping up at the end or force "Do not Open" (See the picture).

 

I eventually want to loop through a folder of drawings, and this will undoubtedly prevent me from doing so since this prompt requires a manual input.

 

I appreciate the help in advance.

OJ

 

Public Sub ExportToLayout()

'ACAD Main Application
Dim oACADApp As AutoCAD.AcadApplication
Set oACADApp = GetObject(, "AutoCAD.Application")

'Master Active Document
Dim oMasterDwgDoc As AcadDocument
Set oMasterDwgDoc = oACADApp.ActiveDocument

'Background Ops oMasterDwgDoc.SetVariable "FILEDIA", 0 oMasterDwgDoc.SetVariable "BACKGROUNDPLOT", 0 Dim oSaveLocation As String: oSaveLocation = "D:\SampleLocation\NewExported.dwg" 'Send Export Command oMasterDwgDoc.SendCommand "EXPORTLAYOUT" & vbCr & oSaveLocation & vbCr '& 'Chr(27) -ESC End Sub

Open Message Box.PNG

4,665 Views
16 Replies
Replies (16)
Message 2 of 17

Ed__Jobe
Mentor
Mentor

Are  you running this from withing AutoCAD or some other app, like Excel?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 17

Anonymous
Not applicable

Hey @Ed__Jobe . Thanks for your reply. Much appreciated. I'm running this from Autocad's regular VBA IDE. 

 

I just opened a regular drawing with something on the layout to test. Like I said, send command Export Layout works, but once it's done it shows the Open Drawing File pop-up.

 

The pop-up won't fly  If I'm eventually looping through a set of drawings.

 

Thanks again for any feedback  

0 Likes
Message 4 of 17

Ed__Jobe
Mentor
Mentor

Then you don't need the GetObject function. There are some other issues. I'm busy the next couple hours. I'll get you something then.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 17

Ed__Jobe
Mentor
Mentor

Sorry, I was busy when I first read your question. I didn't pay close enough to the command you are interested in. I was thinking that you just wanted to import a layout into another dwg.

 

You can't suppress the dialog from the EXPORTLAYOUT command. You would need to develop your own version of the command. You can sort of mimic it by using the CHSPACE command and just move everything to ms.

 

Regarding the code you supplied, if you are going to use GetObject you should always test for the error condition where the app you want is not listed in the Running Object Table (ROT). If it's not, then use CreateObject.

    
    On Error Resume Next
    Err.Clear
    Set acad = GetObject(, "AutoCAD.Application")
    If Err <> 0 Then
        Set acad = CreateObject("AutoCAD.Application")
        acad.Visible = True
        AppActivate acad.Caption
        'User needs to navigate to the right drawing.
        acad.ActiveDocument.Utility.Prompt "Open the drawing file first and then re-execute this command!"
        Exit Sub
    End If

 

However, in this case, you don't need to use this since you are already in AutoCAD. Just use the ThisDrawing variable that are automatically bound when VBA initializes. For the application object, use ThisDrawing.Application.

 

When you set FILEDIA to 0, you need to reset it at the end of your sub.

 

Hard coding the file path into the sub is a bad idea as it makes it inflexible. Try using FSO methods to manipulate the path based on the current dwg name. e.g. add a prefix or suffix to the file name.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 6 of 17

Anonymous
Not applicable

Thanks @Ed__Jobe .

That's a big bummer on not being able to suppress the dialog from ExportLayout.

I feel like AutoCAD has little quirks like these that never quite made it into the actual VBA API. Although the sendcommand is slick, it definitely has its limitations.

 

I looked into the CHSPACE command, however it's not quite giving me the outcome I need.

Roger that! on the GetObject, and FileDia feedback. 

 

Again, I appreciate the reply!

0 Likes
Message 7 of 17

george1985
Collaborator
Collaborator

@Ed__Jobe wrote:

You can't suppress the dialog from the EXPORTLAYOUT command.


Hi @Ed__Jobe ,
Is this still valid, even in the latest Autocad 2023? Why are we unable to suppress the dialog from EXPORTLAYOUT command?

Thank you for the reply.

0 Likes
Message 8 of 17

Ed__Jobe
Mentor
Mentor

@george1985 Yes, it's still true. You can't really suppress any dialog. However, some commands are written to respect the FILEDIA sysvar. They all are preceded with a dash, e.g. -PU, -LAYER. They will accept a file spec at the command line. If you want to programmatically import a layout, I would use .NET CopyFrom method. You could use VBA, just iterate the Layout.Block object and copy all of it's ents to a new Layout. In general, its always better to code your solution rather than issuing a native command. You have much more control.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 9 of 17

george1985
Collaborator
Collaborator

Hi @Ed__Jobe ,
I am very grateful for your quick, information answer, plus you are doing it in your free time on weekends. Really amazing support you provide!
My issue is that, I can't use Autocad .NET. I simply have invested too much time in ActiveX API, and built too much ActiveX code in the last 10+ years, in order to throw away all of it. I guess I will continue using ActiveX for a foreseeable future, and switch to .NET only if at some point ActiveX gets removed from future Autocad versions.

Setting FILEDIA variable to 0, suppresses only the first dialog (one which requires to define the path for the exported .dwg file), but the second (and the last dialog) is still not affected by FILEDIA. This one:

george1985_0-1674947938361.png

I have to manually click on 'Don't open' each time, for each Layout (I have 20+ layouts sometimes in a single .dwg file).

@Ed__Jobe wrote:

You could use VBA, just iterate the Layout.Block object and copy all of it's ents to a new Layout. In general, its always better to code your solution rather than issuing a native command. You have much more control.


I didn't understand you this part. Why do I need to copy all entities to a new Layout?
I need them to be in the Model space (AcadModelSpace), not Layout (AcadPaperSpace).

Message 10 of 17

Ed__Jobe
Mentor
Mentor

@george1985 wrote:

Hi @Ed__Jobe ,

I didn't understand you this part. Why do I need to copy all entities to a new Layout?
I need them to be in the Model space (AcadModelSpace), not Layout (AcadPaperSpace).


I didn't realize you wanted to copy a layout to modelspace. To give you the best advice can you better describe what you want to do? If all the objects you want to move to model space are supported types, like lines, circles, etc., then try using the CHSPACE command. It doesn't use any dialogs. If you're trying to get it to a new dwg, the copy the existing dwg to a new one and then run chgspace. As to what I was talking about earlier, you can mimic the chgspace command by iterating the Layout.Block collection to get access to the Layout's entities and then copy those in a For..Each statement. I checked and VBA does have a Layout.CopyFrom method, but that is only going to copy the page setup, not the entities.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 11 of 17

george1985
Collaborator
Collaborator

Hi @Ed__Jobe ,
My apologies for the late reply, and thank you for your response.
I tried CHSPACE command and it is not exactly the same what EXPORTLAYOUT command does (which is what I need).
Here is somewhat short description of why EXPORTLAYOUT command is so valuable:
What we (I) do is make technical drawings of buildings. Those technical drawings can be a vertical section through a building or building facade. Such vertical section is then drawn in a very detailed manner, and then certain locations on that vertical section are marked as "Detail 1", "Detail 2", "Detail 3" and so on. Each of these details represent a separate Layout in Autocad. I need to send these layouts to the client as a pdf. This is easily achievable by just printing the particular layout. However, from time to time, there is client who is asking additionally for a .dwg version of that layout.
So what I do in that case is run the EXPORTLAYOUT command, for each of the layouts, and thus create a .dwg version of the .pdf file.
What EXPORTLAYOUT command does perfectly is that it exports the geometry from the Layout to the Model space (geometry like: heading, legend, BOM table...) AND (this is maybe the most important part) it cuts the Model space geometry completely, and leaves only the Model geometry which is visible inside the Viewport of that particular Layout. This capability of EXPORTLAYOUT is very useful, because it means that we are not providing to the client our whole vertical section geometry, but only the geometry of particular details. The geometry which is visible inside the Viewports of each of the Layouts.

The only issue with the EXPORTLAYOUT command is that it can't be automated through ActiveX, due to incapability to suppress that last dialog box ("The file was successfully created. Do yo want to open it now?").

Message 12 of 17

Ed__Jobe
Mentor
Mentor

Unfortunately, since you are using SendCommand, this is a dead end. You could submit a support request to suggest that they make a command line version. They only offer way is to use the api to replicate it. NET would be a better choice. I would go to the App Store and find a developer that can do it for you. 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 13 of 17

george1985
Collaborator
Collaborator

@Ed__Jobe wrote:

You could submit a support request to suggest that they make a command line version.


Thank you @Ed__Jobe .
Where should I submit that request?


@Ed__Jobe wrote:

They only offer way is to use the api to replicate it. NET would be a better choice. I would go to the App Store and find a developer that can do it for you. 


You min hire a developer to make a some sort of NET plugin for this functionality?

0 Likes
Message 14 of 17

Ed__Jobe
Mentor
Mentor

To file a support request, see this post

Yes. It’s probably cheaper to hire a developer. You can also ask in the NET forum. Some friends that are developers are @_gile and @BlackBox_ 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 15 of 17

george1985
Collaborator
Collaborator

Thank you very much for all the provided help @Ed__Jobe 

0 Likes
Message 16 of 17

sanchezgT58LY
Explorer
Explorer
Public Sub ExportToLayout()

'ACAD Main Application
Dim oACADApp As AutoCAD.AcadApplication
Set oACADApp = GetObject(, "AutoCAD.Application")

'Master Active Document
Dim oMasterDwgDoc As AcadDocument
Set oMasterDwgDoc = oACADApp.ActiveDocument

'Background Ops oMasterDwgDoc.SetVariable "FILEDIA", 0 oMasterDwgDoc.SetVariable "BACKGROUNDPLOT", 0 Dim oSaveLocation As String: oSaveLocation = "D:\SampleLocation\NewExported.dwg" 'Send Export Command
SendKeys "{ESC}" oMasterDwgDoc.SendCommand "EXPORTLAYOUT" & vbCr & oSaveLocation & vbCr '& 'Chr(27) -ESC End Sub

 I solved it like this. That solution works only in VBA Autocad. If you execute the code on VBA Excel or VB.net, it does not work. Have a good day 

Message 17 of 17

Ed__Jobe
Mentor
Mentor

Here's a link to a plugin that can be scripted.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature