How to Update color of the square of lines, per block?

How to Update color of the square of lines, per block?

jlobo2
Advocate Advocate
471 Views
2 Replies
Message 1 of 3

How to Update color of the square of lines, per block?

jlobo2
Advocate
Advocate

So this is my code below:

 

using (transaction)
{
         // Get the block table from the drawing
         BlockTable blocktable = (BlockTable)transaction.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);

       if (!blocktable.Has(givenPANBLK))
      {
          // Create our new block table record...
           BlockTableRecord blocktablerecord = new BlockTableRecord();
          // ... and set its properties
          blocktablerecord.Name = givenPANBLK;

           // Set the insertion point for the block
          blocktablerecord.Origin = new Point3d(originPt.X, originPt.Y, originPt.Z);

          // Add some lines to the block to form a square  (the entities belong directly to the block)
           DBObjectCollection ents =
                       SquareOfLines(
                                       panelThickness, originPt,  givenLeftHeight, givenRightHeight);
          foreach (Entity ent in ents)
          { blocktablerecord.AppendEntity(ent); }

          
            foreach (Entity ent in entsREW)
            { blocktablerecord.AppendEntity(ent);}
   }

 

 

// Add an attribute definition to the block
// 
// PANEL NAME
//
{
       AttributeDefinition acAttDef = new AttributeDefinition();
       acAttDef.Position = new Point3d(originPt.X, originPt.Y, originPt.Z);
       acAttDef.Verifiable = true;
        acAttDef.Prompt = Constants.PANBLK_PROMPT_PANELNAME;
        acAttDef.Tag = Constants.PANBLK_TAG_PANELNAME;
         acAttDef.TextString = "A";
       acAttDef.Height = panelNameTextHeight;
         acAttDef.ColorIndex = 132;
         acAttDef.Layer = Constants.LAYER_PANNAME;
        acAttDef.Invisible = false;
          blocktablerecord.AppendEntity(acAttDef);
}
////
//// and many more Attribute definitions.

 

 

Now, How do I update the color of the lines per block? I need to update them only when they are selected.

 

Thank You for your help in advance.

0 Likes
Accepted solutions (1)
472 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

If you want to be able to change the color of entities in a block reference (BlockReference) without changing it in the other references, you have to set the Color property of these entities in the block definition (BlockTableRecord) to ByBlock so that they'll take the block reference Color. You can see this video.

 

The code you're showing* is related to the creation of a new block definition (BlockTableRecord). If you set the Color property of the entities you append to the block definition to ByBlock (ColorIndex = 1) you'll be able to handle the color of these entities in each reference you shall insert in the drawing.

 

*take care of adding the newly created entities to the transaction after having appending them to the block table record.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

jlobo2
Advocate
Advocate

Thank You for your response.

 

I agree with what you have said. I guess I am looking for How to access the entities of lines.

 

This is how, I am building the square block of lines.


    {
           Point3d[] pts = {
            new Point3d( givenRefPoint.X,  givenRefPoint.Y,  givenRefPoint.Z),
            new Point3d( givenRefPoint.X,  givenRefPoint.Y + givenLeftHeight, givenRefPoint.Z),
            new Point3d( givenRefPoint.X + givenWidthTop ,  givenRefPoint.Y + givenRightHeight, givenRefPoint.Z),
            new Point3d(givenRefPoint.X + givenWidthBase , givenRefPoint.Y + givenRightHeight, givenRefPoint.Z),
            new Point3d(givenRefPoint.X+ givenWidthBase,givenRefPoint.Y, givenRefPoint.Z)
    };
   

     int max = pts.GetUpperBound(0);

     for (int i = 0; i <= max; i++)
     {
           int j = (i == max ? 0 : i + 1);
           Line ln = new Line(pts[i], pts[j]);
           ln.Thickness = panelThickness;
           ln.Layer = Constants.LAYER_PANBLK; // I understand, I can change to one constant color.
           ents.Add(ln);
      }
}

 

I am looking for a way or resource, on how to access those line entities from the drawing?

Currently, I am accessing it from the BlockTableRecord, but it's changing the color for all the block references.

 

This is what I am currently using:

using (Transaction acTrans = dwgDb.TransactionManager.StartTransaction())
{
             // Access drawing block table
            pBlockTbl = acTrans.GetObject(dwgDb.BlockTableId, OpenMode.ForWrite) as BlockTable;
            // ------------------
           // ------------------
          foreach (ObjectId btrId in pBlockTbl)
          {
               BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(btrId, OpenMode.ForRead);
               if (!btr.IsLayout)
               {
                     foreach (ObjectId id in btr)
                     {
                           Entity ent = (Entity)acTrans.GetObject(thePANBLKBlockReference, OpenMode.ForWrite);
                           ent.Layer = Constants.LAYER_FINGRD;
                     }
               }
         }

}

 

Thank You for your help in advance.

0 Likes