<?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 creating blocks in vba in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/creating-blocks-in-vba/m-p/2594020#M14461</link>
    <description>First some background.&lt;BR /&gt;
I have a vba project in which the user is asked to pick points on the screen and when done a userform opens from which the user selects options from combo/textboxes etc. these values are then passed across and a block is created and then inserted on the drawing. There may be many many instances required on the drawing which when extracted to excel create a bill of materials. This all works fine xcept i have needed to add a further attribute to the block which on new drawings all works fine but when the macro is used on a drawing which has the existing block in it it fails to create all the attributes  although the block is inserted with blank attribute values in the block. Is there some way this can be overcome. I am new to vba and most of what i have done is through trial and error and with help from the discussion group members.&lt;BR /&gt;
&lt;BR /&gt;
i do appreciate the help in the past and thank to all who take the time to help&lt;BR /&gt;
johnb&lt;BR /&gt;
&lt;BR /&gt;
below is the code from the create block section&lt;BR /&gt;
&lt;BR /&gt;
Private Sub btnAddTendon_Click()&lt;BR /&gt;
    Dim objBlockDefinition As AcadBlock&lt;BR /&gt;
    Dim objBlockReference As AcadBlockReference&lt;BR /&gt;
    Dim varAttributes As Variant&lt;BR /&gt;
    Dim blnBlockExists As Boolean&lt;BR /&gt;
    Dim varInsertionPoint As Variant&lt;BR /&gt;
    Dim intIndex As Integer&lt;BR /&gt;
    Dim txtTotStrandLength As Variant&lt;BR /&gt;
    Dim txtTendonTonnage As Variant&lt;BR /&gt;
    Dim PI As Double&lt;BR /&gt;
    PI = Atn(1) * 4&lt;BR /&gt;
    &lt;BR /&gt;
    If FormDataIsValid Then&lt;BR /&gt;
        Me.Hide&lt;BR /&gt;
    &lt;BR /&gt;
        ' Create the tendon block definition if it doesn't already exist.&lt;BR /&gt;
        blnBlockExists = False&lt;BR /&gt;
        For Each objBlockDefinition In ThisDrawing.Blocks&lt;BR /&gt;
            If objBlockDefinition.Name = TENDON_BLOCK_NAME Then&lt;BR /&gt;
                blnBlockExists = True&lt;BR /&gt;
                Exit For&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next objBlockDefinition&lt;BR /&gt;
    &lt;BR /&gt;
        If Not blnBlockExists Then&lt;BR /&gt;
            CreateTendonBlock&lt;BR /&gt;
        End If&lt;BR /&gt;
       &lt;BR /&gt;
'insert an instance of the tendon block in modelspace.&lt;BR /&gt;
'select points for block rotation:&lt;BR /&gt;
Dim Pt As Variant&lt;BR /&gt;
&lt;BR /&gt;
Dim PtSel(0 To 2) As Double&lt;BR /&gt;
Dim Bl_RotationAngle As Double&lt;BR /&gt;
Dim ipang As Double&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
varInsertionPoint = ThisDrawing.Utility.GetPoint(, "select insertion point:")&lt;BR /&gt;
Bl_RotationAngle = ThisDrawing.Utility.GetAngle(varInsertionPoint, "select point on tendon: ")&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 ' You will see a rubber band from Pt to the cursor location.&lt;BR /&gt;
&lt;BR /&gt;
' Set values of a point from the returned variant&lt;BR /&gt;
PtSel(0) = varInsertionPoint(0)&lt;BR /&gt;
PtSel(1) = varInsertionPoint(1)&lt;BR /&gt;
Dim LayerObj As AcadLayer&lt;BR /&gt;
Set LayerObj = ThisDrawing.Layers.Add("TendonID")&lt;BR /&gt;
&lt;BR /&gt;
If Bl_RotationAngle &amp;gt; (PI / 2) Then&lt;BR /&gt;
   ipang = Bl_RotationAngle + PI&lt;BR /&gt;
End If&lt;BR /&gt;
If Bl_RotationAngle &amp;lt; (1.5 * PI) Then&lt;BR /&gt;
   ipang = Bl_RotationAngle + PI&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ThisDrawing.ActiveLayer = ThisDrawing.Layers("TendonID") 'objBlockDefinition.Layer = "TendonId"&lt;BR /&gt;
        &lt;BR /&gt;
        Set objBlockReference = ThisDrawing.ModelSpace.InsertBlock(varInsertionPoint, _&lt;BR /&gt;
            TENDON_BLOCK_NAME, 1#, 1#, 1#, Bl_RotationAngle + (PI / 2#))&lt;BR /&gt;
' Update the block ref's attributes.&lt;BR /&gt;
        varAttributes = objBlockReference.GetAttributes&lt;BR /&gt;
        For intIndex = LBound(varAttributes) To UBound(varAttributes)&lt;BR /&gt;
            Select Case varAttributes(intIndex).TagString&lt;BR /&gt;
                                Case "Pour Number"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = TxtPourNumber.Text&lt;BR /&gt;
                Case "ID"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtTendonID.Text&lt;BR /&gt;
                    varAttributes(intIndex).Rotation = 0#&lt;BR /&gt;
                Case "Strand Type"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = cboStrandType.Text&lt;BR /&gt;
                Case "No. Strands"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = cboNumberStrands.Text&lt;BR /&gt;
                    varAttributes(intIndex).Rotation = ipang '+ PI ' / 2  '-1#)&lt;BR /&gt;
                Case "Duct Length"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtDuctLength.Text&lt;BR /&gt;
                Case "Tendon Length"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtTendonLength.Text&lt;BR /&gt;
                Case "TotStrandLength"&lt;BR /&gt;
                   varAttributes(intIndex).TextString = getTotalStrandLength(txtTendonLength.Text, cboNumberStrands.Text)&lt;BR /&gt;
                Case "CASTING1"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtcastingle1.Text&lt;BR /&gt;
                Case "ANCHOR1"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtanchorblockle1.Text&lt;BR /&gt;
                Case "CASTING2"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtcastingle2.Text&lt;BR /&gt;
                Case "ANCHOR2"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtanchorblockle2.Text&lt;BR /&gt;
                Case "COUPLER"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtCouplingLE.Text&lt;BR /&gt;
                Case "1stend"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Cbofirstend.Text&lt;BR /&gt;
                Case "2ndend"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Cbosecondend.Text&lt;BR /&gt;
                Case "Tendon Tonnes"&lt;BR /&gt;
                varAttributes(intIndex).TextString = Format(tonnage, "#.###")&lt;BR /&gt;
                Case "Duct Size"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtductsize.Text&lt;BR /&gt;
                                        &lt;BR /&gt;
                    &lt;BR /&gt;
                    End Select&lt;BR /&gt;
                    &lt;BR /&gt;
                    &lt;BR /&gt;
        Next intIndex&lt;BR /&gt;
        Unload Me&lt;BR /&gt;
    End If&lt;BR /&gt;
End Sub</description>
    <pubDate>Tue, 24 Nov 2009 10:05:40 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-11-24T10:05:40Z</dc:date>
    <item>
      <title>creating blocks in vba</title>
      <link>https://forums.autodesk.com/t5/vba-forum/creating-blocks-in-vba/m-p/2594020#M14461</link>
      <description>First some background.&lt;BR /&gt;
I have a vba project in which the user is asked to pick points on the screen and when done a userform opens from which the user selects options from combo/textboxes etc. these values are then passed across and a block is created and then inserted on the drawing. There may be many many instances required on the drawing which when extracted to excel create a bill of materials. This all works fine xcept i have needed to add a further attribute to the block which on new drawings all works fine but when the macro is used on a drawing which has the existing block in it it fails to create all the attributes  although the block is inserted with blank attribute values in the block. Is there some way this can be overcome. I am new to vba and most of what i have done is through trial and error and with help from the discussion group members.&lt;BR /&gt;
&lt;BR /&gt;
i do appreciate the help in the past and thank to all who take the time to help&lt;BR /&gt;
johnb&lt;BR /&gt;
&lt;BR /&gt;
below is the code from the create block section&lt;BR /&gt;
&lt;BR /&gt;
Private Sub btnAddTendon_Click()&lt;BR /&gt;
    Dim objBlockDefinition As AcadBlock&lt;BR /&gt;
    Dim objBlockReference As AcadBlockReference&lt;BR /&gt;
    Dim varAttributes As Variant&lt;BR /&gt;
    Dim blnBlockExists As Boolean&lt;BR /&gt;
    Dim varInsertionPoint As Variant&lt;BR /&gt;
    Dim intIndex As Integer&lt;BR /&gt;
    Dim txtTotStrandLength As Variant&lt;BR /&gt;
    Dim txtTendonTonnage As Variant&lt;BR /&gt;
    Dim PI As Double&lt;BR /&gt;
    PI = Atn(1) * 4&lt;BR /&gt;
    &lt;BR /&gt;
    If FormDataIsValid Then&lt;BR /&gt;
        Me.Hide&lt;BR /&gt;
    &lt;BR /&gt;
        ' Create the tendon block definition if it doesn't already exist.&lt;BR /&gt;
        blnBlockExists = False&lt;BR /&gt;
        For Each objBlockDefinition In ThisDrawing.Blocks&lt;BR /&gt;
            If objBlockDefinition.Name = TENDON_BLOCK_NAME Then&lt;BR /&gt;
                blnBlockExists = True&lt;BR /&gt;
                Exit For&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next objBlockDefinition&lt;BR /&gt;
    &lt;BR /&gt;
        If Not blnBlockExists Then&lt;BR /&gt;
            CreateTendonBlock&lt;BR /&gt;
        End If&lt;BR /&gt;
       &lt;BR /&gt;
'insert an instance of the tendon block in modelspace.&lt;BR /&gt;
'select points for block rotation:&lt;BR /&gt;
Dim Pt As Variant&lt;BR /&gt;
&lt;BR /&gt;
Dim PtSel(0 To 2) As Double&lt;BR /&gt;
Dim Bl_RotationAngle As Double&lt;BR /&gt;
Dim ipang As Double&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
varInsertionPoint = ThisDrawing.Utility.GetPoint(, "select insertion point:")&lt;BR /&gt;
Bl_RotationAngle = ThisDrawing.Utility.GetAngle(varInsertionPoint, "select point on tendon: ")&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 ' You will see a rubber band from Pt to the cursor location.&lt;BR /&gt;
&lt;BR /&gt;
' Set values of a point from the returned variant&lt;BR /&gt;
PtSel(0) = varInsertionPoint(0)&lt;BR /&gt;
PtSel(1) = varInsertionPoint(1)&lt;BR /&gt;
Dim LayerObj As AcadLayer&lt;BR /&gt;
Set LayerObj = ThisDrawing.Layers.Add("TendonID")&lt;BR /&gt;
&lt;BR /&gt;
If Bl_RotationAngle &amp;gt; (PI / 2) Then&lt;BR /&gt;
   ipang = Bl_RotationAngle + PI&lt;BR /&gt;
End If&lt;BR /&gt;
If Bl_RotationAngle &amp;lt; (1.5 * PI) Then&lt;BR /&gt;
   ipang = Bl_RotationAngle + PI&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ThisDrawing.ActiveLayer = ThisDrawing.Layers("TendonID") 'objBlockDefinition.Layer = "TendonId"&lt;BR /&gt;
        &lt;BR /&gt;
        Set objBlockReference = ThisDrawing.ModelSpace.InsertBlock(varInsertionPoint, _&lt;BR /&gt;
            TENDON_BLOCK_NAME, 1#, 1#, 1#, Bl_RotationAngle + (PI / 2#))&lt;BR /&gt;
' Update the block ref's attributes.&lt;BR /&gt;
        varAttributes = objBlockReference.GetAttributes&lt;BR /&gt;
        For intIndex = LBound(varAttributes) To UBound(varAttributes)&lt;BR /&gt;
            Select Case varAttributes(intIndex).TagString&lt;BR /&gt;
                                Case "Pour Number"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = TxtPourNumber.Text&lt;BR /&gt;
                Case "ID"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtTendonID.Text&lt;BR /&gt;
                    varAttributes(intIndex).Rotation = 0#&lt;BR /&gt;
                Case "Strand Type"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = cboStrandType.Text&lt;BR /&gt;
                Case "No. Strands"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = cboNumberStrands.Text&lt;BR /&gt;
                    varAttributes(intIndex).Rotation = ipang '+ PI ' / 2  '-1#)&lt;BR /&gt;
                Case "Duct Length"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtDuctLength.Text&lt;BR /&gt;
                Case "Tendon Length"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtTendonLength.Text&lt;BR /&gt;
                Case "TotStrandLength"&lt;BR /&gt;
                   varAttributes(intIndex).TextString = getTotalStrandLength(txtTendonLength.Text, cboNumberStrands.Text)&lt;BR /&gt;
                Case "CASTING1"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtcastingle1.Text&lt;BR /&gt;
                Case "ANCHOR1"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtanchorblockle1.Text&lt;BR /&gt;
                Case "CASTING2"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtcastingle2.Text&lt;BR /&gt;
                Case "ANCHOR2"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtanchorblockle2.Text&lt;BR /&gt;
                Case "COUPLER"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = txtCouplingLE.Text&lt;BR /&gt;
                Case "1stend"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Cbofirstend.Text&lt;BR /&gt;
                Case "2ndend"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Cbosecondend.Text&lt;BR /&gt;
                Case "Tendon Tonnes"&lt;BR /&gt;
                varAttributes(intIndex).TextString = Format(tonnage, "#.###")&lt;BR /&gt;
                Case "Duct Size"&lt;BR /&gt;
                    varAttributes(intIndex).TextString = Txtductsize.Text&lt;BR /&gt;
                                        &lt;BR /&gt;
                    &lt;BR /&gt;
                    End Select&lt;BR /&gt;
                    &lt;BR /&gt;
                    &lt;BR /&gt;
        Next intIndex&lt;BR /&gt;
        Unload Me&lt;BR /&gt;
    End If&lt;BR /&gt;
End Sub</description>
      <pubDate>Tue, 24 Nov 2009 10:05:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/creating-blocks-in-vba/m-p/2594020#M14461</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-24T10:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: creating blocks in vba</title>
      <link>https://forums.autodesk.com/t5/vba-forum/creating-blocks-in-vba/m-p/2594021#M14462</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
The code you gave seems to be ok, the pb should be in you "CreateTendonBlock" or the code where you add the Attribute definition in the existing block:&lt;BR /&gt;
&lt;BR /&gt;
This works for me :&lt;BR /&gt;
&lt;BR /&gt;
Dim oAcadBlockRef As AcadBlockReference&lt;BR /&gt;
Dim oAcadBlockDef As AcadBlock&lt;BR /&gt;
Dim oAttribDef As AcadAttribute&lt;BR /&gt;
&lt;BR /&gt;
'Get the existing block definition&lt;BR /&gt;
Set oAcadBlockDef = ThisDrawing.Blocks(oAcadBlockRef.Name)&lt;BR /&gt;
'Add the attribute...&lt;BR /&gt;
Set oAttrib = oAcadBlockDef.AddAttribute(4, acAttributeModeNormal, "Message :", InsPoint, "TAG", "Value")&lt;BR /&gt;
'Update the block reference&lt;BR /&gt;
oAcadBlockRef.Update&lt;BR /&gt;
&lt;BR /&gt;
Enjoy.</description>
      <pubDate>Wed, 25 Nov 2009 19:03:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/creating-blocks-in-vba/m-p/2594021#M14462</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-25T19:03:56Z</dc:date>
    </item>
  </channel>
</rss>

