.NET

Reply
Contributor
Luigi71
Posts: 22
Registered: ‎08-30-2011
Message 1 of 4 (193 Views)

File name

193 Views, 3 Replies
11-19-2012 01:46 AM

Hi to all.

 

I'm trying to save two drawings sequentially with the following code:

 

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime


Public Class Class1

<CommandMethod("SaveTwoDrawings")> _
Public Sub SaveTwoDrawings()


Dim doc As Document
Dim strDWGName As String
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Dim obj As Object

 

doc = acDocMgr(0)
strDWGName = doc.Name
strDWGName = "c:\MyDrawing#1.dwg"

doc.Database.SaveAs(strDWGName, True, DwgVersion.Current, doc.Database.SecurityParameters)

 

doc = acDocMgr(1)
strDWGName = doc.Name
strDWGName = "c:\MyDrawing#2.dwg"

doc.Database.SaveAs(strDWGName, True, DwgVersion.Current, doc.Database.SecurityParameters)


End Sub
End Class

 

While the two drawings are correctly saved in the desired position whith the desired names, only the name of the last drawing is updated ("Drawing2.dwg"--->"MyDrawing#2.dwg"), but the name of the first drawing still remains the original assigned by autocad "Drawing1.dwg", the autocad title bar is not updated too.

 

Some suggestions?

 

Thanks

*Expert Elite*
Alfred.NESWADBA
Posts: 8,566
Registered: ‎06-29-2007
Message 2 of 4 (187 Views)

Re: File name

11-19-2012 02:07 AM in reply to: Luigi71

Hi,

 

try to use the "Session"-flag for your command-definition:

   <CommandMethod("SaveTwoDrawings", Autodesk.AutoCAD.Runtime.CommandFlags.Session)> _
   Public Shared Sub SaveTwoDrawings()

      ...

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
Luigi71
Posts: 22
Registered: ‎08-30-2011
Message 3 of 4 (173 Views)

Re: File name

11-19-2012 04:40 AM in reply to: Luigi71

Thanks Alfred.

 

Tried the suggestion, but still not working.

 

 

Contributor
Luigi71
Posts: 22
Registered: ‎08-30-2011
Message 4 of 4 (140 Views)

Re: File name

11-20-2012 12:21 AM in reply to: Alfred.NESWADBA

Hi Alfred, I modified the code like this (including your suggestion).

 

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime


Public Class Class1

<CommandMethod("SaveTwoDrawings", CommandFlags.Session)> _
Public Shared Sub SaveTwoDrawings()


Dim doc As Document
Dim strDWGName As String
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Dim obj As Object

 

doc = acDocMgr(0)

acDocMgr.MdiActiveDocument = doc
strDWGName = doc.Name
strDWGName = "c:\MyDrawing#1.dwg"

doc.Database.SaveAs(strDWGName, True, DwgVersion.Current, doc.Database.SecurityParameters)

 

doc = acDocMgr(1)

acDocMgr.MdiActiveDocument = doc
strDWGName = doc.Name
strDWGName = "c:\MyDrawing#2.dwg"

doc.Database.SaveAs(strDWGName, True, DwgVersion.Current, doc.Database.SecurityParameters)


End Sub
End Class

 

In this case the routine works fine.

It seems that there is a need to make the document active. When the document is active the doc.Name property is updated.

 

Using Autocad 2010 32bit, Visual Studio Espress 2008

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community