.NET

Reply
*TedSch
Message 1 of 5 (250 Views)

xref repath

250 Views, 4 Replies
06-22-2005 05:50 AM
Does anyone know how to repath an xref, preferably vb.net?

- Ted Schaefer
WD Partners
*TedSch
Message 2 of 5 (250 Views)

Re: xref repath

06-23-2005 10:51 AM in reply to: *TedSch
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
*TedSch
Message 3 of 5 (250 Views)

Re: xref repath

06-27-2005 01:34 PM in reply to: *TedSch
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
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 4 of 5 (250 Views)

Re: xref repath

06-27-2005 05:11 PM in reply to: *TedSch
do you know how to insert a external reference by dot net api? thanks.
*TedSch
Message 5 of 5 (250 Views)

Re: xref repath

06-28-2005 10:00 AM in reply to: *TedSch
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.
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 or visit the Installation and Licensing Forum to get help installing your software.