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

How to insert xref using .net API

282 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 (282 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
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.