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

Warning: An error occurred during save.

8 REPLIES 8
Reply
Message 1 of 9
prakashdotc
919 Views, 8 Replies

Warning: An error occurred during save.

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
8 REPLIES 8
Message 2 of 9
prakashdotc
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.
Message 3 of 9

. Edited by: logistique.lyon on Mar 5, 2009 6:10 PM
Message 4 of 9

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
Message 5 of 9
Anonymous
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
Message 6 of 9

This is a .cs file containing the two previous methods.
Message 7 of 9
Anonymous
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.
Message 8 of 9

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
Message 9 of 9

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.

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