Author Topic: Blocks xdata DesignCenter Data  (Read 1171 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1851
Blocks xdata DesignCenter Data
« on: April 08, 2007, 12:42:57 PM »
I haven't attached xdata to blocks before as I've always added it to the blockreferences.
But now I find if I add it to an existing block definition it automatically becomes part of acad DesignCenter Data, ????.
Here's a couple of subs to show it.
If you run the first one you get the expected (and desired) result
 1001         Yours
 1000         CCCC

The second one debug.prints

 1001         ACAD
 1000         DesignCenter Data
 1002         {
 1070          1
 1070          1
 1002         }
 1001         Yours
 1000         CCCC


Code: [Select]
Sub MakeBlockwithXdata()

    Dim oBlock As AcadBlock
    Dim Zero(2) As Double
    Set oBlock = ThisDrawing.Blocks.Add(Zero, "L")
    oBlock.AddCircle Zero, 4
    Dim DataType(1) As Integer
    Dim Data(1) As Variant
    DataType(0) = 1001: Data(0) = "Yours"
    DataType(1) = 1000: Data(1) = "CCCC"
    oBlock.SetXData DataType, Data
    getxd "L"
   
End Sub

Sub AddXdatatoBlock()

    Dim oBlock As AcadBlock, P
    Dim br As AcadBlockReference
    ThisDrawing.Utility.GetEntity br, P, "Pick"
    Set oBlock = ThisDrawing.Blocks(br.Name)
    Dim DataType(1) As Integer
    Dim Data(1) As Variant
    DataType(0) = 1001: Data(0) = "Yours"
    DataType(1) = 1000: Data(1) = "CCCC"
    oBlock.SetXData DataType, Data
    getxd oBlock.Name
   
End Sub

Function getxd(sBlock As String)

    Dim oBlock As AcadBlock
    Set oBlock = ThisDrawing.Blocks(sBlock)
    Dim sMt As String
    Dim xdataOut As Variant
    Dim xtypeOut As Variant
    Dim i As Integer
   
    Debug.Print
    oBlock.GetXData "", xtypeOut, xdataOut
    If IsEmpty(xtypeOut) = False Then
    For i = 0 To UBound(xtypeOut)
        Debug.Print xtypeOut(i), xdataOut(i)
    Next
    End If
   
End Function

DaveW

  • Guest
Re: Blocks xdata DesignCenter Data
« Reply #1 on: April 08, 2007, 11:57:45 PM »
Not sure what your are asking or telling, as I do not know the difference between a block or blockreference.

The only thing I can see is that you are not clearing previous xdata on write. Note: if it is one time write, no big deal, but perhaps you are not really adding the data to blocks at all. as in, its already there???

Try clearing to data before the write. Make sure you test the object. the data that you are seeing may be needed for use later by acad and cause a corruption issue???


Code: [Select]
Public Function setXdataInformation(ByVal itm As AcadObject, sAppName As String, sValue As String) As Boolean

    Dim DataType(0 To 1) As Integer
    Dim Data(0 To 1) As Variant
    Dim clearDataType(0) As Integer
    Dim clearData(0) As Variant
   
    If itm Is Nothing Then
        'MsgBox "not found"
        Exit Function
    End If
 
    ' -- create new xdata item
    clearDataType(0) = 1001: clearData(0) = sAppName
    itm.SetXData clearDataType, clearData

    ' -- save data
    DataType(0) = 1001: Data(0) = sAppName
    DataType(1) = 1000: Data(1) = sValue
    itm.SetXData DataType, Data
   
    ' -- cleanup
    Set itm = Nothing
 
End Function
« Last Edit: April 09, 2007, 12:08:54 AM by DaveW »

Bryco

  • Water Moccasin
  • Posts: 1851
Re: Blocks xdata DesignCenter Data
« Reply #2 on: April 09, 2007, 10:26:21 AM »
Dave I was trying to show that Acad is adding stuff on it's own. (acad2006)
A block is basically a non graphical description of how to group some objects together, a blockreference is the graphic part where the group of objects is inserted into the drawing.
I can't see a need for clearing xdata as setxdata seems to clear whatever is in the app already.

DaveW

  • Guest
Re: Blocks xdata DesignCenter Data
« Reply #3 on: April 09, 2007, 10:48:40 AM »
Thanks for explaining the difference.

I see you are saying ACAD writes that on its own. I am not surprised and knowing that is there allows coders to use it in creative ways if need be.

Interesting. Our code just kept appending the xdata unless it was cleared. I have even seen posts where people were asking how to delete it and the answer was to write nothing back first, so that is what we did. Perhaps there was a slight difference between your code and ours at the time. I have no idea what that code was now though, so no comparision is possible.