.NET

Reply
Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 1 of 6 (371 Views)
Accepted Solution

Creating DWG using .Net

371 Views, 5 Replies
03-04-2012 08:36 PM

 

Hi,

 

 

How i can create DWG using .Net.

 

While creating DWG file, i have to choose one of the dwg template and

location for created DWG file.

 

Regards,

Raman

Hi,

 

do you want to have it opened in AutoCAD or do you just want to create a new file and open it just in memory?

Both samples:

 'first lines in the class have to include:
'Imports Autodesk.AutoCAD
Dim tTemplateFileName As String = "C:\TEMP\myTemplate.DWT"
Dim tNewFileName As String = "C:\TEMP\newFile.DWG"
'open it in editor
Dim tNewDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.Add(tTemplateFileName)
tNewDoc.CloseAndSave(tNewFileName)
'open it as database in memory
Dim tDb As DatabaseServices.Database = New DatabaseServices.Database(False, True)
tDb.SaveAs(tNewFileName, DatabaseServices.DwgVersion.Current)

 

 

- alfred -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,583
Registered: ‎06-29-2007
Message 2 of 6 (364 Views)

Re: Creating DWG using .Net

03-04-2012 11:09 PM in reply to: RamanSBV

Hi,

 

do you want to have it opened in AutoCAD or do you just want to create a new file and open it just in memory?

Both samples:

      'first lines in the class have to include:
      'Imports Autodesk.AutoCAD

      Dim tTemplateFileName As String = "C:\TEMP\myTemplate.DWT"
      Dim tNewFileName As String = "C:\TEMP\newFile.DWG"

      'open it in editor
      Dim tNewDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.Add(tTemplateFileName)
      tNewDoc.CloseAndSave(tNewFileName)

      'open it as database in memory
      Dim tDb As DatabaseServices.Database = New DatabaseServices.Database(False, True)
      tDb.SaveAs(tNewFileName, DatabaseServices.DwgVersion.Current)

 

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 3 of 6 (346 Views)

Re: Creating DWG using .Net

03-05-2012 01:51 AM in reply to: Alfred.NESWADBA

 

 

Just I have to create a DWG with given template and and open it in AUTOCAD.

 

So, I have written below statements

 

 'open it in editor
      Dim tNewDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.Ad​d(tTemplateFileName)
      tNewDoc.CloseAndSave(tNewFileName)

But " tNewDoc.CloseAndSave(tNewFileName)" is not working ... means it is not creating file in given path

 

Then i changed to

 

  tNewDoc.Database.SaveAs(tNewFileName, trueDwgVersion.Current,                          tNewDoc.Database.SecurityParameters);

 

 

and it is creating file in given location.

 

Thanks for helping me.....



*Expert Elite*
Alfred.NESWADBA
Posts: 9,583
Registered: ‎06-29-2007
Message 4 of 6 (319 Views)

Re: Creating DWG using .Net

03-05-2012 09:35 AM in reply to: RamanSBV

Hi,

 

>> But " tNewDoc.CloseAndSave(tNewFileName)" is not working

Have you started that by a self-defined command? If so have you added the "Session"-flag?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 5 of 6 (295 Views)

Re: Creating DWG using .Net

03-05-2012 08:36 PM in reply to: RamanSBV

 

 

Sorry..I am not understanding what you are saying....can you please elaborate it.

 

-Raman

*Expert Elite*
Alfred.NESWADBA
Posts: 9,583
Registered: ‎06-29-2007
Message 6 of 6 (250 Views)

Re: Creating DWG using .Net

03-07-2012 05:50 AM in reply to: RamanSBV

Hi,

 

you can define your own commands in your DLL, these commands do work either in document-context or in application-context. If they are working in document-context you can't activate an other document then that and that may be a problem if you try to open and/or to save another document then that where you started the command.

 

So take care of the attribtutes for your command-definition, one sample including the .Session flag:

<Autodesk.AutoCAD.Runtime.CommandMethod("OOCLoad", Autodesk.AutoCAD.Runtime.CommandFlags.Redraw Or Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet Or Autodesk.AutoCAD.Runtime.CommandFlags.Session)> _
Public Shared Sub OOCLoad()
   '....
End Sub

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.