VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

modifying xrefs path and filename

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
598 Views, 10 Replies

modifying xrefs path and filename

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
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

Jorge,

Set xref_file = Me.Blocks.Item(x)
--
Joe Sutphin
Visual Basic How-To For AutoCAD
for more book details click on the link
http://eomnisource.hypermart.net


"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
>
>
>
Message 3 of 11
Anonymous
in reply to: Anonymous

I have tried this. I get an error message, run-time error '13' Type
mismatch.

Thank You for your response
Jorge Aguirre




"Joe Sutphin" wrote in message
news:B78BCC21DF8001E95213AC39FA18A976@in.WebX.maYIadrTaRb...
> Jorge,
>
> Set xref_file = Me.Blocks.Item(x)
> --
> Joe Sutphin
> Visual Basic How-To For AutoCAD
> for more book details click on the link
> http://eomnisource.hypermart.net
>
>
> "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
> >
> >
> >
>
>
Message 4 of 11
Anonymous
in reply to: Anonymous

"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.

VBA does not have access to the path of an external
reference, so you will have to use a third-party tool.

You can visit www.caddzone.com/acadx/acadx.htm and get
a copy of AcadX.arx, which provides several ways to do
this (one at a time, or all at once).

See the ReplaceXRefPaths() function in AcadXDatabase,
or the XRefPath property of the AcadXUtility object.
Message 5 of 11
Anonymous
in reply to: Anonymous

Public Sub GetXref()
Dim oXref As AcadExternalReference
Dim acObject As AcadObject

For Each acObject In ThisDrawing.ModelSpace
If TypeOf acObject Is AcadBlockReference Then
If ThisDrawing.Blocks(acObject.Name).IsXRef Then
Set oXref = acObject
End If
End If
Next acObject

MsgBox oXref.Path
End Sub
--
Joe Sutphin
Visual Basic How-To For AutoCAD
for more book details click on the link
http://eomnisource.hypermart.net
Message 6 of 11
Anonymous
in reply to: Anonymous

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
>
>
>
Message 7 of 11
Anonymous
in reply to: Anonymous

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
Message 8 of 11
Anonymous
in reply to: Anonymous

"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.

Sorry, my mistake. You can get at the Path of an XRef from
VBA.

However, the way that several others have suggested doing it
is wrong, because it iterates over the Xrefs, and there can
be any number of insertions of the same xref in a drawing,
in which case, the code repeatedly changes the path of and
reloads the same xref multiple times.

Use a dictionary or collection to store the name of each
xref you have already visited, and you can use it to avoid
changing the path and reloading it multiple times.
Message 9 of 11
Anonymous
in reply to: Anonymous

Good point!

Joe

Tony Tanzillo wrote in message
news:71946B8D8F47A996C64B28E557E80A39@in.WebX.maYIadrTaRb...
> "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.
>
> Sorry, my mistake. You can get at the Path of an XRef from
> VBA.
>
> However, the way that several others have suggested doing it
> is wrong, because it iterates over the Xrefs, and there can
> be any number of insertions of the same xref in a drawing,
> in which case, the code repeatedly changes the path of and
> reloads the same xref multiple times.
>
> Use a dictionary or collection to store the name of each
> xref you have already visited, and you can use it to avoid
> changing the path and reloading it multiple times.
>
>
>
>
Message 10 of 11
Anonymous
in reply to: Anonymous

This can be simple accomplished without Collection or dictionaries just by
checking the current path to the new path.

Sudo code:

If isXref(x) then
if x.path <> YourPath then
x.path = Yourpath
ThisDrawing.Blocks("x").Reload
end if
end if

--
|
-+-------------------------------------------------
| Rob Starz
| Stardsign cad solutions
| iC - AEC Information Center
| www.stardsign.com/aecic.html
| free ADT and Building Systems tools
| *******LayerX available Now*************
| www.stardsign.com/layerx.htm
| Easter Egg Hunt.....win a free version of LayerX
Message 11 of 11
Anonymous
in reply to: Anonymous

A dictionary/collection is unnecessary. All you need to do is process the
first item in the returned selection set.

--
Good judgment comes from experience.
Experience comes from bad judgment.

http://www.acadx.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost