new database, readdwgfile, insunits

new database, readdwgfile, insunits

fieldguy
Advisor Advisor
652 Views
3 Replies
Message 1 of 4

new database, readdwgfile, insunits

fieldguy
Advisor
Advisor

I am using this code to rename dwg files from a third party.  The insunits are set to "2" (feet).  I thought I could change the units at the same time, but it is not working.

We work in metres (insunits = "6").

 

string dwgname = "dwg from third party"; 
string newname = "newname.dwg";
string savepath = "c:\\temp\\";
using (Database db = new Database(false, true)) { db.ReadDwgFile(dwgname, FileOpenMode.OpenForReadAndWriteNoShare, false, ""); db.CloseInput(true); using (Transaction tr = db.TransactionManager.StartTransaction()) { Application.SetSystemVariable("INSUNITS", 6); tr.Commit(); }// using tr db.SaveAs(savepath + newname, DwgVersion.Current);
}// using new database

What is the correct procedure?   

0 Likes
Accepted solutions (1)
653 Views
3 Replies
Replies (3)
Message 2 of 4

fieldguy
Advisor
Advisor
Accepted solution

The answer is  replace "Application.SetSystemVariable("INSUNITS", 6)" with "db.Insunits = acdb.UnitsValue.Meters;"

I should have searched a bit further.

0 Likes
Message 3 of 4

_gile
Consultant
Consultant

Hi,

 

Try doing simply like this:

            using (var db = new Database(false, true))
            {
                db.ReadDwgFile(dwgname, FileOpenMode.OpenForReadAndAllShare, false, "");
                db.Insunits = UnitsValue.Meters;
                db.SaveAs(savepath + newname, DwgVersion.Current);
            }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 4

fieldguy
Advisor
Advisor

Yes - thanks.  It occurred to me (too late) that I didn't need a transaction to set an application system variable.

In my own words - "SEARCH FIRST" and use the correct search parameters.

0 Likes