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

ReadDwgFile - side database correct useage

2 REPLIES 2
Reply
Message 1 of 3
Dale.Bartlett
1591 Views, 2 Replies

ReadDwgFile - side database correct useage

All, I have struck some seemingly contradictory information and would appreciate a comment on the correct method to access a side database (dwg), edit, and save to the same name. I have been doing this for ages but now wonder if correctly:

 

// Fenton version

 

public static void DoSomeWorkExt01(string DwgToProcess)

{

using (Database db = new Database(false, true))

{

db.ReadDwgFile(DwgToProcess, FileOpenMode.OpenForReadAndReadShare, false, "");

// closing the input makes sure the whole dwg is read from disk

// it also closes the file so you can SaveAs the same name

db.CloseInput(true);

// store the current working database, to reset

Database currDb = HostApplicationServices.WorkingDatabase;

// set working database

HostApplicationServices.WorkingDatabase = db;

{Do Some Work}

db.SaveAs(DwgToProcess, DwgVersion.Current);

// reset the working database

HostApplicationServices.WorkingDatabase = currDb;

}

}

 

// my code currently

public static void DoSomeWorkExt02(string DwgToProcess)

{

using (Database db = new Database(false, false))

{

db.ReadDwgFile(DwgToProcess, FileOpenMode.OpenForReadAndWriteNoShare, true, "");

{Do Some Work}

db.SaveAs(DwgToProcess, DwgVersion.Current);

}

}

 

Thanks, Dale.

 

 




______________
Yes, I'm Satoshi.
2 REPLIES 2
Message 2 of 3
FRFR1426
in reply to: Dale.Bartlett

Setting the HostApplicationServices.WorkingDatabase seems to be needed for some operations. From the docs:

 

Many areas of ObjectDBX code require a database to query for information. For example, if you make an Entity in memory, it may require default information from a database. It will take that information from the working database.
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 3
Dale.Bartlett
in reply to: FRFR1426

Thanks for the reply. I have been trialing Fenton's code and so far so good. I was looking for a single, all cases version. His original code referred only to attaching Xrefs, but it does seem the safer process for all occasions. Dale



______________
Yes, I'm Satoshi.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report