This works, thanks. I was cycling through the blocks but never thought to
cycle through the objects.
Jorge
"Frank Oquendo" wrote in message
news:79466AB48F77B79CAB1C41A389E7992C@in.WebX.maYIadrTaRb...
> Contrary to Tony's post, VBA can access the path of an xref just fine. The
> trick is getting to the xref. The attached module shows one way to do
this.
>
> If your intention is to repath and reload the xref, once you've changed
the
> xref path be sure to use the blocks collection to reload it:
>
> ThisDrawing.Blocks("x").Reload
>
> --
> Good judgment comes from experience.
> Experience comes from bad judgment.
>
> http://www.acadx.com
>
>
> "Jorge Aguirre" wrote in message
> news:90480FA55016B5A448665C6E2D85C392@in.WebX.maYIadrTaRb...
> > I am trying to modify the xref block filename and path. I have written
a
> > routine that will grab all blocks that are xrefs but I cannot figure out
> how
> > to incorporate the externalreference object. Every example I find loads
> the
> > xref with the code. I am trying to modify the xref path and file name
of
> an
> > xref that has already been loaded. Any suggestions.
> >
> > Dim xref_file As AcadExternalReference
> > For x = 0 To Me.Blocks.Count - 1
> > If Me.Blocks(x).IsXRef Then
> >
> > 'Set xref_file = Me.Blocks.Item(Me.Blocks(x).Name).Reload
> > 'The line above is what I am having trouble with.
> > 'I cannot figure out how to attach the object to the xref_file
> > 'variable.
> >
> > End If
> > Next x
> >
> >
> >
>
>
----------------------------------------------------------------------------
----
Attribute VB_Name = "Module1"
Public Sub test()
' Assumes you've referenced COLORWH.DWG in your sample folder.
' Move COLORWH.DWG to your TEMP folder before running.
Dim ss As AcadSelectionSet, fType, fData
Dim xref As AcadExternalReference
Set ss = CreateSelectionSet
BuildFilter fType, fData, 0, "INSERT", 2, "COLORWH"
ss.Select acSelectionSetAll, , , fType, fData
For Each xref In ss
xref.Path = "C:\Temp\colorwh.dwg"
ThisDrawing.Blocks(xref.Name).Reload
Next
End Sub
Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
Dim fType() As Integer, fData()
Dim index As Long, i As Long
index = LBound(gCodes) - 1
For i = LBound(gCodes) To UBound(gCodes) Step 2
index = index + 1
ReDim Preserve fType(0 To index)
ReDim Preserve fData(0 To index)
fType(index) = CInt(gCodes(i))
fData(index) = gCodes(i + 1)
Next
typeArray = fType: dataArray = fData
End Sub
Public Function CreateSelectionSet(Optional ssName As String = "ss") As
AcadSelectionSet
Dim ss As AcadSelectionSet
On Error Resume Next
Set ss = ThisDrawing.SelectionSets(ssName)
If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
ss.Clear
Set CreateSelectionSet = ss
End Function