.NET

Reply
Active Member
prakashdotc
Posts: 10
Registered: ‎12-21-2006
Message 1 of 9 (355 Views)

Warning: An error occurred during save.

355 Views, 8 Replies
12-21-2006 11:25 PM
Hi all,

when i drag drop AutoCAD object which was created through .Net, i'm getting this error message before showing image in model space.

'Warning: An error occurred during save.
We recommend that you run RECOVER on the drawing.'

what's the cause of this problem, and can it be solved, thank's in advance.........................Prakash.C
Active Member
prakashdotc
Posts: 10
Registered: ‎12-21-2006
Message 2 of 9 (355 Views)

Re: Warning: An error occurred during save.

12-22-2006 02:43 AM in reply to: prakashdotc
Hi all,

i have narrowed down the problem area to the following code.

using (AcadDb.TextStyleTableRecord tstR = new Autodesk.AutoCAD.DatabaseServices.TextStyleTableRecord())
{
tstR.Name = "Style" + textStyleCount++;
tstR.Font = new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor(font.FaceName, font.IsBold, font.IsItalic, font.CharSet, font.PitchAndFamily);
AcadDb.TextStyleTable tst = (AcadDb.TextStyleTable)trans.GetObject(db.TextStyleTableId, AcadDb.OpenMode.ForWrite);
mText.TextStyle = tst.Add(tstR);
trans.AddNewlyCreatedDBObject(tstR, true);
}

when i comment these lines the problem does'nt raise.
Member
logistique.lyon
Posts: 4
Registered: ‎03-05-2009
Message 3 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-05-2009 10:02 AM in reply to: prakashdotc
. Edited by: logistique.lyon on Mar 5, 2009 6:10 PM
Member
logistique.lyon
Posts: 4
Registered: ‎03-05-2009
Message 4 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-05-2009 10:08 AM in reply to: prakashdotc
Hello,
I was developing a library in C# .Net enabling to generate railroad drawing from a client winform interface.
I had to create new TextStyles that I wanted to use in my Attributes references. And I encountered the same probleme. Each time I wanted to programmatically SaveAs my drawing, Autocad displayed this warning message. But I had simply to click ok and the drawing was generated.
I noticed that I couldn’t catch any exception.

So I found a very simple work around.
I just create manually a .dwg file containing my TextStyles. I read this file and clone TextStyleTableRecords to my new drawing where I need my TextStyles. All is working perfectly.

This is the sample of my source code :


public void LoadTextStyles(
Database currentAcDb,
string inputFileDirectory,
string inputFileName)
{
Database dbSourceDb = new Database(false, true);
Database dbTargetDb = currentAcDb;

Logs.Trace.TraceInfo("LoadTextStyles()", "textstyle loading started", _activeEditor, IsInDebugOnAcadConsole);

// Open two transactions, the 1rst one for getting blocks from .dwg source file,
// the 2nd one for inserting cloned blocks in the current drawing.
Autodesk.AutoCAD.DatabaseServices.TransactionManager tmSourceTm = dbSourceDb.TransactionManager;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tmTargetTm = dbTargetDb.TransactionManager;
try
{
// Get name of DWG from which to copy blocks;
if (!System.IO.Directory.Exists(inputFileDirectory))
throw new Exception("Le dossier censé contenir le bloc n'existe pas à l'endroit spécifié.");

string sourceFilePath = "";
if (inputFileDirectory.EndsWith(@"\"))
{
sourceFilePath = inputFileDirectory + inputFileName + ".dwg";
}
else
{
sourceFilePath = inputFileDirectory + @"\" + inputFileName + ".dwg";
}

if (!System.IO.File.Exists(sourceFilePath))
throw new Exception("Le fichier censé fournir le bloc n'existe pas.");

AcadFunctions.CloneTextStylesFromOneDbToAnother(dbSourceDb, dbTargetDb, tmSourceTm, sourceFilePath, inputFileName, _activeEditor, IsInDebugOnAcadConsole);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Logs.Trace.TraceError(ex, _activeEditor, IsInDebugOnAcadConsole);
}
catch (System.Exception ex)
{
Logs.Trace.TraceError(ex, _activeEditor, IsInDebugOnAcadConsole);
}
finally
{
tmSourceTm.Dispose();
tmTargetTm.Dispose();
dbSourceDb.Dispose();
//dbTargetDb.Dispose();
}
}


internal static void CloneTextStylesFromOneDbToAnother(
Database dbSourceDb,
Database dbTargetDb,
Autodesk.AutoCAD.DatabaseServices.TransactionManager tmSourceTm,
string sourceFilePath,
string fileName,
Editor activeEditor,
bool isInDebugOnAcadConsole)
{
try
{
// Read the DWG into the side database
dbSourceDb.ReadDwgFile(sourceFilePath, System.IO.FileShare.Read, true, "");
}
catch (System.Exception)
{
throw new System.Exception("Unable to read drawing source file.");
}
// Create a variable to store the list of block identifiers
ObjectIdCollection oicBlockIds = new ObjectIdCollection();

using (Transaction tCurrentTrans = tmSourceTm.StartTransaction())
{
// Open the block table
TextStyleTable btTextStyleTable =
(TextStyleTable)tmSourceTm.GetObject(dbSourceDb.TextStyleTableId, OpenMode.ForRead, false);

// Check each block in the block table
foreach (ObjectId oiCurrentBtrId in btTextStyleTable)
{
TextStyleTableRecord btr = (TextStyleTableRecord)tmSourceTm.GetObject(oiCurrentBtrId, OpenMode.ForRead, false);

// No need to get the Standard textstyle because it's not replaceable in the new database
if (btr.Name!=TextStyleName.Standard.ToString())
{
oicBlockIds.Add(oiCurrentBtrId);
Logs.Trace.TraceInfo("CloneTextStylesFromOneDbToAnother",
"Read "
+ btr.Name
+ " textstyle definition",
activeEditor,
isInDebugOnAcadConsole);
}
btr.Dispose();
}
btTextStyleTable.Dispose();
}

// Copy textstyles from source to destination database
IdMapping mapping = new IdMapping();
dbSourceDb.WblockCloneObjects(oicBlockIds,
dbTargetDb.TextStyleTableId,
mapping,
DuplicateRecordCloning.Replace,
false);

RemoveNotWantedLayer(dbTargetDb); // This is an optionnal function I created to delete the not wanted layers
Logs.Trace.TraceInfo("CloneTextStylesFromOneDbToAnother",
"Loaded "
+ oicBlockIds.Count.ToString()
+ " textstyle definitions from "
+ sourceFilePath
+ " to the current drawing.",
activeEditor,
isInDebugOnAcadConsole);
}


Matthieu Adjogah
m.adjogah@gmail.com
*Tony Tanzillo
Message 5 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-05-2009 11:27 AM in reply to: prakashdotc
Sorry, can't read your code in a newsreader.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6137001@discussion.autodesk.com...
Hello, I was developing a library in C# .Net enabling to generate railroad
drawing from a client winform interface. I had to create new TextStyles that
I wanted to use in my Attributes references. And I encountered the same
probleme. Each time I wanted to programmatically SaveAs my drawing, Autocad
displayed this warning message. But I had simply to click ok and the drawing
was generated. I noticed that I couldn't catch any exception. So I found a
very simple work around. I just create manually a .dwg file containing my
TextStyles. I read this file and clone TextStyleTableRecords to my new
drawing where I need my TextStyles. All is working perfectly. This is the
sample of my source code : public void LoadTextStyles( Database currentAcDb,
string inputFileDirectory, string inputFileName) { Database dbSourceDb = new
Database(false, true); Database dbTargetDb = currentAcDb;
Logs.Trace.TraceInfo("LoadTextStyles()", "textstyle loading started",
_activeEditor, IsInDebugOnAcadConsole); // Open two transactions, the 1rst
one for getting blocks from .dwg source file, // the 2nd one for inserting
cloned blocks in the current drawing.
Autodesk.AutoCAD.DatabaseServices.TransactionManager tmSourceTm =
dbSourceDb.TransactionManager;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tmTargetTm =
dbTargetDb.TransactionManager; try { // Get name of DWG from which to copy
blocks; if (!System.IO.Directory.Exists(inputFileDirectory)) throw new
Exception("Le dossier censé contenir le bloc n'existe pas à l'endroit
spécifié."); string sourceFilePath = ""; if
(inputFileDirectory.EndsWith(@"\")) { sourceFilePath = inputFileDirectory +
inputFileName + ".dwg"; } else { sourceFilePath = inputFileDirectory + @"\"
+ inputFileName + ".dwg"; } if (!System.IO.File.Exists(sourceFilePath))
throw new Exception("Le fichier censé fournir le bloc n'existe pas.");
AcadFunctions.CloneTextStylesFromOneDbToAnother(dbSourceDb, dbTargetDb,
tmSourceTm, sourceFilePath, inputFileName, _activeEditor,
IsInDebugOnAcadConsole); } catch (Autodesk.AutoCAD.Runtime.Exception ex) {
Logs.Trace.TraceError(ex, _activeEditor, IsInDebugOnAcadConsole); } catch
(System.Exception ex) { Logs.Trace.TraceError(ex, _activeEditor,
IsInDebugOnAcadConsole); } finally { tmSourceTm.Dispose();
tmTargetTm.Dispose(); dbSourceDb.Dispose(); //dbTargetDb.Dispose(); } }
internal static void CloneTextStylesFromOneDbToAnother( Database dbSourceDb,
Database dbTargetDb, Autodesk.AutoCAD.DatabaseServices.TransactionManager
tmSourceTm, string sourceFilePath, string fileName, Editor activeEditor,
bool isInDebugOnAcadConsole) { try { // Read the DWG into the side database
dbSourceDb.ReadDwgFile(sourceFilePath, System.IO.FileShare.Read, true,
""); } catch (System.Exception) { throw new System.Exception("Unable to read
drawing source file."); } // Create a variable to store the list of block
identifiers ObjectIdCollection oicBlockIds = new ObjectIdCollection(); using
(Transaction tCurrentTrans = tmSourceTm.StartTransaction()) { // Open the
block table TextStyleTable btTextStyleTable =
(TextStyleTable)tmSourceTm.GetObject(dbSourceDb.TextStyleTableId,
OpenMode.ForRead, false); // Check each block in the block table foreach
(ObjectId oiCurrentBtrId in btTextStyleTable) { TextStyleTableRecord btr =
(TextStyleTableRecord)tmSourceTm.GetObject(oiCurrentBtrId, OpenMode.ForRead,
false); // No need to get the Standard textstyle because it's not
replaceable in the new database if
(btr.Name!=TextStyleName.Standard.ToString()) {
oicBlockIds.Add(oiCurrentBtrId);
Logs.Trace.TraceInfo("CloneTextStylesFromOneDbToAnother", "Read " + btr.Name
+ " textstyle definition", activeEditor, isInDebugOnAcadConsole); }
btr.Dispose(); } btTextStyleTable.Dispose(); } // Copy textstyles from
source to destination database IdMapping mapping = new IdMapping();
dbSourceDb.WblockCloneObjects(oicBlockIds, dbTargetDb.TextStyleTableId,
mapping, DuplicateRecordCloning.Replace, false);
RemoveNotWantedLayer(dbTargetDb); // This is an optionnal function I created
to delete the not wanted layers
Logs.Trace.TraceInfo("CloneTextStylesFromOneDbToAnother", "Loaded " +
oicBlockIds.Count.ToString() + " textstyle definitions from " +
sourceFilePath + " to the current drawing.", activeEditor,
isInDebugOnAcadConsole); } Matthieu Adjogah m.adjogah@gmail.com
Member
logistique.lyon
Posts: 4
Registered: ‎03-05-2009
Message 6 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-06-2009 03:10 AM in reply to: prakashdotc
This is a .cs file containing the two previous methods.
*Tony Tanzillo
Message 7 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-06-2009 09:17 AM in reply to: prakashdotc
I see no calls to Commit() any transaction in your code,
and I have no idea what RemoveNotWantedLayer() does.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6137422@discussion.autodesk.com...
This is a .cs file containing the two previous methods.
Valued Contributor
bert.vanpeteghem
Posts: 57
Registered: ‎07-10-2008
Message 8 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-07-2009 10:25 AM in reply to: prakashdotc
I have succesfully run this version of your code without any errors or problems:



using (Transaction t = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())

{



// load block table

ObjectId btId = Application.DocumentManager.MdiActiveDocument.Database.BlockTableId;

BlockTable bt = (BlockTable)t.GetObject(btId, OpenMode.ForRead);



// load modelspace

ObjectId modelspaceId = bt[BlockTableRecord.ModelSpace];

BlockTableRecord modelspace = (BlockTableRecord)t.GetObject(modelspaceId, OpenMode.ForWrite);



// textstyle blocktable





Database db = Application.DocumentManager.MdiActiveDocument.Database;

MText mText = new MText();



using (TextStyleTableRecord tstR = new TextStyleTableRecord())

{

tstR.Name = "Style" + 0;

tstR.Font = new FontDescriptor("Calibri", false, false, 0, 0);

TextStyleTable tst = (TextStyleTable)t.GetObject(db.TextStyleTableId, OpenMode.ForWrite);

mText.TextStyle = tst.Add(tstR);

t.AddNewlyCreatedDBObject(tstR, true);

}





mText.Contents = "hahahahahahah";



modelspace.AppendEntity(mText);



t.AddNewlyCreatedDBObject(mText, true);



t.Commit();

}





If this does not work, can you explain what you mean by Drag and Drop?



--



http://cupocadnet.blogspot.com
Member
logistique.lyon
Posts: 4
Registered: ‎03-05-2009
Message 9 of 9 (355 Views)

Re: Warning: An error occurred during save.

03-16-2009 07:22 AM in reply to: prakashdotc
I use "RemoveNotWantedLayer" method just to delete unused layers that I imported during some block imports. No need to call it.
And no need to commit any transaction because I use them only to read informations (id's in TextStyleTable). Then I use "WblockCloneObjects" method to get TextStyleTableRecord's.

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 familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

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

Ask the Community