Posts: 5
Registered: ‎05-29-2006
Message 1 of 2 (287 Views)

How to insert xref using .net API

287 Views, 1 Replies
06-01-2006 10:45 PM
in my .net application, i try to attach xref programmly. can anyone help?
Valued Contributor
Posts: 60
Registered: ‎06-08-2006
Message 2 of 2 (287 Views)

Re: How to insert xref using .net API

06-08-2006 01:31 PM in reply to: demo2005
From the VBNetARX sample in the ObjectARX 2005 SDK:
Public Shared Sub XRecCommand()
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As DBTransMan = db.TransactionManager
'start a transaction
Dim myT As Transaction = tm.StartTransaction()
Dim rec As New Xrecord()
rec.Data = New ResultBuffer( _
New TypedValue(CInt(DxfCode.Text), "This is a test"), _
New TypedValue(CInt(DxfCode.Int8), 0), _
New TypedValue(CInt(DxfCode.Int16), 1), _
New TypedValue(CInt(DxfCode.Int32), 2), _
New TypedValue(CInt(DxfCode.HardPointerId), db.BlockTableId), _
New TypedValue(CInt(DxfCode.BinaryChunk), New Byte() {0, 1, 2, 3, 4}), _
New TypedValue(CInt(DxfCode.ArbitraryHandle), db.BlockTableId.Handle), _
New TypedValue(CInt(DxfCode.UcsOrg), New Point3d(0, 0, 0)))

Dim dict As DBDictionary = CType(myT.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, False), DBDictionary)
dict.SetAt("test", rec)
tm.AddNewlyCreatedDBObject(rec, True)
'list the entries we just added
CommandLinePrompts.Message("Xrecord items:" + ControlChars.Lf)
Dim rb As TypedValue
For Each rb In rec.Data
CommandLinePrompts.Message(String.Format("TypeCode={0}, Value={1}" + ControlChars.Lf, rb.TypeCode, rb.Value))
Next rb
'add some xdata on the xrecord (silly but this is just a test)
'first have to register an app
Dim tbl As RegAppTable = CType(myT.GetObject(db.RegAppTableId, OpenMode.ForWrite, False), RegAppTable)
Dim app As New RegAppTableRecord()
app.Name = "MyApp"
tm.AddNewlyCreatedDBObject(app, True)

rec.XData = New ResultBuffer(New TypedValue(CInt(DxfCode.ExtendedDataRegAppName), "MyApp"), New TypedValue(CInt(DxfCode.ExtendedDataAsciiString), "This is some xdata string"))
'list them
CommandLinePrompts.Message("Xdata items:" + ControlChars.Lf)
For Each rb In rec.XData
CommandLinePrompts.Message(String.Format("TypeCode={0}, Value={1}" + ControlChars.Lf, rb.TypeCode, rb.Value))
Next rb
'commit transaction
End Try
End Sub 'XRecCommand
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!