Тема: Как добавить атрибут в блок?

Как добавить атрибут в блок?

Re: Как добавить атрибут в блок?

Смотреть Developer Help, метод AddAttribute.

ThisDrawing.Blocks.Item[...].AddAttribute

Re: Как добавить атрибут в блок?

Пример создания выноски с 2-я атрибутами
(форму frmVin1 моно заменить InputBox'ом)
  Dim P1, P2, Po As Variant
  Dim TxtVal As String
  Dim g As Integer
  Dim Bol As Byte
'********************Input points
  P1 = ThisDrawing.Utility.GetPoint(, "Укажите точку вставки")
  P2 = ThisDrawing.Utility.GetPoint(P1, "Укажите положение выноски")
  Po = ThisDrawing.Utility.GetPoint(P2, "Укажите ориентацию выноски")
Dim frmVin1 As New frmVin
'********************Using Dialog Forms
  frmVin1.Show
  If frmVin1.TB1.text = "Censel_Censel_Censel" Then Exit Sub
  If frmVin1.TB1.text = "" And frmVin1.TB2.text = "" Then Exit Sub
'********************Calc Number and set Block Name
  Dim sTemp As String
  Dim iTemp As Integer
  Dim iMax As Integer
  iMax = 1000
  For g = 0 To ThisDrawing.Blocks.Count - 1
      If Mid(ThisDrawing.Blocks.item(g).Name, 1, 7) = "Vinoska" _
      And VBA.Len(ThisDrawing.Blocks.item(g).Name) = 11 Then
        sTemp = Mid(ThisDrawing.Blocks.item(g).Name, 8, 4)
        iTemp = CInt(sTemp)
        If iTemp > iMax Then iMax = iTemp
      End If
  Next g
  Dim BlcName As String
  BlcName = "Vinoska" & iMax + 1
'********************Add Line
  Set L1 = ThisDrawing.ModelSpace.AddLine(P1, P2)
'********************Add Block
  Dim Blc As AcadBlock
  Set Blc = ThisDrawing.Blocks.Add(P2, BlcName)
'********************
  If Po(0) > P2(0) Then
    P3(0) = 1: P3(1) = 1: P3(2) = 0
    P4(0) = 1: P4(1) = -3.5: P4(2) = 0
  Else
    P3(0) = -1: P3(1) = 1: P3(2) = 0
    P4(0) = -1: P4(1) = -1: P4(2) = 0
  End If
'********************Add Attributes
  Dim Att As AcadAttribute
      If frmVin1.TB1.text <> "" Then
        Set Att = Blc.AddAttribute(2.5, acAttributeModeVerify, "Текст выноски2", P3, _
                  "TxtVin1", frmVin1.TB1.text)
      Else
        Set Att = Blc.AddAttribute(2.5, acAttributeModeVerify, "Текст выноски2", P3, _
                  "TxtVin1", " ")
      End If
      Att.ObliqueAngle = 15 * 3.14159265358979 / 180
      'Att.StyleName = "SIMPLEX"
      Att.ScaleFactor = 0.8
      Att.color = acByBlock
      Att.Lineweight = acLnWtByBlock
  Dim Att1 As AcadAttribute
      If frmVin1.TB2.text <> "" Then
        Set Att1 = Blc.AddAttribute(2.5, acAttributeModeVerify, "Текст выноски2", P4, _
                  "TxtVin2", frmVin1.TB2.text)
      Else
        Set Att1 = Blc.AddAttribute(2.5, acAttributeModeVerify, "Текст выноски2", P4, _
                  "TxtVin2", " ")
      End If
      Att1.ObliqueAngle = 15 * 3.14159265358979 / 180
      'Att1.StyleName = "SIMPLEX"
      Att1.ScaleFactor = 0.8
      Att1.color = acByBlock
      Att1.Lineweight = acLnWtByBlock
  If Po(0) > P2(0) Then
'    Att.Alignment = acAlignmentLeft
'    Att1.Alignment = acAlignmentLeft
  Else
    Att.Alignment = acAlignmentBottomRight
    Att.TextAlignmentPoint = P3
    Att1.Alignment = acAlignmentTopRight
    Att1.TextAlignmentPoint = P4
  End If
'********************Insert Block
  Dim BlcRef As AcadBlockReference
  Set BlcRef = ThisDrawing.ModelSpace.InsertBlock(P2, BlcName, 1#, 1#, 1#, 0)
'********************Calc Attributes Length
  Dim vAtt As Variant
  vAtt = BlcRef.GetAttributes
  Dim mE1 As Variant
  Dim nE1 As Variant
  vAtt(0).GetBoundingBox nE1, mE1
  Dim mE2 As Variant
  Dim nE2 As Variant
  vAtt(1).GetBoundingBox nE2, mE2
  If Po(0) > P2(0) Then
    If mE1(0) > mE2(0) Then
      xE = mE1(0) - nE1(0) + 2
    Else
      xE = mE2(0) - nE2(0) + 2
    End If
  Else
    If nE1(0) > nE2(0) Then
      xE = mE2(0) - nE2(0) + 2
    Else
      xE = mE1(0) - nE1(0) + 2
    End If
  End If
'********************
  If Po(0) > P2(0) Then
    P5(0) = P2(0) + xE: P5(1) = P2(1): P5(2) = P2(2)
  Else
    P5(0) = P2(0) - xE: P5(1) = P2(1): P5(2) = P2(2)
  End If
'********************Add Middle Line
  Dim LLL As AcadLine
  Set LLL = Blc.AddLine(P2, P5)
  LLL.color = acByBlock
  LLL.Lineweight = acLnWtByBlock

Re: Как добавить атрибут в блок?

Большое спасибо.