.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating .dwg file Programmatically

31 REPLIES 31
Reply
Message 1 of 32
Anonymous
913 Views, 31 Replies

Creating .dwg file Programmatically

Hi All,
How to create a .dwg file with some entity example line, programmatically with c#, can any one help me with example please, thank's

Prakash
31 REPLIES 31
Message 2 of 32
deepa
in reply to: Anonymous

using System.io

File.create("C:\\temp\\ex.dwg");
Message 3 of 32
Ed.Jobe
in reply to: Anonymous

Can you open that example in acad?

Ed

EESignature

Message 4 of 32
deepa
in reply to: Anonymous

Yes.Sure
Message 5 of 32
gilseorin
in reply to: Anonymous

No, I tested it.
Creating dwg file is good,but can't open.
That's no available.
create .dvb file,.txt file ..... all is working, but can't open.
Message 6 of 32
deepa
in reply to: Anonymous

Right Click - >Select that File name - >open

It's working in the txt files and other extension files.

but I test it the dwg file.it's true.i will try get a solution for that.
Message 7 of 32
gilseorin
in reply to: Anonymous

Imports Autodesk.AutoCAD.Runtime
Imports System.io
Public Class GILSclass1
_
Public Sub EraseObjectsFromLayer()
File.Create("C:\\temp\\MyTest.dwg")
End Sub
End Class

Attempting to open created 'MyTest.dwg' file in the specified path, I meet the message of 'Drawing file is not valid.'
Message 8 of 32
Anonymous
in reply to: Anonymous

Why would you think that the System.IO knows how to create a dwg file??

wrote in message news:5498917@discussion.autodesk.com...
Imports Autodesk.AutoCAD.Runtime
Imports System.io
Public Class GILSclass1
_
Public Sub EraseObjectsFromLayer()
File.Create("C:\\temp\\MyTest.dwg")
End Sub
End Class

Attempting to open created 'MyTest.dwg' file in the specified path, I meet
the message of 'Drawing file is not valid.'
Message 9 of 32
gilseorin
in reply to: Anonymous

It's not my thougt, I only follow as you mentioned above.
Using system.io;
Message 10 of 32
Anonymous
in reply to: Anonymous

I didn't mention anyting above...

Database db = new Database();
db.SaveAs(...);
db.Dispose();


wrote in message news:5498985@discussion.autodesk.com...
It's not my thougt, I only follow as you mentioned above.
Using system.io;
Message 11 of 32
gilseorin
in reply to: Anonymous

Yes, you're right.
I already knew from previous post in this site.
I just wish to know the above method shown by deepa is valid or not.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Public Class GILSclass1
_
Public Sub CreateDrawingFile()
Dim db As Database = New Database(True, True)
db.SaveAs("C:\temp\MySecond.dwg", DwgVersion.Newest)
db.Dispose()
End Sub
End Class
Message 12 of 32
Anonymous
in reply to: Anonymous

I got ya... But you tried it...~)
If you want to work on that doc now in the current document context - open
it and lock it.
Also pass "CommandSession.Flags" to your CommandMethod

[CommandMethod("SMD", CommandSession.Flags)]
...
Document newDoc = Application.DocumentManager.Open(dwgpath, false);
newDoc.LockDocument();
//now it's your active database - add lines or such as questioned by the OP.

wrote in message news:5499219@discussion.autodesk.com...
Yes, you're right.
I already knew from previous post in this site.
I just wish to know the above method shown by deepa is valid or not.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Public Class GILSclass1
_
Public Sub CreateDrawingFile()
Dim db As Database = New Database(True, True)
db.SaveAs("C:\temp\MySecond.dwg", DwgVersion.Newest)
db.Dispose()
End Sub
End Class
Message 13 of 32
gilseorin
in reply to: Anonymous

Thank you,Palul.

What I can clear. ---> Adding commandFlags.Session,
newDoc is activated to the current drawing.

What I can get. --->I don't know what change was made with using method of newDoc.LockDocument.
Message 14 of 32
Anonymous
in reply to: Anonymous

CommandFlags.Session -> makes the command available in the application
context
instead of just the calling doc.

newDoc.LockDocument ->Before you edit a doc you must lock it. When an app
runs
in the doc context the doc is locked for you. Others must be locked
manually.

Attached is a sample of a test. Keyword test!



wrote in message news:5499346@discussion.autodesk.com...
Thank you,Palul.

What I can clear. ---> Adding commandFlags.Session,
newDoc is activated to the current drawing.

What I can get. --->I don't know what change was made with using
method of newDoc.LockDocument.
Message 15 of 32
Anonymous
in reply to: Anonymous

>DocumentCollection docs
= Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
This is not used in the attached file - I should have deleted it.

"Paul Richardson" wrote in message
news:5499364@discussion.autodesk.com...
CommandFlags.Session -> makes the command available in the application
context
instead of just the calling doc.

newDoc.LockDocument ->Before you edit a doc you must lock it. When an app
runs
in the doc context the doc is locked for you. Others must be locked
manually.

Attached is a sample of a test. Keyword test!



wrote in message news:5499346@discussion.autodesk.com...
Thank you,Palul.

What I can clear. ---> Adding commandFlags.Session,

newDoc is activated to the current drawing.

What I can get. --->I don't know what change was made with using
method of newDoc.LockDocument.
Message 16 of 32
Anonymous
in reply to: Anonymous

Paul, can you upload a similar example
for VS .NET 2003 / Acad2005 on VB.NET
Your prior example does not worked for me
Problem is on, I have not found on Browser
EditorInput in my VS version

Thanks in advance,

Fatty

~'J'~
Message 17 of 32
Anonymous
in reply to: Anonymous

I don't have 05 installed. If you must use it to learn try getting the
ARX api - although I would avoid it as it was the first incarnation
of the api and not very complete. Not much help/samples available.

How about downloading the Acad07 trial and an Express version
of the .net compilers. Many samples with the ARX api and some
labs available from Autodesk. Also I would start with running
commands in the document context and worry about the session
context once you get up and running.

wrote in message news:5499463@discussion.autodesk.com...
Paul, can you upload a similar example
for VS .NET 2003 / Acad2005 on VB.NET
Your prior example does not worked for me
Problem is on, I have not found on Browser
EditorInput in my VS version

Thanks in advance,

Fatty

~'J'~
Message 18 of 32
Anonymous
in reply to: Anonymous

>> newDoc.LockDocument();

The result of LockDocument() must be
Disposed() of explicitly, because that is
what unlocks the document.

If you let the runtime do it (e.g., whenever
it gets around to it), the document remains
locked until that happens.

So,

using( DocumentLock myLock = newDoc.LockDocument() )
{
// work with locked document here

} // document is unlocked here


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Paul Richardson" wrote in message news:5499364@discussion.autodesk.com...
CommandFlags.Session -> makes the command available in the application
context
instead of just the calling doc.

newDoc.LockDocument ->Before you edit a doc you must lock it. When an app
runs
in the doc context the doc is locked for you. Others must be locked
manually.

Attached is a sample of a test. Keyword test!



wrote in message news:5499346@discussion.autodesk.com...
Thank you,Palul.

What I can clear. ---> Adding commandFlags.Session,

newDoc is activated to the current drawing.

What I can get. --->I don't know what change was made with using
method of newDoc.LockDocument.
Message 19 of 32
Anonymous
in reply to: Anonymous

Sweet! Thanks Tony. I couldn't find an unlock method so
assumed it was just magic..~)
"Tony Tanzillo" wrote in message
news:5499486@discussion.autodesk.com...
>> newDoc.LockDocument();

The result of LockDocument() must be
Disposed() of explicitly, because that is
what unlocks the document.

If you let the runtime do it (e.g., whenever
it gets around to it), the document remains
locked until that happens.

So,

using( DocumentLock myLock = newDoc.LockDocument() )
{
// work with locked document here

} // document is unlocked here


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Paul Richardson" wrote in message
news:5499364@discussion.autodesk.com...
CommandFlags.Session -> makes the command available in the application
context
instead of just the calling doc.

newDoc.LockDocument ->Before you edit a doc you must lock it. When an app
runs
in the doc context the doc is locked for you. Others must be locked
manually.

Attached is a sample of a test. Keyword test!



wrote in message news:5499346@discussion.autodesk.com...
Thank you,Palul.

What I can clear. ---> Adding commandFlags.Session,

newDoc is activated to the current drawing.

What I can get. --->I don't know what change was made with using
method of newDoc.LockDocument.
Message 20 of 32
Anonymous
in reply to: Anonymous

Thanks for the quick reply
I agree I need to install a newer
VS version on my machine
I saw Acad07 Training VB.NET
and main problem is on many stuffs
frome there are not available for me

Regards,

Fatty

~'J'~

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost