Jump to content

Need to revise VB code to read text from DWG


zer0_code

Recommended Posts

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 Function

I 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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...