I'm not sure why you can't find FindFile. Here's an example anyway:
public class Testinsert
{
[CommandMethod("testinsert")]
static public void DoIt()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptResult res = ed.GetString("Give me a file to insert");
if (res.Status != PromptStatus.OK)
return;
string fname = res.StringResult;
if (!File.Exists(fname))
fname =
HostApplicationServices.Current.FindFile(fname,doc.Database,FindFileHint.Default);
using (Database db = new Database(false,false))
{
//read drawing
db.ReadDwgFile(fname,FileShare.Read,true,null);
using (Transaction t =
doc.TransactionManager.StartTransaction())
{
//insert it as a new block
ObjectId idBTR = doc.Database.Insert("test",db,false);
//create a ref to the block
BlockTable bt =
(BlockTable)t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite);
using (BlockReference bref = new
BlockReference(Point3d.Origin,idBTR))
{
btr.AppendEntity(bref);
t.AddNewlyCreatedDBObject(bref, true);
}
t.Commit();
}
}
}
}
wrote in message news:4894592@discussion.autodesk.com...
Albert,
I use .net api method ,but failed.
HostApplicationServices doesn't has FindFile property, I can read file, but
I don't know how to use Database.Insert method,could you show some examples
in detail.