Author Topic: Civil 3D add block to point lable style  (Read 1715 times)

0 Members and 2 Guests are viewing this topic.

sdunn

  • Newt
  • Posts: 90
Civil 3D add block to point lable style
« on: February 26, 2018, 02:32:48 PM »
I am trying to add a block component to a point label style.  I haven't figured out how to assign the block name once the component is created.  The only thing I can find is component.Block.BlockName.Value.  Is this possible or am I missing something simple?

Code: [Select]
        Private Sub addBlockComponent(ByVal style As LabelStyle, ByRef blknam As String, blkht As Double)
            Dim id As ObjectId = style.AddComponent("Block", LabelStyleComponentType.Block)
            Dim component As LabelStyleBlockComponent = TryCast(id.GetObject(OpenMode.ForWrite), LabelStyleBlockComponent)

            component.Block.BlockName.Value = blknam
            component.Block.Attachment.Value = BlockAttachmentType.MiddleCenter
            component.Block.BlockHeight.Value = blkht
            component.Block.RotationAngle.Value = 0

        End Sub

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Civil 3D add block to point lable style
« Reply #1 on: February 26, 2018, 05:53:02 PM »
In C3D 2018 the BlockName.Value property is get/set so you can assign the block to use. However, the Height and rotation values are get only. I've found that the docs say all of the Block. properties are get only, but the BlockName, Attachment, XOffset, & YOffset are all get/set. The following c# code works for me:

Code - C#: [Select]
  1.         [CommandMethod("testsetting")]
  2.         public void testsetting()
  3.         {
  4.             CivilDocument civdoc = (CivilDocument)CivilApplication.ActiveDocument;
  5.             using (AcDb.Transaction tr = AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  6.             {
  7.                 LabelStyle labelStyle = (LabelStyle)tr.GetObject(civdoc.Styles.LabelStyles.PointLabelStyles.LabelStyles[0], AcDb.OpenMode.ForWrite);
  8.                 var compId = labelStyle.AddComponent("TheBlock", LabelStyleComponentType.Block);
  9.                 var comp = (LabelStyleBlockComponent)tr.GetObject(compId, AcDb.OpenMode.ForWrite);
  10.                 comp.Block.BlockName.Value = "bound"; //must exist in the drawing
  11.                 comp.Block.Attachment.Value = Autodesk.Civil.BlockAttachmentType.MiddleCenter;
  12.                 comp.Block.XOffset.Value = (.1/12);
  13.                 comp.Block.YOffset.Value = (.1/12);
  14.                 tr.Commit();
  15.             }
  16.         }
  17.  

sdunn

  • Newt
  • Posts: 90
Re: Civil 3D add block to point lable style
« Reply #2 on: February 27, 2018, 11:46:49 AM »
Thank you Jeff!