Visual Basic Customization

Reply
*Aguirre, Jorge
Message 1 of 11 (91 Views)

modifying xrefs path and filename

91 Views, 10 Replies
12-17-2001 04:03 AM
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
*Sutphin, Joe
Message 2 of 11 (91 Views)

Re: modifying xrefs path and filename

12-17-2001 04:58 AM in reply to: *Aguirre, Jorge
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
>
>
>
*Aguirre, Jorge
Message 3 of 11 (91 Views)

Re:

12-17-2001 05:02 AM in reply to: *Aguirre, Jorge
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
> >
> >
> >
>
>
*Tanzillo, Tony
Message 4 of 11 (91 Views)

Re: modifying xrefs path and filename

12-17-2001 05:49 AM in reply to: *Aguirre, Jorge
"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.
*Sutphin, Joe
Message 5 of 11 (91 Views)

Re:

12-17-2001 05:58 AM in reply to: *Aguirre, Jorge
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
*Oquendo, Frank
Message 6 of 11 (91 Views)

Re: modifying xrefs path and filename

12-17-2001 06:10 AM in reply to: *Aguirre, Jorge
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
>
>
>
*Aguirre, Jorge
Message 7 of 11 (91 Views)

Re:

12-17-2001 06:47 AM in reply to: *Aguirre, Jorge
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
*Tanzillo, Tony
Message 8 of 11 (91 Views)

Re: modifying xrefs path and filename

12-17-2001 09:02 AM in reply to: *Aguirre, Jorge
"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.
*Sutphin, Joe
Message 9 of 11 (91 Views)

Re:

12-17-2001 09:02 AM in reply to: *Aguirre, Jorge
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.
>
>
>
>
*Starz, Rob
Message 10 of 11 (91 Views)

Re:

12-17-2001 10:57 AM in reply to: *Aguirre, Jorge
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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community