Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some code that replaces title blocks in batch that works good (excerpt below). But for some reason the few attributes in the block that are set to Constant = Yes are appearing in an DDATTE edit of the block after it's inserted even with the attribute set correctly. A manual insert of the block has the desire result. What am I doing wrong? What am I missing?
Code:
private static bool ProcessTitleBlockObjectMigration(Transaction transaction, Database db, ObjectId id, string titleBlocksPath)
{
using (DBObject dbObj = transaction.GetObject(id, OpenMode.ForRead))
{
if (dbObj is BlockReference)
{
BlockReference blockRef = (BlockReference)dbObj;
string blockName = blockRef.Name;
ObjectId ownerId = blockRef.OwnerId;
string replacementBlockName = GetReplacementBlockName(blockName);
if (replacementBlockName == "")
return false;
// Upgrade to write access.
blockRef.UpgradeOpen();
// store the current block position/scale/tranform/attributes
Point3d position = blockRef.Position;
Scale3d scaleFactors = blockRef.ScaleFactors;
Matrix3d tranformMatrix = blockRef.BlockTransform;
Dictionary<string, string> attributeDataDict = CadUtils.ExtractBlockAttributedata(transaction, blockRef);
// MAPPING CODE
RemapAttribute(attributeDataDict, "MATL", "MATERIAL");
RemapAttribute(attributeDataDict, "REV", "REV.");
RemapAttribute(attributeDataDict, "HEAT", "HEAT_TREATMENT");
RemapAttribute(attributeDataDict, "SPECS", "SPECIFICATIONS");
RemapAttribute(attributeDataDict, "DSGN", "DSG/INT");
RemapAttribute(attributeDataDict, "NOTES", "DRAWING_TYPE");
RemapAttribute(attributeDataDict, "DWG_TITLE", "DRAWING_DESCRIPTION");
RemapAttribute(attributeDataDict, "EFC", "EFC No.");
if (attributeDataDict.ContainsKey("XXX-000000-00000"))
RemapAttribute(attributeDataDict, "XXX-000000-00000", "DWG_NO");
// Hard rule. Check rev and make it 0 if its blank or -
if (attributeDataDict.ContainsKey("REV."))
{
string rev = attributeDataDict["REV."].Trim();
if (rev == "" || rev == "-")
attributeDataDict["REV."] = "0";
}
blockRef.Erase();
ObjectId btrId = CadUtils.LoadBlockFromFile(transaction, db, titleBlocksPath + "\\" + replacementBlockName, (replacementBlockName.Replace(".dwg", "")).Replace("_","")); // Replace "_" added by TJR
BlockReference newBtr = new BlockReference(position, btrId);
using (BlockTableRecord space = (BlockTableRecord)transaction.GetObject(ownerId, OpenMode.ForWrite))
{
space.AppendEntity(newBtr);
transaction.AddNewlyCreatedDBObject(newBtr, true);
newBtr.Position = position; // Added by TJR 07/07/2018 ####
newBtr.ScaleFactors = scaleFactors;
newBtr.BlockTransform = tranformMatrix;
CadUtils.CopyAttributesToBlock(db, transaction, newBtr, attributeDataDict);
}
return true;
}
return false;
}
}
Solved! Go to Solution.