Em meu artigo anterior, discuti os objetos AutoCAD Block e outros objetos relacionados à classe AutoCAD Block. Nesse artigo, também apresentei brevemente os atributos de bloco. Agora, neste artigo, concentro-me principalmente na classe AutoCAD Attribute.
Estou usando o módulo pyautocad para este artigo, mas também posso usar módulos de comunicação como pythoncom e win32com .
O que é um objeto de atributo do AutoCAD?
O objeto AutoCAD Attribute é basicamente um meta-dado que descreve as características de um objeto AutoCAD. Por exemplo, ele pode descrever as características de objetos de bloco do AutoCAD.AttributeReference é a classe de objeto que contém o texto que caracteriza algum objeto de bloco do AutoCAD .
Como já expliquei em um dos meus artigos anteriores sobre objetos AutoCAD Block, o AutoCAD Block é um elemento da classe BlockCollection. Para usar o objeto de bloco do AutoCAD, tenho que criar uma instância de um bloco específico no meu desenho. O objeto resultante é uma instância BlockReference.
Da mesma forma, um objeto AutoCAD AttributeRefrence é uma instância da classe Attribute.
Nas atividades de trabalho diárias, como, por exemplo, etiquetar entidades, criar etiquetas e anotações de desenhos, notações para um objeto específico, ajustes de configuração da janela de visualização, etc., precisarei de objetos AutoCAD Block atribuídos.
Portanto, entender os vários comandos relacionados ao AutoCAD Attribute é de grande importância.
Propriedades do objeto de atributo do AutoCAD
Nesta seção, discutirei algumas das propriedades importantes dos objetos Attribute. Além disso, gostaria de salientar que todas as propriedades que se aplicam aos objetos Attribute também se aplicam aos objetos AttributeReference.
Usei o mesmo exemplo para esta prática que já usei em meu artigo anterior do AutoCAD Block. Eu recomendo que você confira essa postagem no blog para uma compreensão abrangente da classe AutoCAD Block.
from pickle import TRUE
from pyautocad import Autocad, APoint, aDouble
acad = Autocad(create_if_not_exists=True)
ip = APoint(0, 0, 0)
b1 = acad.doc.Blocks.Add(ip, "Attributed_Block_1")
pl = b1.AddPolyline(aDouble(0, 0, 0, 10000, 0, 0, 10000, 5000, 0, 0, 5000, 0, 0, 0, 0))
l = b1.AddLine(APoint(0, 250, 0), APoint(10000, 250, 0))
l = b1.AddLine(APoint(5000, 250, 0), APoint(5000, 0, 0))
#0, 1, 2, 3, 4, 5, 6 .... 10
a1 = b1.AddAttribute(50, 0, "DATE", aDouble(200, 100, 0), "DATE", "Date: 17/07/2022")
a2 = b1.AddAttribute(50, 0, "DWG", aDouble(5200, 100, 0), "DWG", "Drawing Name: Drawing 1")
a2.MTextAttribute=True
br = acad.model.InsertBlock(APoint(50, 50, 0), "Attributed_Block_1", 1, 1, 1, 0)
print("Does the Block contain any Attributes: ", end="")
print(br.HasAttributes)

Agora, posso ver que uma referência ao bloco atribuído do AutoCAD foi criada no meu documento.
Abaixo demonstro as propriedades do objeto Attribute e do objeto AttributeRefrence que criei.
#General Properties
print("Attribute alignment: ", end="")
print(a1.Alignment)
print("Layer of attribute: " + a1.Layer)
print("Is the direction of text backward? " + str(a1.Backward))
print("Is the attribute reference constant ? " + str(a1.Constant))
print("Entity transparency value: ", end="")
print(a1.EntityTransparency)
print("Field length of the attribute: ", end="")
print(a1.FieldLength)
print("Text height: ", end="")
print(a1.Height)
print("Attribute insertion point: ", end="")
print(a1.InsertionPoint)
print("Is attribute reference invisible: " + str(a1.Invisible))
print("Can the attribute or attribute reference be moved relative to geometry in the block ? " + str(a1.LockPosition))
print("Object name: " + a1.ObjectName)
print("Oblique angle of the object: ", end="")
print(a1.ObliqueAngle)
print("Is the attribute preset? " + str(a1.Preset))
# apreset attribute sets the attribute to its default, or preset, value when the user inserts the block.
print("Rotation of object: ", end="")
print(a1.Rotation)
print("Scale factor for the object: ", end="")
print(a1.ScaleFactor)
print("Style name of the attribute object: " + a1.StyleName)
print("Is the attribute set for verification: " + str(a1.Verify))
O/p:
Attribute alignment: 0
Layer of attribute: 0
Is the direction of text backward? False
Is the attribute reference constant ? False
Entity transparency value: ByLayer
Field length of the attribute: 0
Text height: 50.0
Attribute insertion point: (200.0, 100.0, 0.0)
Is attribute reference invisible: False
Can the attribute or attribute reference be moved relative to geometry in the block ? False
Object name: AcDbAttributeDefinition
Oblique angle of the object: 0.0
Is the attribute preset? False
Rotation of object: 0.0
Scale factor for the object: 1.0
Style name of the attribute object: Standard
Is the attribute set for verification: False
Da mesma forma, existem algumas outras propriedades que definem o nome do atributo, o conteúdo do atributo e o tipo de texto. E assim por diante. Veja o código e a saída do programa abaixo.
# multiline text / text properties
if(a2.MTextAttribute==True):
print("Attribute content: " + a2.MTextAttributeContent)
print("Boundary width of multiline text: ", end="")
print(a2.MTextBoundaryWidth)
print("Multiline text direction: ", end="")
print(a2.MTextDrawingDirection)
print("Prompt string of an attribute: " + a1.PromptString)
print("Tag string of the attribute: " + a1.TagString)
print("Text string of the attribute: " + a1.TextString)
print("Alignment point of the text: ", end="")
print(a1.TextAlignmentPoint)
print("Attribute text generation flag: ", end="")
print(a1.TextGenerationFlag)
O/p:
Attribute content: Drawing Name: Drawing 1
Boundary width of multiline text: 0.0
Multiline text direction: 5
Prompt string of an attribute: DATE
Tag string of the attribute: DATE
Text string of the attribute: Date: 17/07/2022
Alignment point of the text: (0.0, 0.0, 0.0)
Attribute text generation flag: 0
Como mostro no código acima, existe uma propriedade para texto multilinha que retorna o valor da direção do texto. Tem cinco valores de retorno possíveis na forma de números inteiros. Essas opções são as seguintes:
- acBottomToTop : 1
- acByStyle : 2
- acLeftToRight : 3
- acRightToLeft : 4
- acTopToBottom : 5
Métodos da classe AutoCAD Attribute
Alguns métodos da classe Attribute e AttributeReference são semelhantes a outros métodos de outras classes de objetos do AutoCAD. Eu listo alguns dos métodos importantes abaixo:
- MatrizPolar
- MatrizRetangular
- cópia de
- Excluir
- GetBoundingBox
- Intersecção Com
- Espelho
- Espelho 3D
- Jogada
- Girar
- Girar3D
- ScaleEntity
- Atualizar
- UpdateMTextAttribute
Observações finais
Demonstrei o uso das classes AutoCAD Attribute, AttributeReference e AttriburtedBlock. Obviamente, o mais importante é implementar essas informações em nosso dia-a-dia para automatizar tarefas repetitivas e dispendiosas em um esforço para aumentar a produtividade. Considerando o mesmo, sinta-se à vontade para usar nosso formulário de contato para marcar uma sessão comigo para qualquer tipo de orientação técnica. Além disso, deixe comentários, dúvidas ou perguntas na seção de comentários abaixo.

Leave a Reply