PDA

View Full Version : Need to revise VB code to read text from DWG



zer0_code
16th Nov 2009, 12:18 pm
Public Function Oku()
'Dim objacad As AcadApplication
Dim thisdrawing As AcadDocument
Dim objBlok As AcadBlockReference
Dim element As Object
Dim ArrayAttributes As Variant

Set objacad = CreateObject("AutoCAD.Application")
objacad.Documents.Open (DwgName)
Set thisdrawing = objacad.ActiveDocument


'objacad.Visible = True

For Each element In thisdrawing.ModelSpace
If element.EntityType = 7 Then
If element.HasAttributes = True Then
Set objBlok = element
ArrayAttributes = element.GetAttributes

If objBlok.Name = blok_adi Then
adet = UBound(ArrayAttributes) - LBound(ArrayAttributes)

For j = LBound(ArrayAttributes) To UBound(ArrayAttributes)
Matrix(k, j, 1) = ArrayAttributes(j).TagString
Matrix(k, j, 2) = ArrayAttributes(j).TextString
Next

Else

For i = LBound(ArrayAttributes) To UBound(ArrayAttributes)

If ArrayAttributes(i).TagString = tag_adi Then
adet = UBound(ArrayAttributes) - LBound(ArrayAttributes)
For j = LBound(ArrayAttributes) To UBound(ArrayAttributes)
Matrix(k, j, 1) = ArrayAttributes(j).TagString
Matrix(k, j, 2) = ArrayAttributes(j).TextString
Next
'MsgBox "Attribute De─čeri : " & ArrayAttributes(I).TextString
GoTo sonraki
End If

Next

End If

End If
End If

sonraki:
Next

objacad.Quit

End FunctionI was using the above code to read attributes of blocks in dwg files. Now I need to do a similar thing. I need to read text object values with a specific layer in a dwg file.

The above code works fine. What it does is:
1. Opens the target dwg file
2. Checks for entitytype is a block or not
3. Checks for entity has attributes or not
4. If the element has attributes, it reads the attribute values

Now I need to revise my code but I don't know how ! Any help would be appriciated.

Things I wonder:
1. how can I check if an element is a text or not
2. how can I specify a layer and look for the object in that layer

I guess i may figure out the rest if I sum1 would show me the way :)

Thanks & best wishes from Turkey

jalucerol
16th Nov 2009, 04:44 pm
1.- Use a SelectionSet object, filtering by text.
2.- Use other SelectionSet, filtering by specified layer.

SelectionSet example:



'Seccion: crea un SelectionSet
Dim selectionSet1 As AcadSelectionSet
'selectionSet1.Delete
Set selectionSet1 = acadapp.ActiveDocument.SelectionSets.Add("BloquesSS")
'Fin de seccion
'Seccion: agrega objectos al selectionSet1
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
FilterType(0) = 1
FilterData(0) = "Text"
'fin de seccion