.NET

Reply
Member
demo2005
Posts: 5
Registered: ‎05-29-2006
Message 1 of 2 (276 Views)

How to insert xref using .net API

276 Views, 1 Replies
06-01-2006 10:45 PM
in my .net application, i try to attach xref programmly. can anyone help?
Valued Contributor
smcclure
Posts: 60
Registered: ‎06-08-2006
Message 2 of 2 (276 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:
[code]
_
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()
Try
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"
tbl.Add(app)
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
myT.Commit()
Finally
myT.Dispose()
End Try
End Sub 'XRecCommand
[/code]

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