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