Problem about DataBase.insert method in version 2021 and 2023

Problem about DataBase.insert method in version 2021 and 2023

570010762
Explorer Explorer
645 Views
6 Replies
Message 1 of 7

Problem about DataBase.insert method in version 2021 and 2023

570010762
Explorer
Explorer

Can anyone help? I  have use DataBase.insert method to insert a block to current database,  it's has no problem in version 2021 , the block displayed correctly ,    but it no working in version 2023.  

source code:

Document acDoc = AuCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

Database acCurDb = acDoc.Database;

using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())

{

Database headerDb = new Database();

headerDb.ReadDwgFile( path + "/blk.dwg", FileOpenMode.OpenForReadAndAllShare, true, null); headerDb.CloseInput(true);

Point3d basePoint = getPartListBasePosition();

Vector3d v = basePoint.GetAsVector();

v += new Vector3d(0, 56.0, 0);

Matrix3d mat = Matrix3d.Displacement(v);

acCurDb.Insert(mat, headerDb, false);

acTrans.Commit();

}

0 Likes
Accepted solutions (1)
646 Views
6 Replies
Replies (6)
Message 2 of 7

ActivistInvestor
Mentor
Mentor

@570010762 wrote:

no working in version 2023.  

What does not working mean?  What happens? Is there an exception? Is there any sign of a block being created in the destination database?

 

Lastly, have you tried passing true in the last argument to Insert() instead of false? 

 

 

0 Likes
Message 3 of 7

570010762
Explorer
Explorer

Thank you for your reply! 

I have create a new "dwg" document in CAD version 2023 ,  I want to insert a block , but the block does not display in drawing , and has no exception . I don't know if the insertion was successful or failed。
In CAD version 2021 ,the insertion is successful and the block is displayed.

0 Likes
Message 4 of 7

ActivistInvestor
Mentor
Mentor

Again, did you try changing the 3rd argument to Insert()?

0 Likes
Message 5 of 7

570010762
Explorer
Explorer

After changing the third parameter, the effect remains the same.

0 Likes
Message 6 of 7

_gile
Consultant
Consultant
Accepted solution

Hi,

You have to use this Database constructor with buildDefaultDrawing = false and noDocument = true.

You should dispose the newly created database when you're done with it (typically with a using statement).

You do not need a transaction.

This works for me.

var activeDocument = Application.DocumentManager.MdiActiveDocument;
var targetDatabase = activeDocument.Database;
using (var sourceDatabase = new Database(false, true))
{
    sourceDatabase.ReadDwgFile(sourceFileName, FileOpenMode.OpenForReadAndAllShare, true, null);
    targetDatabase.Insert(Matrix3d.Displacement(position.GetAsVector()), sourceDatabase, true);
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 7

570010762
Explorer
Explorer

Solved . Thank you very much!!

0 Likes