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

Correctly creating new drawing file

16 REPLIES 16
Reply
Message 1 of 17
Anonymous
584 Views, 16 Replies

Correctly creating new drawing file

I am creating a new drawing from a template using this code.
[start]
Document odoc;
if (File.Exists(myFile) == false)
{
// create a file
odoc = acadApp.DocumentManager.Add(myBlankFilePath);
Database db = odoc.Database;
db.SaveAs(myFile, DwgVersion.AC1015);
db.CloseInput(true);
db.Dispose();
odoc.CloseAndDiscard();
}
odoc = acadApp.DocumentManager.Open(myFile, false);
[end]

The last line causes a messagebox to display saying there is 1 error . . . run Recover on this drawing . . .Yes/No.
If I answer No the file is created and it contains no errors.
The error only happens if the file is created. If it already exists then it opens without error.

What is the best way to create a new drawing file using a template?
16 REPLIES 16
Message 2 of 17
Anonymous
in reply to: Anonymous

Man-O-Man,

I have never seen someone do as much cross-posting as you. I was just
getting ready to respond to your post at the other place. Now, I see your
same post here.

wrote in message news:5564089@discussion.autodesk.com...
I am creating a new drawing from a template using this code.
[start]
Document odoc;
if (File.Exists(myFile) == false)
{
// create a file
odoc = acadApp.DocumentManager.Add(myBlankFilePath);
Database db = odoc.Database;
db.SaveAs(myFile, DwgVersion.AC1015);
db.CloseInput(true);
db.Dispose();
odoc.CloseAndDiscard();
}
odoc = acadApp.DocumentManager.Open(myFile, false);
[end]

The last line causes a messagebox to display saying there is 1 error . . .
run Recover on this drawing . . .Yes/No.
If I answer No the file is created and it contains no errors.
The error only happens if the file is created. If it already exists then it
opens without error.

What is the best way to create a new drawing file using a template?
Message 3 of 17
Anonymous
in reply to: Anonymous

I almost always post in both places. I consider is my civic duty.
It doesn't matter to me where you post your response as long as you respond.

By the way, is it really "cross-posting" when we are talking about 2 different sites? I always considered "cross-posting" as being when you post in more than one forum on the same site. (for example posting the same question in VB, ARX and .NET)
Message 4 of 17
Anonymous
in reply to: Anonymous

>> db.Dispose();
>> odoc.CloseAndDiscard();

Why are you disposing the database?

You didn't create it with 'new Database(..)' did you?

You never Dispose() a database that belongs
to a document open in the editor. The document
takes care of that.

You don't have to cross-post topics relating to .NET.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"John Lindstrom" wrote in message news:5564136@discussion.autodesk.com...
Man-O-Man,

I have never seen someone do as much cross-posting as you. I was just
getting ready to respond to your post at the other place. Now, I see your
same post here.

wrote in message news:5564089@discussion.autodesk.com...
I am creating a new drawing from a template using this code.
[start]
Document odoc;
if (File.Exists(myFile) == false)
{
// create a file
odoc = acadApp.DocumentManager.Add(myBlankFilePath);
Database db = odoc.Database;
db.SaveAs(myFile, DwgVersion.AC1015);
db.CloseInput(true);
db.Dispose();
odoc.CloseAndDiscard();
}
odoc = acadApp.DocumentManager.Open(myFile, false);
[end]

The last line causes a messagebox to display saying there is 1 error . . .
run Recover on this drawing . . .Yes/No.
If I answer No the file is created and it contains no errors.
The error only happens if the file is created. If it already exists then it
opens without error.

What is the best way to create a new drawing file using a template?
Message 5 of 17
Anonymous
in reply to: Anonymous

>> You don't have to cross post

Sorry, I didn't realize that he meant cross-posting
on another site.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5564151@discussion.autodesk.com...
I almost always post in both places. I consider is my civic duty.
It doesn't matter to me where you post your response as long as you respond.

By the way, is it really "cross-posting" when we are talking about 2 different sites? I always considered "cross-posting" as being when you post in more than one forum on the same site. (for example posting the same question in VB, ARX and .NET)
Message 6 of 17
jerrywinters
in reply to: Anonymous

Mark,

Did you get an answer to this question?

Jerry
Message 7 of 17
jerrywinters
in reply to: Anonymous

Mark,

When I use the AC1015 constant for the drawing version, I get the same result. When I use Current, things seem to work fine.

I've attached a VB.NET project to this post. My code appears below.

[code starts here]


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

Public Class vbstudentClass

<CommandMethod("CreateNewDoc")> _
Public Sub CreateNewDoc()
Dim myDoc As ApplicationServices.Document
myDoc = Application.DocumentManager.Add("Tutorial-iArch.dwt")
myDoc.Database.SaveAs("C:\FileFromTemplate.dwg", DatabaseServices.DwgVersion.Current)
myDoc.CloseAndDiscard()
myDoc = Application.DocumentManager.Open("C:\FileFromTemplate.dwg", False)
End Sub

End Class

[code ends here]

Jerry
Message 8 of 17
Anonymous
in reply to: Anonymous

I took out the dispose.

Document adoc = acadApp.DocumentManager.Add(myBlankFilePath);
Database db = adoc.Database;
db.SaveAs(myFile, DwgVersion.AC1015);
adoc.CloseAndDiscard();

I get the exact same error message.

Actually I had added the "dispose" in hoping it would fix the error.
Message 9 of 17
Anonymous
in reply to: Anonymous

Jerry,
Thanks very much.
I tried changing AC1015 to Current and no message was displayed.
I would call that a verifiable bug in the API.
Others would say conspiracy. (a nudge along the upgrade path)

It's a shame too because we still use the 2000 file format in house.
I guess I will use some "file copy" code and work around it that way for now.
Message 10 of 17
Anonymous
in reply to: Anonymous

Jerry,
FYI, this works for me like a charm
Thanks

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

Hi Mark.

I haven't verified this, but I'm pretty sure the problem
is related to the fact that the file is open in the drawing
editor.

Here is what I would try:

1. Save the file in the current release format, to a
temporary location, and then close the file in the
editor.

2. Create a new Database, and call ReadDwgFile()
to read in the file saved in step 1, followed by
CloseInput().

3. Then try saving down to 2000 format.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5564530@discussion.autodesk.com...
Jerry,
Thanks very much.
I tried changing AC1015 to Current and no message was displayed.
I would call that a verifiable bug in the API.
Others would say conspiracy. (a nudge along the upgrade path)

It's a shame too because we still use the 2000 file format in house.
I guess I will use some "file copy" code and work around it that way for now.
Message 12 of 17
jerrywinters
in reply to: Anonymous

Tony,

Great idea. Haven't tried it yet but will do so.

Jerry
Message 13 of 17
Anonymous
in reply to: Anonymous

Hi Jerry.

Perhaps even better, is to create a new Database
and WblockClone the source database into it, rather
than saving to a temp location and then having to
call ReadDwgFile.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5564783@discussion.autodesk.com...
Tony,

Great idea. Haven't tried it yet but will do so.

Jerry
Message 14 of 17
Anonymous
in reply to: Anonymous

I hate to even post this because it is embarrassing.
It turned out to be much easier to just copy the file then open it. Especially since I was using a template anyway.
[start]
if (File.Exists(myFile) == false)
{
// create a file
File.Copy(myBlankFilePath, myFile);
}
Document odoc = acadApp.DocumentManager.Open(myFile, false);
[end]
So simple.
Message 15 of 17
Anonymous
in reply to: Anonymous

[quote from John Lindstrom]
Man-O-Man,

I have never seen someone do as much cross-posting as you. I was just
getting ready to respond to your post at the other place. Now, I see your
same post here.
[/quote]
You've been "getting ready to respond" for quite a while now. Is a response forthcoming? :) Message was edited by: Mark Johnston
Message 16 of 17
Anonymous
in reply to: Anonymous

I have a class that is my frame work for autocad. I inserted your code and created a public sub.

Doing some testing getting something interesting that I have not seen before.

If I run a test where I call this sub from with in a class where my command methods are it works.

However if I run this from another class, where I would be getting the template name I get a "filer error" It is happening on the line of code where you are calling the template.

Any ideas of what is causing this?


pat
Message 17 of 17
Anonymous
in reply to: Anonymous

I am getting the same error. I have a program now that will save a file as a dxf but it is sometimes corrupt so I am trying to do it a different way to get consistency. Below is the Error I am getting:
"A COMException exception is thrown when an unrecognized HRESULT is returned from a COM method call."

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