Hi
Parameter sind keine Attribute und umgekehrt- wie dem auch sei beide kann man getrennt auslesen oder setzen. Bei dynamischen Bloecken vergibt acad einen dynamischen Namen mit den bekannten sehr aussagekraeftigen *U ...
Um an den "richtigen" namen zu kommen muss man ".EffectiveName" verwenden.
Oder in simple du kannst parameter und attribute jederzeit getrennt setzen und auslesen
und an den urspruenglichen Blocknamen kommt man auch. Anbei ein paar Beispielroutinen welche funktionieren.
BTW Wenn du über die "001" stolpern solltest Autocad hatte scheints irgenwann einmal einen ziemlich ueblen bugfix der kurzerhand eigenmaechtig die dynamischen bloecke umbenannte (and die autodeskler coole nummer wirklich ...(*zensiert*))
Sub block_set_attribute(blo As AcadBlockReference, tagname, tagvalue)
Dim attlist As Variant
If blo Is Nothing Then Exit Sub
If blo.HasAttributes Then
tagname = Trim(UCase(tagname))
attlist = blo.GetAttributes
For I = LBound(attlist) To UBound(attlist)
''debug.print "#" & UCase(attlist(i).TagString) & "#", tagname
If UCase(attlist(I).TagString) = tagname Or UCase(Trim(attlist(I).TagString)) = tagname & "_001" Then
'On Error Resume Next
attlist(I).textstring = "" & tagvalue
' attlist(I).Update
' On Error GoTo 0
Exit Sub
End If
Next
End If
End Sub
Function block_has_attribute(blo As AcadBlockReference, tagname As String) As Boolean
Dim attlist As Variant
On Error Resume Next
block_has_attribute = False
If blo.HasAttributes Then
attlist = blo.GetAttributes
For I = LBound(attlist) To UBound(attlist)
If UCase(attlist(I).TagString) = tagname Or UCase(Trim(attlist(I).TagString)) = tagname & "_001" Then
block_has_attribute = True
Exit Function
End If
Next
End If
End Function
Function block_get_attribute(blo As AcadBlockReference, tagname) As String
Dim attlist As Variant
On Error Resume Next
'If blo Is Nothing Then Exit Function
If blo.HasAttributes Then
attlist = blo.GetAttributes
For I = LBound(attlist) To UBound(attlist)
If UCase(attlist(I).TagString) = tagname Or UCase(Trim(attlist(I).TagString)) = tagname & "_001" Then
block_get_attribute = attlist(I).textstring
Exit Function
End If
Next
End If
End Function
Function block_set_parameter(BlockRef As AcadBlockReference, ByVal NAME As String, Value As Variant) As Boolean
block_set_parameter = False
If BlockRef Is Nothing Then Exit Function
Dim DynProp As AcadDynamicBlockReferenceProperty
Dim Variable As Variant
NAME = UCase(NAME)
Variable = BlockRef.GetDynamicBlockProperties
For K = LBound(Variable) To UBound(Variable)
Set DynProp = Variable(K)
temp = UCase(DynProp.PropertyName)
'Check for variable and when found ask for input
If UCase(DynProp.PropertyName) = NAME Then
DynProp.Value = Value
block_set_parameter = True
Exit Function
End If
Next
End Function
Function block_has_parameter(BlockRef As AcadBlockReference, ByVal NAME As String) As Boolean
block_has_parameter = False
Dim DynProp As AcadDynamicBlockReferenceProperty
Dim Variable As Variant
NAME = UCase(NAME)
Variable = BlockRef.GetDynamicBlockProperties
For K = LBound(Variable) To UBound(Variable)
Set DynProp = Variable(K) 'Check for variable and when found ask for input
If UCase(DynProp.PropertyName) = NAME Then
block_has_parameter = True
Exit Function
End If
Next
End Function
Function block_get_parameter(ByRef v As Variant, BlockRef As AcadBlockReference, ByVal NAME As String) As Boolean
Dim DynProp As AcadDynamicBlockReferenceProperty
Dim Variable As Variant
NAME = UCase(NAME)
block_get_parameter = False
If BlockRef Is Nothing Then Exit Function
If BlockRef.IsDynamicBlock Then
Variable = BlockRef.GetDynamicBlockProperties
For K = LBound(Variable) To UBound(Variable)
Set DynProp = Variable(K)
If UCase(DynProp.PropertyName) = NAME Then
block_get_parameter = True
v = DynProp.Value
Exit For
End If
Next
End If
End Function
Sub block_delete()
If SLOPEFORM.BNAME = "" Then Exit Sub
Dim entity As AcadEntity
Dim blo As AcadBlockReference
For Each entity In ThisDrawing.modelspace
If LCASE(entity.ObjectName) = "acdbblockreference" Then
Set blo = entity
'ENTSCAHAERFT If LCASE(blo.EffectiveName) = LCASE(SLOPEFORM.BNAME) Then 'blo.Delete
'habs mal auskommentiert eh da noch was aus versehen passiert...
End If
Next
End Sub
------------------
wer es nicht versucht, hat schon verlorn
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP