Autocad Database Save ?

Autocad Database Save ?

Anonymous
Not applicable
3,554 Views
5 Replies
Message 1 of 6

Autocad Database Save ?

Anonymous
Not applicable

Dear all,

Here i have one question,

while using myDBt.Save() program is terminating,

Is there only way to use myDBt.saveas()

Please give me suggession...

 

 

 

{code}

 

PublicSub text_replace_CAD(ByVal fname AsString, ByVal old_string AsString, ByVal new_string AsString)

 

Dim myTranst AsDatabaseServices.Transaction

 

Dim myTransMant AsDatabaseServices.TransactionManager

 

Dim myBTRt AsBlockTableRecord

 

Dim myBTt AsBlockTable

 

Dim myDBt AsNew DatabaseServices.Database(False, True)

 

If fname.ToUpper.EndsWith("DWG") Then'myDBt.ReadDwgFile(fname, IO.FileShare.ReadWrite, True, "")

myDBt.ReadDwgFile(fname, FileShare.ReadWrite,

True, "")

 

EndIf

myTransMant = myDBt.TransactionManager

myTranst = myTransMant.StartTransaction

myBTt = myDBt.BlockTableId.GetObject(OpenMode.ForWrite)

myBTRt = myBTt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

Dim myBTEn AsBlockTableRecordEnumerator = myBTRt.GetEnumerator()

 

WhilemyBTEn.MoveNext

 

Dim acEnt As Entity = CType(myTranst.GetObject(myBTEn.Current, OpenMode.ForWrite), Entity)

 

SelectCaseacEnt.GetType.Name.ToUpper

 

Case"DBTEXT"Dim dbt AsDBText = acEnt

dbt.TextString =

"Mabani"Case"MTEXT"Dim mtb AsMText = acEnt

mtb.SetContentsRtf(

"Mabani")

 

Case"RotatedDimension".ToUpper

 

Dim mtb AsRotatedDimension = acEnt

mtb.DimensionText =

"Mabani"EndSelectEndWhile

myDBt.Regenmode =

True

myDBt.CloseInput(

True)

myTranst.Commit()

myDBt.SaveAs(fname, DwgVersion.Current)

myDBt.Save()

myTransMant.Dispose()

EndSub

{code}

0 Likes
Accepted solutions (1)
3,555 Views
5 Replies
Replies (5)
Message 2 of 6

norman.yuan
Mentor
Mentor
Accepted solution

Yes, this is by design: you must use Database.SaveAs() to save changes made to the database.

 

Database.Save() method is inherited from the API interface under the hood and is not implemented (that is, if you call it, it raises exception like "...not implemented...".

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 6

Anonymous
Not applicable

Did you try to Lock the document before making any changes in the database and saving?

 

using (DocumentLock docLock = doc.LockDocument())
{
	you code here
	......
}

 

0 Likes
Message 4 of 6

Ertqwa
Advocate
Advocate

Hi,

 

Database.Save() is not implemented and always gives an error, as I understand it.

 

I save a database like this (C#):

 

// Save as tmp file.
objDatabase.SaveAs(ChangeEnd(strPath, "tmp"), DwgVersion.Current);
// Delete bak file.
if (System.IO.File.Exists(ChangeEnd(strPath, "bak")))
{ System.IO.File.Delete(ChangeEnd(strPath, "bak")); }
// Rename current dwg to bak file.
System.IO.File.Move(strPath, ChangeEnd(strPath, "bak"));
// Rename temp file to dwg file.
System.IO.File.Move(ChangeEnd(strPath, "tmp"), strPath);

 

The function ChangeEnd() you'll have to write yourself, I use it to change the extensions (C#):

        public static string ChangeEnd(string strSource, string strEnd)
        {
            // Change the last characters from string strSource into strNewExt.
            // strSource.Length must be >= strNewExt.
            // On error, it returns strSource.
            string strResult;

            try
            {
                if (strSource == null || strEnd == null) { return strSource; }
                if (strSource.Length < strEnd.Length) { return strSource; }
                if (strSource.Length == strEnd.Length) { return strEnd; }
                strResult = strSource.Substring(0, strSource.Length - strEnd.Length);
                strResult += strEnd;
                return strResult;
            }
            catch
            {
                return strSource;
            }
        }

 

0 Likes
Message 5 of 6

Hallex
Advisor
Advisor
Spoiler

Take a look at String.EndWith method,

then you have to use like this:

if (FileName.EndWith(".bak")

{

//do your mojo here

}

HTH

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 6 of 6

tyronebk
Collaborator
Collaborator

Ertqwa, you could also simplify your functions using some of the methods available in System.IO.Path.

0 Likes