.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

xref repath

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
543 Views, 4 Replies

xref repath

Does anyone know how to repath an xref, preferably vb.net?

- Ted Schaefer
WD Partners
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

I slogged my way through it. Here's some code that seems to work.
Any suggestions would be appreciated.

- Ted

Imports System.IO
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

Public Class clsWdProjGenLT

_
Public Sub UpdateXref()
Dim db As Autodesk.AutoCAD.DatabaseServices.Database
db = New Database(False, False)
db.ReadDwgFile("C:\Swap\DwgBlockText.dwg", IO.FileShare.ReadWrite,
False, Nothing)

Dim tm As DBTransMan = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction()
Dim bt As Autodesk.AutoCAD.DatabaseServices.BlockTable
Dim btr As BlockTableRecord
Dim blockId As ObjectId
Dim iter As IEnumerator
Dim strFname As String

bt = ta.GetObject(db.BlockTableId, OpenMode.ForRead)

iter = bt.GetEnumerator()

Do While iter.MoveNext() ' GetEnumerator(bt)
blockId = iter.Current
btr = ta.GetObject(blockId, OpenMode.ForWrite)
If btr.PathName.Length > 0 Then
'strFname = Path.GetFileName(btr.PathName)
btr.PathName = "c:\swap\x_az.dwg"
Debug.WriteLine(btr.Name & " " & btr.PathName)
End If
Loop
ta.Commit()
ta.Dispose()

db.RetainOriginalThumbnailBitmap = True
'if drawing is open, may throw error on save
db.SaveAs("C:\Swap\DwgBlockText2.dwg", Nothing)
db.Dispose()

End Sub
End Class


"TedSch" wrote in message
news:4881608@discussion.autodesk.com...
Does anyone know how to repath an xref, preferably vb.net?

- Ted Schaefer
WD Partners
Message 3 of 5
Anonymous
in reply to: Anonymous

This line:
If btr.PathName.Length > 0 Then

Should be replaced by:
if btr.isFromExternalReference then

- Ted


"TedSch" wrote in message
news:4883513@discussion.autodesk.com...
I slogged my way through it. Here's some code that seems to work.
Any suggestions would be appreciated.

- Ted

Imports System.IO
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

Public Class clsWdProjGenLT

_
Public Sub UpdateXref()
Dim db As Autodesk.AutoCAD.DatabaseServices.Database
db = New Database(False, False)
db.ReadDwgFile("C:\Swap\DwgBlockText.dwg", IO.FileShare.ReadWrite,
False, Nothing)

Dim tm As DBTransMan = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction()
Dim bt As Autodesk.AutoCAD.DatabaseServices.BlockTable
Dim btr As BlockTableRecord
Dim blockId As ObjectId
Dim iter As IEnumerator
Dim strFname As String

bt = ta.GetObject(db.BlockTableId, OpenMode.ForRead)

iter = bt.GetEnumerator()

Do While iter.MoveNext() ' GetEnumerator(bt)
blockId = iter.Current
btr = ta.GetObject(blockId, OpenMode.ForWrite)
If btr.PathName.Length > 0 Then
'strFname = Path.GetFileName(btr.PathName)
btr.PathName = "c:\swap\x_az.dwg"
Debug.WriteLine(btr.Name & " " & btr.PathName)
End If
Loop
ta.Commit()
ta.Dispose()

db.RetainOriginalThumbnailBitmap = True
'if drawing is open, may throw error on save
db.SaveAs("C:\Swap\DwgBlockText2.dwg", Nothing)
db.Dispose()

End Sub
End Class


"TedSch" wrote in message
news:4881608@discussion.autodesk.com...
Does anyone know how to repath an xref, preferably vb.net?

- Ted Schaefer
WD Partners
Message 4 of 5
netcai
in reply to: Anonymous

do you know how to insert a external reference by dot net api? thanks.
Message 5 of 5
Anonymous
in reply to: Anonymous

I think there's a sample in the .net training that you can download from
this forum.
I am only using 2005 at this point which doesn't have much of the autocad
elements.
And, I can't install 2006 because it corrupts the develpment environment.

- Ted


wrote in message news:4886635@discussion.autodesk.com...
do you know how to insert a external reference by dot net api? thanks.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost