Results 1 to 2 of 2

Thread: AutoCad VBA XRef Handling

  1. #1
    Member
    Join Date
    2017-07
    Posts
    4
    Login to Give a bone
    0

    Default AutoCad VBA XRef Handling

    Hi!

    Good day.

    Please help using AutoCad VBA. Currently I'm developing a tool to remove XRefs that are un-reference or unloaded.

    Below the code that I already started to list all Xref in to the drawing and display it to the listbox. I don't know if this is the proper way to load the Xref's?

    Code:
    Dim bdef As AcadBlock
        Dim bref As AcadBlockReference
        Dim xref As AcadExternalReference
        Dim blk As AcadBlock
        Dim ent As AcadEntity
        Dim xEnt As AcadEntity
        Dim list As New Collection
        Dim item As Variant
        Dim msg As String
        Dim processCnt As Integer
        '' handle errors inline
        On Error Resume Next
        
        '' Purge
        purgeBlocks
        purgeBlocks
        
        '' Settings
        pCnt = 1
        pCntMax = ThisDrawing.Blocks.Count
        ListBox1.ColumnCount = 5
        ListBox1.ColumnWidths = "30,150,250,50,30"
        mProcessDetached = True
        processCnt = 0
        
        ListBox1.Clear
        '' iterate block collection
        frmProgressBar.show
        pCnt = 0
        For Each blk In ThisDrawing.Blocks
            processCnt = processCnt + 1
            'frmProgressBar.progressbar "", processCnt, pCntMax
            'frmProgressBar.Repaint
            If (blk.IsXRef) Then
                pCnt = pCnt + 1
                Set xref = blk.XRefDatabase
                With ListBox1
                    .AddItem
                    .list(.ListCount - 1, 0) = pCnt
                    .list(.ListCount - 1, 1) = blk.Name
                    .list(.ListCount - 1, 2) = blk.Path
                    .list(.ListCount - 1, 3) = IIf(IsBlockNoXRefDatabase(blk), "Unloaded", "Loaded")
                    If (mProcessDetached) Then
                        If (IsBlockNoXRefDatabase(blk)) Then
                            'blk.Unload
                            'blk.Detach
                            'blk.Delete
                            .list(.ListCount - 1, 3) = "Detached"
                        End If
                    End If
                End With
                
                For Each bdef In blk.XRefDatabase.Blocks
                    'frmProgressBar.progressbar "", pCnt, pCntMax
                    'frmProgressBar.Repaint
                    If Not (bdef Is Nothing) Then
                        If (bdef.IsXRef) Then
                            pCnt = pCnt + 1
                            If (bdef.Name = "") Then
                                MsgBox bdef.Name
                                MsgBox (bdef Is Nothing)
                            End If
                            With ListBox1
                                .AddItem
                                .list(.ListCount - 1, 0) = pCnt
                                .list(.ListCount - 1, 1) = " -" & bdef.Name
                                .list(.ListCount - 1, 2) = bdef.Path
                                .list(.ListCount - 1, 3) = IIf(IsBlockNoXRefDatabase(bdef), "Unloaded", "Loaded")
                            End With
                        End If
                    End If
                Next
            End If
            
            
     
        Next

    Thanks and best regards,
    Alex
    Last edited by Ed Jobe; 2018-07-19 at 02:23 PM. Reason: Added code tags

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: AutoCad VBA XRef Handling

    Are you having a problem?
    C:> ED WORKING....

Similar Threads

  1. Replies: 12
    Last Post: 2024-02-26, 11:54 PM
  2. Replies: 1
    Last Post: 2012-07-20, 02:11 PM
  3. 2008 SCALE 1:100 xref xref xref xref- scale list issues
    By Apsis0215 in forum AutoCAD Customization
    Replies: 2
    Last Post: 2008-11-21, 08:17 PM
  4. Exporting Revit into Autocad with attached autocad Xref
    By kimudang in forum Revit Architecture - General
    Replies: 1
    Last Post: 2006-02-09, 07:26 PM
  5. How to set draworder in xref w/ AutoCAD 2002 LT
    By lsunarch in forum AutoCAD LT - General
    Replies: 2
    Last Post: 2005-06-22, 10:51 PM

Tags for this Thread

Posting Permissions

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