下面是一个根据数据库里主键值添加扩展数据的代码,它的运行结果总是满足不了要求请教高手们. Private Sub kzsj(obj As AcadEntity, cn, dwname) '加扩展数据 Dim sjk As New ADODB.Recordset Dim id As Long id = 0 sjk.Open "select * from tysx order by cadid asc ", cn, adOpenDynamic, adLockReadOnly Do While Not sjk.EOF id = sjk.Fields("cadid") sjk.MoveNext Loop sjk.Close For Each obj In ThisDrawing.ModelSpace Dim xtype As Variant Dim xdata As Variant obj.GetXData "", xtpye, xdata If IsEmpty(xtype) Then '判断是否有扩展数据。(不知是不是这里不对)我想判断在它没有扩展数据的时候添加} Dim datatype(0 To 7) As Integer Dim data(0 To 7) As Variant datatype(0) = 1001: data(0) = "tete" datatype(1) = 1000: data(1) = dwname datatype(2) = 1003: data(2) = "0" datatype(3) = 1040: data(3) = 1.232 datatype(4) = 1041: data(4) = id + 1 datatype(5) = 1070: data(5) = 5656 datatype(6) = 1071: data(6) = 32332 datatype(7) = 1042: data(7) = 10 obj.SetXData datatype, data id = id + 1 End If Next obj
End Sub |