.NET

Reply
Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 1 of 4 (364 Views)
Accepted Solution

XData problem

364 Views, 3 Replies
12-10-2011 03:05 AM

I have used Kean Walmsley's article http://through-the-interface.typepad.com/through_the_interface/2007/04/adding_xdata_to.html as a basis for trying to add xdata to a block.

 

I am trying to add the handle of another object to the block. Here is the code:-

   Private Sub Insert(ByVal tr As Transaction, ByVal Name As String, ByVal Path As String, _
                            ByVal Scale As Integer, ByVal ip As Point3d, ByVal Hwnd As Handle)
      Dim btr As BlockTableRecord = CType(tr.GetObject(CurDb.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
      Dim BlkId As ObjectId = CreateBlockReference(tr, Name, Path, btr)                '  insert blockreference
      Dim blk As BlockReference = New BlockReference(ip, BlkId)                        '  insert block
      blk.SetDatabaseDefaults()
      blk.ScaleFactors = New Scale3d(Scale, Scale, 1)
      blk.Rotation = 0
      btr.AppendEntity(blk)
      tr.AddNewlyCreatedDBObject(blk, True)                                            '  add it to transaction
      AddRegAppTableRecord(tr, "MYXDATA")
      Dim values() As TypedValue = {New TypedValue(1001, "MYXDATA"), New TypedValue(DxfCode.Handle, Hwnd)}
      Dim rb As New ResultBuffer(values)
      blk.XData = rb
      rb.Dispose()
   End Sub
   Private Sub AddRegAppTableRecord(ByVal tr As Transaction, ByVal regAppName As String)
      Dim rat As RegAppTable = DirectCast(tr.GetObject(CurDb.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
      If Not rat.Has(regAppName) Then
         rat.UpgradeOpen()
         Dim ratr As New RegAppTableRecord()
         ratr.Name = regAppName
         rat.Add(ratr)
         tr.AddNewlyCreatedDBObject(ratr, True)
      End If
   End Sub

 I get the following error:- eInvalidInput

at the line blk.Xdata = rb

Hi,

 

first guess:

don't use this: New TypedValue(DxfCode.Handle, Hwnd)

instead try this: New TypedValue(DxfCode.ExtendedDataHandle, Hwnd)

The DxfCode.Handle can only exist once for an object, and that's the object's handle, not a referenced handle from another entity.

 

HTH, - alfred -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,051
Registered: ‎06-29-2007
Message 2 of 4 (363 Views)

Re: XData problem

12-10-2011 03:15 AM in reply to: stuartnathan

Hi,

 

first guess:

don't use this: New TypedValue(DxfCode.Handle, Hwnd)

instead try this: New TypedValue(DxfCode.ExtendedDataHandle, Hwnd)

The DxfCode.Handle can only exist once for an object, and that's the object's handle, not a referenced handle from another entity.

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
dgorsman
Posts: 5,335
Registered: ‎10-12-2006
Message 3 of 4 (307 Views)

Re: XData problem

12-12-2011 08:00 AM in reply to: Alfred.NESWADBA

Let me guess - .Handle is DXF code 5, .ExtendedDataHandle is DXF code 1005?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 4 of 4 (299 Views)

Re: XData problem

12-12-2011 09:37 AM in reply to: dgorsman

:smileysurprised:Only way to fly!

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.