Hi,
Your idea was right!! Thanks for your help.
I need also to change a little my code.
Here is the code I used:
public static void InsertBlock3(Database db, string FileName, Point3d InsertionPoint, double Rotation = 0)
{
ObjectId blkid = ObjectId.Null;
using (Database bdb = new Database(false, true))
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
bdb.ReadDwgFile(FileName, System.IO.FileShare.Read, true, "");
blkid = db.Insert(System.IO.Path.GetFileNameWithoutExtension(FileName), bdb, true);
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = default(BlockTableRecord);
btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
using (btr)
{
BlockReference bref = new BlockReference(InsertionPoint, blkid);
using (bref)
{
BlockTableRecord acBlkTblRec;
acBlkTblRec = tr.GetObject(blkid, OpenMode.ForRead) as BlockTableRecord;
BlockTableRecord accurspaceblktblrecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
accurspaceblktblrecord.AppendEntity(bref);
tr.AddNewlyCreatedDBObject(bref, true);
if (bref.IsDynamicBlock)
{
DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
{
if (dynBrefProps.PropertyName == "Visibility1")
{
dynBrefProps.Value = "M36";
}
}
}
if (acBlkTblRec.HasAttributeDefinitions)
{
// Add attributes from the block table record
foreach (ObjectId objID in acBlkTblRec)
{
DBObject dbObj = tr.GetObject(objID, OpenMode.ForRead) as DBObject;
if (dbObj is AttributeDefinition)
{
AttributeDefinition acAtt = dbObj as AttributeDefinition;
if (!acAtt.Constant)
{
using (AttributeReference acAttRef = new AttributeReference())
{
acAttRef.SetAttributeFromBlock(acAtt, bref.BlockTransform);
acAttRef.Position = acAtt.Position.TransformBy(bref.BlockTransform);
acAttRef.TextString = acAtt.TextString;
bref.AttributeCollection.AppendAttribute(acAttRef);
tr.AddNewlyCreatedDBObject(acAttRef, true);
}
}
}
}
}
}
}
tr.Commit();
}
}
}
With this code, attributs are showing perfectly.
I used this code as well
https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-2107599E-9405-4D8B-A6DD-83D603B41568
I am still facing an issue.
As said, attributs are showing up. However, when I move the block, then regen, attributs values are not updated.
When I insert my block via the tool itself, I can move the block, and attributs are updated with a regen. Here nothing is updated.
Ahmed