Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I'm here to answer my questions. Hope everybody help please
when i insert a block into autocad drawing. I have a custom edit, it changes the position of position. I have repositioned the block but an error has appeared. attributes do not automatically move by block
below is my image and code
this is when i insert
this is the result i want.
sample my code: I was able to handle it with ed.Command("ATTSYNC", "Name", blockNameInsert); this is probably a bad idea.
#region Insert block WallVertDowelType3
// Create a new block reference and add it to the current space
using (BlockReference br_Insert = new BlockReference(geoPosition, blockTable[blockNameInsert]))
{
br_Insert.Layer = genLayer;
br_Insert.ScaleFactors = getScale;
br_Insert.Rotation = misRotation;
// insert block WallVertDowelType3 vào CurrentSpaceId
BlockTableRecord btrCurrentSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btrCurrentSpace.AppendEntity(br_Insert);
tr.AddNewlyCreatedDBObject(br_Insert, true);
#region Set Attribute[] of Block Reference | if (btr.HasAttributeDefinitions)
BlockTableRecord blockInsert = tr.GetObject(blockTable[blockNameInsert], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId oid_ATB in blockInsert)
{
DBObject dBObject = tr.GetObject(oid_ATB, OpenMode.ForRead);
if (dBObject is AttributeDefinition)
{
AttributeReference attRef = new AttributeReference();
// Add the attribute to the block reference
AttributeDefinition attDef = dBObject as AttributeDefinition;
attRef.SetAttributeFromBlock(attDef, br_Insert.BlockTransform);
//attRef.Position = attDef.Position.TransformBy(br_Insert.BlockTransform);
double temp_DIA = DIA.Contains("D") ? Convert.ToDouble(DIA.Split('D')[1]) : Convert.ToDouble(DIA);
switch (attRef.Tag)
{
case "xxx": attRef.TextString = "xxx"; break;
}
// Add attribute to block reference
br_Insert.AttributeCollection.AppendAttribute(attRef);
tr.AddNewlyCreatedDBObject(attRef, true);
}
}
#endregion
#region Set Custom[] of Block Reference Dynamic | if (bref.IsDynamicBlock)
DynamicBlockReferencePropertyCollection DBRPCollection = br_Insert.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty DBRProperty in DBRPCollection)
{
switch (DBRProperty.PropertyName)
{
case "xxx": DBRProperty.Value = canhB; break;
}
}
br_Insert.Position = geoPosition; // error generated attribute is not in the correct position. Temporarily fixed with `ATTSYNC`
#endregion
}
#endregion
ed.Command("ATTSYNC", "Name", blockNameInsert); //still usable but not optimal in terms of performance. i need another way
Solved! Go to Solution.