Am trying to insert a drawing to specific coordinates, till now i did this part of coding; though this is executing but the drawing is not getting to coordinates specified
public void coordinates()
{
string dwgName = HostApplicationServices.Current.FindFile("D:\\AutoCAD DWG's\\SE-02416_37_A.dwg", acadApp.DocumentManager.MdiActiveDocument.Database, FindFileHint.Default);
//Database db1 = new Database(false, false);
Database db1 = new Database(false, false);
//db1.ReadDwgFile(dwgName, System.IO.FileShare.Write, true, "");
db1.ReadDwgFile(dwgName, FileOpenMode.OpenForReadAndWriteNoShare, true, "");
ObjectId BlkId;
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
BlkId = doc.Database.Insert(dwgName, db1, false);
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite, true);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference bref = new BlockReference(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0), BlkId);
btr.AppendEntity(bref);
tr.AddNewlyCreatedDBObject(bref, true);
bref.ExplodeToOwnerSpace();
bref.Erase();
tr.Commit();
tr.Dispose();
}
}
Can some one tell me where am i going wrong
The similar situation has been posted here and answered before. I think your problem is not the inserted block reference not being in the location of specified coordinate (0,0,0), it is that the block is nowhere to find.
There reason is here:
BlkId = doc.Database.Insert(dwgName, db1, false);
Note the first argument of the Insert() method requires a valid block name, while you pass in a full file path, meaning that the string includes something like "\", which is not allowed in e block name. When you do manual block definition, AutoCAD's BLOCK dialog box will validate block name and reject if the name contains invalid character, however, in .NET API, if a block definition is created by Database.Insert(), it is entirely up to programmer to make sure the block name does not contain invalid character. If it dies contain onvalid character, such as in your case, the block definition is still created, but the block name is BLANK! (you can write code to search the BlockTableRecord after your Database.Insert() to see what I am saying). Then it would cause the situation where the block reference based on this "BLANK" named block definition is inserted into nowhere.
So, you need to use the block file's file name without path/extension in the Database.Insert():
doc.Database.Insert(System.IO.Path.GetFileNameWithoutExtension(dwgName), db1, false)
HTH
Norman Yuan
Hello norman.yuan, I did as you said; its still inserting data in -179,-180,0.
I am trying to get this to 0,0,0 its still the same
Regards
Amit
amitk_189 wrote:Hello norman.yuan, I did as you said; its still inserting data in -179,-180,0.
I am trying to get this to 0,0,0 its still the same
Regards
Amit
What is the BASEPOINT variable in your template drawing. ??
I can think of no reason why the insertion point should change.
Have you tried the process inserting a different drawing ??
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper
Can't find what you're looking for? Ask the community or share your knowledge.