+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Forum Newbie
    Using
    AutoCAD 2002
    Join Date
    Nov 2009
    Posts
    1

    Default Need to revise VB code to read text from DWG

    Registered forum members do not see this ad.

    Code:
    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

  2. #2
    Full Member jalucerol's Avatar
    Using
    AutoCAD 2010
    Join Date
    Oct 2009
    Location
    Mendoza, Argentina
    Posts
    33

    Wink

    Registered forum members do not see this ad.

    1.- Use a SelectionSet object, filtering by text.
    2.- Use other SelectionSet, filtering by specified layer.

    SelectionSet example:

    Code:
     
    '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

Similar Threads

  1. Suppress the read-only notice when opening read-only files?
    By DrewS in forum AutoCAD Drawing Management & Output
    Replies: 10
    Last Post: 14th Jan 2009, 10:31 am
  2. Inserting Text with Code!?
    By matt41129 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 8th Aug 2008, 09:47 pm
  3. Text can not be read in text formatting
    By marti in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 13th Mar 2008, 10:01 pm
  4. read text (Text extraction)
    By iain9876 in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 15th Jan 2008, 10:30 pm
  5. Is it possible to make a read-only sysvar a read/write var?
    By whatispunk in forum AutoCAD General
    Replies: 1
    Last Post: 11th Mar 2006, 11:49 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts