<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic multiline text to attribute in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/multiline-text-to-attribute/m-p/12442748#M6224</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;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 &amp;amp;&amp;amp; bt.IsWriteEnabled &amp;amp;&amp;amp; 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();

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;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&lt;BR /&gt;&lt;BR /&gt;here rowBlock is blocktable record and bt is blocktable how to add multiine text to attributedefination value in attribute&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2023 18:44:34 GMT</pubDate>
    <dc:creator>abhijit_patilJ9KUT</dc:creator>
    <dc:date>2023-12-15T18:44:34Z</dc:date>
    <item>
      <title>multiline text to attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiline-text-to-attribute/m-p/12442748#M6224</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;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 &amp;amp;&amp;amp; bt.IsWriteEnabled &amp;amp;&amp;amp; 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();

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;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&lt;BR /&gt;&lt;BR /&gt;here rowBlock is blocktable record and bt is blocktable how to add multiine text to attributedefination value in attribute&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 18:44:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiline-text-to-attribute/m-p/12442748#M6224</guid>
      <dc:creator>abhijit_patilJ9KUT</dc:creator>
      <dc:date>2023-12-15T18:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: multiline text to attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiline-text-to-attribute/m-p/12444276#M6225</link>
      <description>&lt;P&gt;Firstly, this forum is for ObjectRAX C++, while your question is .NET API topic, thus you should post&lt;A href="https://forums.autodesk.com/t5/net/bd-p/152" target="_blank" rel="noopener"&gt; here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, please use the "&amp;lt;/&amp;gt;" button to post code, so that the code shows more readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for your code:&lt;/P&gt;
&lt;P&gt;You did not show the code how the block definition (rowBlock) is created. More importantly, after the code of creating new attribute definition (attDef), there is no code to add it to the block definition (e.g. you should have this line after the addDef is created: rowBlock.AppendEntity(attDef), followed by adding attDef to the Transaction). That is, your code may have created a entity (Attribute Definition) in memory orphaned (not residing in database, nor disposed). This could be the reason for the crash when saving the drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 18:36:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiline-text-to-attribute/m-p/12444276#M6225</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-12-15T18:36:23Z</dc:date>
    </item>
  </channel>
</rss>

