Message 1 of 2
multiline text to attribute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
ObjectId styleId = db.Textstyle;
// Add an attribute to the block definition
AttributeDefinition attDef = new AttributeDefinition(attributeInsertionPoint, attributeValue, attributeName, attributeName, styleId);
attDef.Height = 2 * scale;
attDef.Position = attributeInsertionPoint;
attDef.HorizontalMode = TextHorizontalMode.TextCenter;
attDef.VerticalMode = TextVerticalMode.TextVerticalMid;
if (columnHeaderNames[count] == "REMARKS" || columnHeaderNames[count] == "DESCRIPTION")
{
attDef.IsMTextAttributeDefinition = true;
MText mText = new MText();
mText.SetDatabaseDefaults();
mText.Contents = attributeValue;
mText.TextHeight = 2 * scale;
mText.Location = attributeInsertionPoint;
mText.Width = 42 * scale; // Adjust width as needed
mText.Attachment = AttachmentPoint.MiddleCenter;
//rowBlock.AppendEntity(mText);
//ObjectId mTextId = rowBlock.AppendEntity(mText);
attDef.MTextAttributeDefinition = mText;
//mText.Dispose();
}
bt.UpgradeOpen();
//ObjectId rowBlockId = bt.Add(rowBlock);
ObjectId rowBlockId = ObjectId.Null;
try
{
if(bt != null && bt.IsWriteEnabled && rowBlock.IsWriteEnabled)
{
rowBlockId = bt.Add(rowBlock);
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
tr.AddNewlyCreatedDBObject(rowBlock, true);
// Insert the row block in the current space
BlockReference rowReference = new BlockReference(new Point3d(tableRecordInsertionPoint.X, distanceInY, 0), rowBlockId);
BlockTableRecord modelSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
modelSpace.AppendEntity(rowReference);
tr.AddNewlyCreatedDBObject(rowReference, true);
// Iterate through the row block and its attributes to add them to the row reference
var attributeCount = 0;
foreach (ObjectId objId in rowBlock)
{
DBObject obj = tr.GetObject(objId, OpenMode.ForRead) as DBObject;
if (obj is AttributeDefinition)
{
AttributeDefinition attDef = obj as AttributeDefinition;
if (!attDef.Constant)
{
// Create an AttributeReference based on the AttributeDefinition
AttributeReference attRef = new AttributeReference();
attRef.SetAttributeFromBlock(attDef, rowReference.BlockTransform);
// Set the attribute's position relative to the block reference
attRef.Position = attributeList[attributeCount];
attRef.AlignmentPoint = attributeList[attributeCount];
//// Add the attribute reference to the block reference
rowReference.AttributeCollection.AppendAttribute(attRef);
tr.AddNewlyCreatedDBObject(attRef, true);
attributeCount++;
}
}
}
tr.Commit();
here when i add attribute defination to attribute reference my drawing is created and multiline text is also visible but when i save drawing my autocad is crashing
here rowBlock is blocktable record and bt is blocktable how to add multiine text to attributedefination value in attribute