.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
915 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 21 of 32
Anonymous
in reply to: Anonymous

Is this nested properly?
[code]
using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId,
OpenMode.ForRead);
ObjectId blkRecId = bt[BlockTableRecord.ModelSpace];

using (DocumentLock myLock = newDoc.LockDocument())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRecId,
OpenMode.ForWrite);
btr.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
}

tr.Commit();
}
[/code]

"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 22 of 32
Anonymous
in reply to: Anonymous

The api has not only matured - how you work with it has changed.
Time to upgrade...)

wrote in message news:5499516@discussion.autodesk.com...
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'~
Message 23 of 32
deepa
in reply to: Anonymous

Sweet!Thank u gilseorin
Message 24 of 32
deepa
in reply to: Anonymous

Paul ,

I have one doubt.How to get the number of levels for nested Block in .net?Pls explain details with example.
Message 25 of 32
Anonymous
in reply to: Anonymous

"Paul Richardson" wrote

>> Is this nested properly?

Easy to determine this yourself. You just have
to be sure that anything that you do which
requires the document to be locked, must be
placed within the scope of the lock variable.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
Message 26 of 32
deepa
in reply to: Anonymous

no tony.

I dont want to place the nested Block tony.I need to get all the nested Block and I want to Calculate number of Levels for the nested Block in .net.

Pls help me
Message 27 of 32
Anonymous
in reply to: Anonymous

I see no reason to not also nest the read-only
operations in the lock scope, for the sake of
clarity.

Also, you can dispense with one pair of curly
braces when you have two using() clauses
with the same scope, like this:

public void singleblock()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
DocumentLock doclock = doc.LockDocument();
Transaction trans = doc.TransactionManager.StartTransaction();
using( doclock )
using( trans )
{
// Do stuff here
}
}

which is precisely equivlent to:

public void multipleblock()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
using( DocumentLock doclock = doc.LockDocument() )
{
using( Transaction trans = doc.TransactionManager.StartTransaction() )
{
// Do stuff here
}
}
}

that works because using() is like many other
constructs that can precede either a single line
of code, or a block of code:

if( test )
{
then();
}

verses

if( test )
then();



--
http://www.caddzone.com

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

"Paul Richardson" wrote in message news:5499519@discussion.autodesk.com...
Is this nested properly?
[code]
using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId,
OpenMode.ForRead);
ObjectId blkRecId = bt[BlockTableRecord.ModelSpace];

using (DocumentLock myLock = newDoc.LockDocument())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRecId,
OpenMode.ForWrite);
btr.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
}

tr.Commit();
}
[/code]

"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 28 of 32
Anonymous
in reply to: Anonymous

I was talking about code blocks, not drawing
blocks.

This is not an online classroom. Contact
Autodesk and ask them if they have any
API training classes in your area.

--
http://www.caddzone.com

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

wrote in message news:5499671@discussion.autodesk.com...
no tony.

I dont want to place the nested Block tony.I need to get all the nested Block and I want to Calculate number of Levels for the nested Block in .net.

Pls help me
Message 29 of 32
deepa
in reply to: Anonymous

Thanks Tony.
Message 30 of 32
Anonymous
in reply to: Anonymous

Thank you - Much appreciated!
"Tony Tanzillo" wrote in message
news:5499666@discussion.autodesk.com...
I see no reason to not also nest the read-only
operations in the lock scope, for the sake of
clarity.

Also, you can dispense with one pair of curly
braces when you have two using() clauses
with the same scope, like this:

public void singleblock()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
DocumentLock doclock = doc.LockDocument();
Transaction trans = doc.TransactionManager.StartTransaction();
using( doclock )
using( trans )
{
// Do stuff here
}
}

which is precisely equivlent to:

public void multipleblock()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
using( DocumentLock doclock = doc.LockDocument() )
{
using( Transaction trans =
doc.TransactionManager.StartTransaction() )
{
// Do stuff here
}
}
}

that works because using() is like many other
constructs that can precede either a single line
of code, or a block of code:

if( test )
{
then();
}

verses

if( test )
then();



--
http://www.caddzone.com

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

"Paul Richardson" wrote in message
news:5499519@discussion.autodesk.com...
Is this nested properly?
[code]
using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId,
OpenMode.ForRead);
ObjectId blkRecId = bt[BlockTableRecord.ModelSpace];

using (DocumentLock myLock = newDoc.LockDocument())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRecId,
OpenMode.ForWrite);
btr.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
}

tr.Commit();
}
[/code]

"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 31 of 32
Anonymous
in reply to: Anonymous

Since Tony took the time to hold my hand through this - here is the final
version.

wrote in message news:5160771@discussion.autodesk.com...
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
Message 32 of 32
gilseorin
in reply to: Anonymous

It's great.
I added a statement to your code below.

doc.CloseAndSave("C:\foo.dwg")

But, As I open it, the result of ZoomExtents is not realized.
I know the method 'SendstringToExcute' don't do time by time.

But, with the mind of luck......
You have the clue of the problem?

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