[VBA]删标标注:提示空指针对象错误?有代码
这段程序是建立一个选择集,将标注对象加入选择集,把所有的标注都删除当然,有更好的办法更好,请看一下下面的代码
Set ACADapp = GetObject(, "AutoCAD.Application")<BR> Set ACADdoc = ACADapp.ActiveDocument<BR> Dim ssetObj As AcadSelectionSet<BR> ACADapp.ActiveDocument.SelectionSets("TEST_SELECTIONSET").Delete<BR> Set ssetObj = ACADapp.ActiveDocument.SelectionSets.Add("TEST_SELECTIONSET")<BR> <BR> Dim i As Long<BR> Dim obj As AcadObject
i = 0<BR> For Each obj In ACADapp.ActiveDocument.ModelSpace '遍历工作区中的实体<BR> Select Case obj.EntityName<BR> Case "AcDbMText", "AcDbText", "AcDbRadialDimension", "AcDb3PointAngularDimension", "AcDbRotatedDimension", "AcDbAlignedDimension", "AcDbOrdinateDimension", "AcDbFcf", "AcDbLeader"<BR> i = i + 1<BR> Case Else<BR> End Select<BR> Next obj
MsgBox i<BR> ReDim ssobjs(0 To i) As AcadEntity
i = 0<BR> For Each obj In ACADapp.ActiveDocument.ModelSpace '遍历工作区中的实体<BR> Select Case obj.EntityName<BR> Case "AcDbMText", "AcDbText", "AcDbRadialDimension", "AcDb3PointAngularDimension", "AcDbRotatedDimension", "AcDbAlignedDimension", "AcDbOrdinateDimension", "AcDbFcf", "AcDbLeader"<BR> Set ssobjs(i) = ACADapp.ActiveDocument.ModelSpace.Item(i)<BR> i = i + 1<BR> Case Else<BR> End Select
Next obj<BR> MsgBox i<BR> <BR> ssetObj.AddItems ssobjs '这句老提示空对象指针,是怎么回事<BR> <BR> ssetObj.Erase<BR> i值指的是选择到的图元数量,但循环却是从0-i,也就是需要i+1的图元数量。所以在你的程序中,ssobjs(i)数组的最后一个元素并未被赋值。 问题已解决,谢谢
页:
[1]