cad二次开发在delphi里的数组结构的问题
pi3b 2012-09-21 07:26:52 USE 了AutoCAD_TLB,选择集的SELECT和SELECTONSCREEN都有这样的问题,过滤器的数组结构貌似对不上,大师们指点一下:
procedure TForm1.N8Click(Sender: TObject);
var filtertype1:OleVariant;
filterdata:OleVariant;
iselectionset:IAcadSelectionSet;
begin
connecttocad;
acdcmnt1.ConnectTo(iapp.ActiveDocument);
while acdcmnt1.SelectionSets.Count<>0 do
acdcmnt1.SelectionSets.Item(0).Delete;
iselectionset:=acdcmnt1.SelectionSets.Add('tk2') ;
filtertype1:=VarArrayCreate([0,3],varInteger);
filterdata:=VarArrayCreate([0,3],varVariant);
filtertype1[0]:=-4;
filterdata[0]:='<OR'; //'图框A0';
filtertype1[1]:=0;
filterdata[1]:='LWPOLYLINE'; //'图框A0';
filtertype1[2]:=0;
filterdata[2]:='LINE'; //'图框A0';
filtertype1[3]:=-4;
filterdata[3]:='OR>'; //'图框A0';
iselectionset.Select(acSelectionSetAll,EmptyParam,EmptyParam,
filtertype1,filterdata);
end;
我目前是对MODOLSPACE里的所有对象做遍历判断,这样效率太低了,大师回答时别说让我放弃DELPHI啊,DELPHI做界面很方便,我不会放弃的。
在VB和VBA里边没有一点问题,以下是VB的代码(引用AUTOCAD2006LIBRARY):
Sub b()
Dim s As String
Dim a, b As AcadSelectionSet
Dim e As AcadBlockReference
Dim filtertype(0) As Integer
Dim filterdata(0) As Variant
Dim ft2(3) As Integer
Dim fd2(3) As Variant
While ActiveDocument.SelectionSets.Count <> 0
ActiveDocument.SelectionSets.Item(0).Delete
Wend
Set a = ActiveDocument.SelectionSets.Add("a")
Set b = ActiveDocument.SelectionSets.Add("b")
ft2(0) = -4
fd2(0) = "<AND" '
ft2(1) = 8
fd2(1) = "图框A1" '
ft2(2) = 0
fd2(2) = "LWPOLYLINE" '
ft2(3) = -4
fd2(3) = "AND>" '
b.Select acSelectionSetAll, , , ft2, fd2
MsgBox b.Count & """个在图层""图框A1""的多段线 "
Dim pline As AcadLWPolyline
Dim minp, maxp As Variant
For Each pline In b
pline.GetBoundingBox minp, maxp
filtertype(0) = 2
filterdata(0) = "图框_2012" '
a.Select acSelectionSetWindow, minp, maxp, filtertype, filterdata
For Each e In a
MsgBox "找到 " & e.Name & """在图层""图框A1""的多段线 " & pline.ObjectID & " 内。"
Next
Next
a.Delete
b.Delete
End Sub
Private Sub Command1_Click()
b
End Sub
附ACTIVEX帮助文档相关:
object.Select Mode[, Point1][, Point2][, FilterType][, FilterData]
Object
SelectionSet
The object or objects this method applies to.
Mode
AcSelect enum; input-only
acSelectionSetWindow
acSelectionSetCrossing
acSelectionSetPrevious
acSelectionSetLast
acSelectionSetAll
Point1
Variant (array of doubles); input-only; optional
The 3D WCS coordinates, or array of coordinates, specifying Point1. See the mode definitions for the proper use of Point1.
Point2
Variant (three-element array of doubles); input-only; optional
The 3D WCS coordinates specifying Point2. See the mode definitions for the proper use of Point2.
FilterType
Integer; input-only; optional
A DXF group code specifying the type of filter to use.
FilterData
Variant; input-only; optional
The value to filter on.