求助!VB2010 调用方式连接autocad2014 调用setxdata时出错!
本帖最后由 yangmz1972 于 2021-6-14 22:38 编辑请教高手,我用VB2010 通过调用autocad2014方式编程,试图用setxdata方法为一个图形对象添加扩展数据,VBA手册中说明对象方法setxdata第一个参数为integer,第二个参数类型为varant类型,但VB2010没有varant类型,在VB2010的setxdata方法提示中,第一和第二参数均为了object类型。我试图用cobj函数把参数变为object型,调用setxdata方法时,老是提示参数类型不对,vb6中这样做无问题,但在VB2010中却出了这样的问题,这如何处理啊?
代码如下:不知道错误在哪里
oCad = CreateObject("autocad.application")
oCad.visible = True
Dim cfilename As String = AppStartDir & "\test.dwg"
oCad.Documents.open(cfilename)
Dim pfSS As AutoCAD.AcadSelectionSet = oCad.ActiveDocument.PickfirstSelectionSet
Dim objsl As Integer = pfSS.Count
Select Case pfSS.Count
Case 0
MsgBox("没有选择对象")
Case 1
Dim xDataType(1) As Object
Dim strdata(1) As Object
xDataType(0) = 1001
xDataType(1) = 1000
strdata(0) = "范围"
strdata(1) = "5"
pfSS.Item(0).SetXData(xDataType, strdata) '提示:参数类型无效
case >1
MsgBox("选择对象f过多")
end select
详见:http://blog.sina.com.cn/s/blog_af1320c70102xraw.html
'读取扩展数据
Public Function GetCode(objEnt As AcadEntity, strAppName As String) As Variant
Dim DataType As Variant, DataVaue As Variant, i As Integer
If HasXData(objEnt, strAppName) = False Then
GetCode = ""
Else
objEnt.GetXData strAppName, DataType, DataValue
For i = LBound(DataType) To UBound(DataType)
If DataType(i) = 1000 Then GetCode = DataValue(i): Exit For
Next i
End If
End Function
'设置扩展数据
Public Function SetCode(objEnt As AcadEntity, strAppName As String, strDataValue As String)
Dim DataType(0 To 1) As Integer
Dim DataValue(0 To 1) As Variant
DataType(0) = 1001: DataValue(0) = strAppName
DataType(1) = 1000: DataValue(1) = strDataValue
objEnt.SetXData DataType, DataValue
End Function 谢谢楼上的回复,VB2010没有Variant变量类型,查看VB2010引用的autocad类型库关于setxdata函数的参数类型,均为object型。所以才会出现参数无效的提示。
页:
[1]