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

How to insert xref using .net API

1 REPLY 1
Reply
Message 1 of 2
demo2005
510 Views, 1 Reply

How to insert xref using .net API

in my .net application, i try to attach xref programmly. can anyone help?
1 REPLY 1
Message 2 of 2
smcclure
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]

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