<?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 After adding BlockRefernce there are not attributes to edit in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/after-adding-blockrefernce-there-are-not-attributes-to-edit/m-p/2618634#M67476</link>
    <description>In a drawing I have a block with editable attributes.&lt;BR /&gt;
the following code adds it to any layout required.&lt;BR /&gt;
&lt;BR /&gt;
private static void ProcessSpaceForRevBlockAttributeUpdate(Layout acLayout, Transaction acTrans, string blockName, List&lt;ACADINTERFACE.ATTRIBUTE&gt; attributes)&lt;BR /&gt;
        {&lt;BR /&gt;
&lt;BR /&gt;
            BlockTable acBlkTbl = acTrans.GetObject(acLayout.Database.BlockTableId,&lt;BR /&gt;
                                             OpenMode.ForRead) as BlockTable;&lt;BR /&gt;
&lt;BR /&gt;
            BlockTableRecord acLayoutBlkTblRec = acTrans.GetObject(acLayout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;&lt;BR /&gt;
&lt;BR /&gt;
            //Get any offset values from Configuration.&lt;BR /&gt;
            double yValue = 0;&lt;BR /&gt;
            double initialOffset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "initialOffset"));&lt;BR /&gt;
            double offset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "offset")); ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            foreach (ObjectId acObjId in acLayoutBlkTblRec)&lt;BR /&gt;
            {&lt;BR /&gt;
                DBObject acObject = acTrans.GetObject(acObjId, OpenMode.ForWrite);&lt;BR /&gt;
&lt;BR /&gt;
                //get the highest of the existing blocks&lt;BR /&gt;
&lt;BR /&gt;
                if (acObject.GetType().ToString() == "Autodesk.AutoCAD.DatabaseServices.BlockReference")&lt;BR /&gt;
                {&lt;BR /&gt;
                    BlockReference acBlockRef = acObject as BlockReference;&lt;BR /&gt;
                    if (acBlockRef.Name == blockName)&lt;BR /&gt;
                        if (acBlockRef.Position.Y &amp;gt; yValue) yValue = acBlockRef.Position.Y;&lt;BR /&gt;
                }&lt;BR /&gt;
&lt;BR /&gt;
            }&lt;BR /&gt;
            //if no current blocks, get a new insertion&lt;BR /&gt;
            if (yValue == 0) yValue = initialOffset;&lt;BR /&gt;
            //increment for new block&lt;BR /&gt;
            yValue = yValue + offset;&lt;BR /&gt;
&lt;BR /&gt;
            //Get a point for insertion&lt;BR /&gt;
            Autodesk.AutoCAD.Geometry.Point3d p3d = new Autodesk.AutoCAD.Geometry.Point3d(0, yValue, 0);&lt;BR /&gt;
            BlockReference acRevBlockRef = new BlockReference(p3d, acBlkTbl[blockName]);&lt;BR /&gt;
&lt;BR /&gt;
            acRevBlockRef.ScaleFactors = new Autodesk.AutoCAD.Geometry.Scale3d(1);&lt;BR /&gt;
            acRevBlockRef.SetDatabaseDefaults();&lt;BR /&gt;
           &lt;BR /&gt;
            acLayoutBlkTblRec.AppendEntity(acRevBlockRef);&lt;BR /&gt;
            acTrans.AddNewlyCreatedDBObject(acRevBlockRef, true);&lt;BR /&gt;
&lt;BR /&gt;
            AttributeCollection attColl = acRevBlockRef.AttributeCollection;&lt;BR /&gt;
            foreach (ObjectId attObjectId in attColl)&lt;BR /&gt;
            {&lt;BR /&gt;
                AttributeReference attRef = (AttributeReference)acTrans.GetObject(attObjectId, OpenMode.ForWrite);&lt;BR /&gt;
                foreach (ACADInterface.Attribute at in attributes)&lt;BR /&gt;
                    if (at.Name == attRef.Tag)&lt;BR /&gt;
                        attRef.TextString = at.Value;&lt;BR /&gt;
            }&lt;BR /&gt;
            return;&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
The block does get added to all layouts and model space, but in the code it doesnt find any attributes.&lt;BR /&gt;
And in Autocad if I try attedit on the block, it also has not editable attributes.&lt;BR /&gt;
But if I add the block in Acad via Insert, attributes edit fine, so I'm reasonably certian its not an issue with the block definition.&lt;BR /&gt;
I think its something pretty simple I'm missing, but cant see it.&lt;/ACADINTERFACE.ATTRIBUTE&gt;</description>
    <pubDate>Tue, 19 Jan 2010 03:47:39 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-01-19T03:47:39Z</dc:date>
    <item>
      <title>After adding BlockRefernce there are not attributes to edit</title>
      <link>https://forums.autodesk.com/t5/net-forum/after-adding-blockrefernce-there-are-not-attributes-to-edit/m-p/2618634#M67476</link>
      <description>In a drawing I have a block with editable attributes.&lt;BR /&gt;
the following code adds it to any layout required.&lt;BR /&gt;
&lt;BR /&gt;
private static void ProcessSpaceForRevBlockAttributeUpdate(Layout acLayout, Transaction acTrans, string blockName, List&lt;ACADINTERFACE.ATTRIBUTE&gt; attributes)&lt;BR /&gt;
        {&lt;BR /&gt;
&lt;BR /&gt;
            BlockTable acBlkTbl = acTrans.GetObject(acLayout.Database.BlockTableId,&lt;BR /&gt;
                                             OpenMode.ForRead) as BlockTable;&lt;BR /&gt;
&lt;BR /&gt;
            BlockTableRecord acLayoutBlkTblRec = acTrans.GetObject(acLayout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;&lt;BR /&gt;
&lt;BR /&gt;
            //Get any offset values from Configuration.&lt;BR /&gt;
            double yValue = 0;&lt;BR /&gt;
            double initialOffset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "initialOffset"));&lt;BR /&gt;
            double offset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "offset")); ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            foreach (ObjectId acObjId in acLayoutBlkTblRec)&lt;BR /&gt;
            {&lt;BR /&gt;
                DBObject acObject = acTrans.GetObject(acObjId, OpenMode.ForWrite);&lt;BR /&gt;
&lt;BR /&gt;
                //get the highest of the existing blocks&lt;BR /&gt;
&lt;BR /&gt;
                if (acObject.GetType().ToString() == "Autodesk.AutoCAD.DatabaseServices.BlockReference")&lt;BR /&gt;
                {&lt;BR /&gt;
                    BlockReference acBlockRef = acObject as BlockReference;&lt;BR /&gt;
                    if (acBlockRef.Name == blockName)&lt;BR /&gt;
                        if (acBlockRef.Position.Y &amp;gt; yValue) yValue = acBlockRef.Position.Y;&lt;BR /&gt;
                }&lt;BR /&gt;
&lt;BR /&gt;
            }&lt;BR /&gt;
            //if no current blocks, get a new insertion&lt;BR /&gt;
            if (yValue == 0) yValue = initialOffset;&lt;BR /&gt;
            //increment for new block&lt;BR /&gt;
            yValue = yValue + offset;&lt;BR /&gt;
&lt;BR /&gt;
            //Get a point for insertion&lt;BR /&gt;
            Autodesk.AutoCAD.Geometry.Point3d p3d = new Autodesk.AutoCAD.Geometry.Point3d(0, yValue, 0);&lt;BR /&gt;
            BlockReference acRevBlockRef = new BlockReference(p3d, acBlkTbl[blockName]);&lt;BR /&gt;
&lt;BR /&gt;
            acRevBlockRef.ScaleFactors = new Autodesk.AutoCAD.Geometry.Scale3d(1);&lt;BR /&gt;
            acRevBlockRef.SetDatabaseDefaults();&lt;BR /&gt;
           &lt;BR /&gt;
            acLayoutBlkTblRec.AppendEntity(acRevBlockRef);&lt;BR /&gt;
            acTrans.AddNewlyCreatedDBObject(acRevBlockRef, true);&lt;BR /&gt;
&lt;BR /&gt;
            AttributeCollection attColl = acRevBlockRef.AttributeCollection;&lt;BR /&gt;
            foreach (ObjectId attObjectId in attColl)&lt;BR /&gt;
            {&lt;BR /&gt;
                AttributeReference attRef = (AttributeReference)acTrans.GetObject(attObjectId, OpenMode.ForWrite);&lt;BR /&gt;
                foreach (ACADInterface.Attribute at in attributes)&lt;BR /&gt;
                    if (at.Name == attRef.Tag)&lt;BR /&gt;
                        attRef.TextString = at.Value;&lt;BR /&gt;
            }&lt;BR /&gt;
            return;&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
The block does get added to all layouts and model space, but in the code it doesnt find any attributes.&lt;BR /&gt;
And in Autocad if I try attedit on the block, it also has not editable attributes.&lt;BR /&gt;
But if I add the block in Acad via Insert, attributes edit fine, so I'm reasonably certian its not an issue with the block definition.&lt;BR /&gt;
I think its something pretty simple I'm missing, but cant see it.&lt;/ACADINTERFACE.ATTRIBUTE&gt;</description>
      <pubDate>Tue, 19 Jan 2010 03:47:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/after-adding-blockrefernce-there-are-not-attributes-to-edit/m-p/2618634#M67476</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-19T03:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: After adding BlockRefernce there are not attributes to edit</title>
      <link>https://forums.autodesk.com/t5/net-forum/after-adding-blockrefernce-there-are-not-attributes-to-edit/m-p/2618635#M67477</link>
      <description>Unlike Acad COM API's counterpart (ModelSpace.InsertBlock()), which when inserting an Acadblockreference, it also inserts AcadAttributeReference according to the AcadBlock definition, in .NET API, you create a BlockRefernce based on a BlockTableRecord (as you did correctly), but the AttributeReferences are not automatically created in the BlockRefernce according to the BlockTableRecord. You need to create the AttributeReferences and append them into the BlockReference's AttributeCollection. That is, even a block definition defines a set of attributes, a block reference based on a block definition may or may not have all the attribute references corresponding to the attribute definition, depending on whether your code creates them or not.&lt;BR /&gt;
&lt;BR /&gt;
Here is some quick psuedo code (not tested):&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
//Start a transaction here...&lt;BR /&gt;
//Create your new blockreference and add to database as you needed&lt;BR /&gt;
BlockReference bref=new BlockReference(pt,theBlockTableRecord);&lt;BR /&gt;
...&lt;BR /&gt;
if (theBlockTableRecord.HasAttributeDefinitions)&lt;BR /&gt;
{&lt;BR /&gt;
    foreach (ObjecyId id in theBlockTableRecord)&lt;BR /&gt;
    {&lt;BR /&gt;
        //Get the Entity in the block definition with the id&lt;BR /&gt;
        ....&lt;BR /&gt;
        //If the Entity is AttributeDefinition&lt;BR /&gt;
       if (ent is AttributeDefinition)&lt;BR /&gt;
       {&lt;BR /&gt;
            AttributeReference aref=new AttributeReference()&lt;BR /&gt;
            aref.SetAttributeFromBlock(theAttrDefinition,theBlockTableRecord.BlockTransform)&lt;BR /&gt;
            aref.TextString="XXXXXX"&lt;BR /&gt;
&lt;BR /&gt;
            //Add to the BlockReference&lt;BR /&gt;
            bref.AttributeCollection.AppendAttribute(aref)&lt;BR /&gt;
            tran.AddNewlyCreatedDBObject(aref,true)&lt;BR /&gt;
        }&lt;BR /&gt;
    }&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
Edited by: norman.yuan on Jan 19, 2010 3:08 PM&lt;BR /&gt;
&lt;BR /&gt;
Edited by: norman.yuan on Jan 19, 2010 3:09 PM

Edited by: norman.yuan on Jan 19, 2010 3:10 PM</description>
      <pubDate>Tue, 19 Jan 2010 15:07:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/after-adding-blockrefernce-there-are-not-attributes-to-edit/m-p/2618635#M67477</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2010-01-19T15:07:40Z</dc:date>
    </item>
  </channel>
</rss>

