[VBA]请看我的 SelectByPolygon acSelectionSetCrossingPolygon 不对了
<P>请大家看一下如下程序,在一幅图的多数地方选择都是正确的,我发现有一个多边形选不到其里面的物体(看付图):</P><P>Sub gHH()<BR>Dim selobj As Object<BR>ThisDrawing.Utility.GetEntity selobj, basePoint, "请选择线:"<BR>SelObjByPoly selobj<BR>End Sub</P>
<P>Function SelObjByPoly(Ent As AcadEntity) As AcadSelectionSet<BR> Dim Coord As Variant<BR> Dim CoordCount As Integer<BR> Dim NewCoord() As Double<BR> Dim SelPoly As AcadSelectionSet<BR> Dim minpnt As Variant '对象边框最小点坐标<BR> Dim maxpnt As Variant '对象边框最大点坐标<BR> Dim zminpnt(0 To 2) As Double '不闭合对象的缩放点左下角点坐标<BR> Dim zmaxpnt(0 To 2) As Double '不闭合对象的缩放点右上角点坐标<BR> <BR> ThisDrawing.Layers.Item("SXD").LayerOn = True<BR> Ent.GetBoundingBox minpnt, maxpnt<BR> zminpnt(0) = minpnt(0) ' - 800<BR> zminpnt(1) = minpnt(1) '- 800<BR> zminpnt(2) = 0<BR> zmaxpnt(0) = maxpnt(0) '+ 800<BR> zmaxpnt(1) = maxpnt(1) '+ 800<BR> zmaxpnt(2) = 0<BR> ThisDrawing.Application.ZoomWindow zminpnt, zmaxpnt<BR> On Error GoTo Err1:<BR> Set SelPoly = ThisDrawing.SelectionSets.Add("SelP")<BR> <BR> If TypeName(Ent) = "IAcadLWPolyline" Then<BR> Coord = Ent.Coordinates '获取顶点坐标数组<BR> CoordCount = (UBound(Coord) + 1) / 2 '顶点数<BR> '定义新的顶点坐标数组<BR> ReDim NewCoord(0 To (3 * CoordCount - 1)) As Double<BR> For j = 0 To UBound(Coord) - 1 Step 2<BR> NewCoord((3 * j) / 2) = Coord(j)<BR> NewCoord((3 * j) / 2 + 1) = Coord(j + 1)<BR> NewCoord((3 * j) / 2 + 2) = 0<BR> Next j<BR> ElseIf TypeName(Ent) = "IAcadPolyline" Then<BR> Coord = Ent.Coordinates<BR> CoordCount = (UBound(Coord) + 1) / 3<BR> ReDim NewCoord(0 To UBound(Coord)) As Double<BR> For j = 0 To UBound(Coord) - 1<BR> NewCoord(j) = Coord(j)<BR> NewCoord(j) = Coord(j)<BR> NewCoord(j) = Coord(j)<BR> Next j<BR> <BR> End If<BR> SelPoly.SelectByPolygon acSelectionSetCrossingPolygon, NewCoord<BR> A = SelPoly.Count '<FONT color=#f73809>个数为0<BR></FONT> Set SelObjByPoly = SelPoly<BR> ZoomPrevious<BR>Exit Function<BR>Err1:<BR> ThisDrawing.SelectionSets.Item("SelP").Delete<BR> Resume<BR>End Function</P> 我反复试了很多次,有几次得到了SelPoly.Count 为7,但多数时候为0,具体哪种情况下得到了7也不搞明白 象这样的程序,你可以在调试时使用debug.print来打印出点表数据,看看数据有没有问题。 点表数据?是指什么?mccad 点列表如下:好象看不出有问题.在我的图内还有这样选不到内部的多段线,我估计会不会与多段线围成的形状有关系,好象复杂一点的都要出问题
1,x= 5468.99675040063,Y=4924.56511756871,z=0
2,x= 5469.81311140064,Y=4931.84850156866,z=0
3,x= 5466.58060740074,Y=4930.67364256922,z=0
4,x= 5463.73991940066,Y=4930.67364256922,z=0
5,x= 5455.88496440003,Y=4932.63833256857,z=0
6,x= 5452.75041139993,Y=4935.67338456912,z=0
7,x= 5449.41995240061,Y=4940.07910256833,z=0
8,x= 5446.77056840062,Y=4952.44458556874,z=0
9,x= 5382.25767040061,Y=4930.83008256881,z=0
10,x= 5370.80693340063,Y=4966.59749256866,z=0
11,x= 5443.23987440049,Y=4982.66365356883,z=0
12,x= 5438.62246540032,Y=4989.24247156922,z=0
13,x= 5434.90018740395,Y=4991.98380756658,z=0
14,x= 5429.98502039775,Y=4994.64100456936,z=0
15,x= 5416.66318140732,Y=4997.96977056656,z=0
16,x= 5403.31080440007,Y=5001.70352956885,z=0
17,x= 5393.09859739873,Y=5008.2800225704,z=0
18,x= 5380.05448939523,Y=5021.51714857388,z=0
19,x= 5366.22386139992,Y=5035.35004256899,z=0
20,x= 5358.86342840228,Y=5042.52191256732,z=0
21,x= 5347.80442539806,Y=5050.19126657071,z=0
22,x= 5327.76251439529,Y=5066.87071757391,z=0
23,x= 5315.5685183985,Y=5078.05919357063,z=0
24,x= 5307.3310904004,Y=5088.10764256958,z=0
25,x= 5306.32446240023,Y=5091.15743956994,z=0
26,x= 5305.40934240056,Y=5095.36410356872,z=0
27,x= 5297.02805140062,Y=5097.40244756872,z=0
28,x= 5297.34873240063,Y=5081.89763956843,z=0
29,x= 5299.41435440053,Y=5072.548062569,z=0
30,x= 5300.99422640068,Y=5059.937058568,z=0
31,x= 5301.2225204006,Y=5053.56433756882,z=0
32,x= 5338.36496440065,Y=5019.17317656847,z=0
33,x= 5299.00366840063,Y=4940.48604856897,z=0
34,x= 5160.03423940064,Y=4936.4713965687,z=0
35,x= 5142.30636940076,Y=4987.60292456858,z=0
36,x= 5137.67673640104,Y=4986.96450656839,z=0
37,x= 5132.40853239904,Y=4988.87976256898,z=0
38,x= 5127.29997440061,Y=4991.27383256936,z=0
39,x= 5114.17309827119,Y=4994.45996359969,z=0
40,x= 5110.41560302791,Y=4993.68675622391,z=0
41,x= 5089.23719439871,Y=4992.01636356814,z=0
42,x= 5072.03421639593,Y=4989.96065256745,z=0
43,x= 5055.33767665934,Y=4987.39608645439,z=0
44,x= 5051.49267287401,Y=4987.78039205959,z=0
45,x= 5044.31533211772,Y=4990.08622087212,z=0
46,x= 5028.38102010684,Y=4995.98497141339,z=0
47,x= 5016.46151240001,Y=4999.6999185686,z=0
48,x= 5009.28418146068,Y=5001.23713534139,z=0
49,x= 5004.54200938472,Y=5001.23713534139,z=0
50,x= 5000.00873398812,Y=5000.55208462155,z=0
51,x= 4990.21088540059,Y=4997.33367756847,z=0
52,x= 4973.39600137121,Y=4988.70058658021,z=0
53,x= 4955.79638479394,Y=4977.50578232016,z=0
54,x= 4942.66282353946,Y=4967.89627067,z=0
55,x= 4937.22918957536,Y=4960.70835241862,z=0
56,x= 4932.59809281473,Y=4949.65803500917,z=0
57,x= 4927.32642090088,Y=4931.31638230942,z=0
58,x= 4920.59904176305,Y=4906.81714777369,z=0
59,x= 4916.54061846848,Y=4890.70328662125,z=0
60,x= 4916.03128650261,Y=4882.80367515003,z=0
61,x= 4916.66515197139,Y=4878.62228145637,z=0
62,x= 4918.56675840082,Y=4870.25948956842,z=0
63,x= 4924.65616439894,Y=4858.06005657185,z=0
64,x= 4929.60032740078,Y=4849.6972665689,z=0
65,x= 4936.57901770825,Y=4842.57271329639,z=0
66,x= 4958.15753785829,Y=4827.85164164845,z=0
67,x= 4966.65582040051,Y=4821.74828956882,z=0
68,x= 4968.43065140065,Y=4817.82031256845,z=0
69,x= 4969.19166156434,Y=4809.17299270816,z=0
70,x= 4968.30425089534,Y=4802.71083592018,z=0
71,x= 4961.57594083546,Y=4780.75682072435,z=0
72,x= 4954.72402902407,Y=4768.3097420698,z=0
73,x= 4939.49500139995,Y=4748.12438156782,z=0
74,x= 4927.69538267009,Y=4729.9766601352,z=0
75,x= 4920.33431985608,Y=4717.26737132669,z=0
76,x= 4918.1761917831,Y=4710.01911847759,z=0
77,x= 4918.42974176531,Y=4706.47126917215,z=0
78,x= 4920.9652082306,Y=4699.75569586735,z=0
79,x= 4932.01910192083,Y=4680.31352917105,z=0
80,x= 4942.06272025016,Y=4665.19578168774,z=0
81,x= 4948.02107833803,Y=4656.95969265513,z=0
82,x= 4954.86684270907,Y=4653.15842383308,z=0
83,x= 4964.24807335198,Y=4650.75095485291,z=0
84,x= 4977.58165357745,Y=4651.13008101471,z=0
85,x= 4986.96288896294,Y=4653.03071399406,z=0
86,x= 5003.47549563576,Y=4657.98014116986,z=0
87,x= 5017.83351340803,Y=4665.47478457261,z=0
88,x= 5037.89410140127,Y=4676.76944456901,z=0
89,x= 5063.27749740053,Y=4685.78735556873,z=0
90,x= 5080.67770485696,Y=4696.57417223137,z=0
91,x= 5092.98739976459,Y=4706.47980175447,z=0
92,x= 5099.2352784017,Y=4714.47526156995,z=0
93,x= 5101.51720071811,Y=4717.13614693889,z=0
94,x= 5102.65816170973,Y=4717.38956635073,z=0
95,x= 5104.94008239952,Y=4717.00943856919,z=0
96,x= 5110.13779040053,Y=4714.34855056927,z=0
97,x= 5113.94101168367,Y=4709.1534582288,z=0
98,x= 5113.94099264522,Y=4709.1534844595,z=0
99,x= 5113.94097329862,Y=4709.15351088624,z=0
100,x= 5123.72472891363,Y=4695.67391761765,z=0
101,x= 5132.24875353585,Y=4686.64120098809,z=0
102,x= 5135.79840454622,Y=4681.69955336582,z=0
103,x= 5136.4322747605,Y=4679.67220934946,z=0
104,x= 5137.06614022015,Y=4673.59018005058,z=0
105,x= 5139.34806157276,Y=4668.01498674974,z=0
106,x= 5141.88353278383,Y=4664.08700996544,z=0
107,x= 5148.61930121644,Y=4659.75181068759,z=0
108,x= 5152.4225034776,Y=4659.87851901632,z=0
109,x= 5155.46506641194,Y=4659.49839388998,z=0
110,x= 5162.45268540038,Y=4661.71773056872,z=0
111,x= 5172.75622540282,Y=4665.52015856979,z=0
112,x= 5182.80982339813,Y=4669.97514556767,z=0
113,x= 5235.18016139255,Y=4696.34753756458,z=0
114,x= 5260.87573072017,Y=4710.44414912025,z=0
115,x= 5262.66090940026,Y=4718.3461205666,z=0
116,x= 5267.14031340054,Y=4736.4930545683,z=0
117,x= 5268.87182640063,Y=4745.65720456839,z=0
118,x= 5269.29162340064,Y=4749.19328456838,z=0
119,x= 5238.03051580733,Y=4758.31964058336,z=0
120,x= 5237.52043540048,Y=4756.78365556849,z=0
121,x= 5236.0460824006,Y=4751.4539235686,z=0
122,x= 5234.88495040085,Y=4748.03776156902,z=0
123,x= 5233.42859840067,Y=4744.83783756895,z=0
124,x= 5230.42542840046,Y=4740.61742656864,z=0
125,x= 5227.92822639609,Y=4738.0265265638,z=0
126,x= 5224.5574374001,Y=4734.6519945683,z=0
127,x= 5223.10806840064,Y=4733.51703356858,z=0
128,x= 5218.98498040013,Y=4732.58947456861,z=0
129,x= 5217.20335640089,Y=4733.04015456839,z=0
130,x= 5212.3292344014,Y=4735.39807656826,z=0
131,x= 5208.05070639949,Y=4738.69233356975,z=0
132,x= 5204.10367540352,Y=4742.39575056592,z=0
133,x= 5202.0919964005,Y=4744.40787756862,z=0
134,x= 5175.70835540071,Y=4716.3320775684,z=0
135,x= 5161.87026040157,Y=4725.46102856845,z=0
136,x= 5147.74816640205,Y=4734.13979556737,z=0
137,x= 5140.50115240394,Y=4738.18421556661,z=0
138,x= 5135.83497240063,Y=4740.69538256899,z=0
139,x= 5134.33014140069,Y=4736.99166056886,z=0
140,x= 5132.83002240042,Y=4730.99737256765,z=0
141,x= 5131.64165740064,Y=4724.86796956882,z=0
142,x= 5131.01250040066,Y=4718.89918256877,z=0
143,x= 5130.87523640064,Y=4713.90981956851,z=0
144,x= 5130.62415940064,Y=4712.18674756866,z=0
145,x= 5130.24414040067,Y=4711.23052656883,z=0
146,x= 5129.54799740098,Y=4710.81210256834,z=0
147,x= 5128.56481040036,Y=4710.97550856881,z=0
148,x= 5121.88193440082,Y=4716.97219756804,z=0
149,x= 5119.13890839939,Y=4722.29577057064,z=0
150,x= 5117.21301140112,Y=4725.89732656768,z=0
151,x= 5114.8320594001,Y=4729.25655156933,z=0
152,x= 5111.73708140088,Y=4732.04737756867,z=0
153,x= 5107.00873140158,Y=4733.51536856871,z=0
154,x= 5103.91620339098,Y=4733.35692256829,z=0
155,x= 5099.77758540085,Y=4733.04632256879,z=0
156,x= 5095.72655439627,Y=4733.06845756946,z=0
157,x= 5089.68495640141,Y=4733.23503556848,z=0
158,x= 5083.48838640307,Y=4732.80850356864,z=0
159,x= 5079.28065140144,Y=4732.18325456837,z=0
160,x= 5077.26955140021,Y=4732.15520756878,z=0
161,x= 5074.51185340033,Y=4732.94937256863,z=0
162,x= 5072.86193940131,Y=4734.08234356809,z=0
163,x= 5066.06960339402,Y=4740.70473857503,z=0
164,x= 5048.49429640081,Y=4757.28311856836,z=0
165,x= 5031.28474340058,Y=4774.7956215688,z=0
166,x= 5040.8716314038,Y=4777.30677256966,z=0
167,x= 5048.02727539925,Y=4779.31314856838,z=0
168,x= 5082.58417039952,Y=4792.91300856834,z=0
169,x= 5095.62161539798,Y=4800.04545556754,z=0
170,x= 5104.17773240071,Y=4805.05644656857,z=0
171,x= 5102.34072440129,Y=4812.16017156653,z=0
172,x= 5100.3699213987,Y=4819.23233757587,z=0
173,x= 5098.91622240073,Y=4824.54123456869,z=0
174,x= 5054.05679940048,Y=4825.2964505679,z=0
175,x= 5066.02023740072,Y=4869.39688856853,z=0
176,x= 5087.70398340089,Y=4896.30562856933,z=0
177,x= 5097.42428040062,Y=4917.2346495688,z=0
178,x= 5089.94712540082,Y=4950.12311056862,z=0
179,x= 5123.59431540064,Y=4938.16366956849,z=0
180,x= 5123.59431540058,Y=4898.54802156892,z=0
181,x= 5118.78265740076,Y=4877.19588356884,z=0
182,x= 5130.54606739938,Y=4876.04069956858,z=0
183,x= 5136.50307340646,Y=4876.33873256948,z=0
184,x= 5151.42215738946,Y=4877.79782756697,z=0
185,x= 5153.51939740061,Y=4878.0756305689,z=0
186,x= 5154.40354840056,Y=4887.10581056774,z=0
187,x= 5155.19879040064,Y=4896.07612556871,z=0
188,x= 5155.81507940055,Y=4904.93371956842,z=0
189,x= 5156.23786140059,Y=4911.49862056784,z=0
190,x= 5156.4941084006,Y=4913.69654556829,z=0
191,x= 5158.10322540061,Y=4920.42220056895,z=0
192,x= 5158.79103840073,Y=4922.12484056875,z=0
193,x= 5159.23408540088,Y=4922.86051256908,z=0
194,x= 5160.24450540112,Y=4923.6035215687,z=0
195,x= 5161.30817340076,Y=4923.71258356841,z=0
196,x= 5163.13027440174,Y=4923.45181156835,z=0
197,x= 5173.6316044,Y=4923.16408656864,z=0
198,x= 5179.06056040613,Y=4924.04744056938,z=0
199,x= 5185.51582140068,Y=4925.37291356875,z=0
200,x= 5196.61865539948,Y=4926.86181456875,z=0
201,x= 5205.67223740317,Y=4926.89641256863,z=0
202,x= 5207.93172140076,Y=4926.69663956854,z=0
203,x= 5210.53398839984,Y=4925.81528756907,z=0
204,x= 5211.9073704012,Y=4924.81776656816,z=0
205,x= 5220.11733540351,Y=4917.05306656612,z=0
206,x= 5224.80416940444,Y=4912.22300156439,z=0
207,x= 5226.31635239971,Y=4910.45523757022,z=0
208,x= 5227.26683240023,Y=4909.03713356936,z=0
209,x= 5227.90033940057,Y=4907.34901056858,z=0
210,x= 5239.23185439868,Y=4911.04959956789,z=0
211,x= 5250.49509440898,Y=4914.93876357144,z=0
212,x= 5261.64240139432,Y=4919.1481325659,z=0
213,x= 5272.71874240128,Y=4923.55350756878,z=0
214,x= 5311.92809540057,Y=4929.82798356842,z=0
215,x= 5318.37229840067,Y=4904.06282356894,z=0
216,x= 5279.6212724006,Y=4895.89812256861,z=0
217,x= 5280.76879540063,Y=4887.49530956848,z=0
218,x= 5281.18563240039,Y=4881.85094757145,z=0
219,x= 5281.48428940063,Y=4879.02631956851,z=0
220,x= 5282.0593174026,Y=4876.21329055913,z=0
221,x= 5282.35720540065,Y=4874.81913656835,z=0
222,x= 5282.24165540066,Y=4872.08680056874,z=0
223,x= 5281.55141640094,Y=4870.07634856971,z=0
224,x= 5280.61712439783,Y=4868.07512956252,z=0
225,x= 5279.41696340067,Y=4865.38414856885,z=0
226,x= 5278.17611740064,Y=4861.26328856871,z=0
227,x= 5277.45699840062,Y=4857.06591456896,z=0
228,x= 5277.16408440063,Y=4854.24080356862,z=0
229,x= 5276.53244040057,Y=4845.73452356784,z=0
230,x= 5275.56872140063,Y=4834.42133556865,z=0
231,x= 5279.36420940148,Y=4831.13137356844,z=0
232,x= 5282.5901784047,Y=4827.98220056528,z=0
233,x= 5287.66033240268,Y=4823.80942656659,z=0
234,x= 5292.10086640087,Y=4819.13150956808,z=0
235,x= 5297.1795833995,Y=4811.95934356982,z=0
236,x= 5299.96202640067,Y=4808.54537056852,z=0
237,x= 5306.90984540165,Y=4803.31455456791,z=0
238,x= 5310.93399639841,Y=4801.65642456897,z=0
239,x= 5319.36413340154,Y=4799.00693456782,z=0
240,x= 5329.39646840061,Y=4794.06151556876,z=0
241,x= 5330.15224240057,Y=4798.09553456865,z=0
242,x= 5332.33030940243,Y=4806.02856757538,z=0
243,x= 5335.65364340111,Y=4817.92688857019,z=0
244,x= 5338.14143740019,Y=4825.75704856776,z=0
245,x= 5340.47276340041,Y=4831.476074568,z=0
246,x= 5343.26024840079,Y=4837.04337656917,z=0
247,x= 5345.02208040084,Y=4840.77239956893,z=0
248,x= 5346.80136240064,Y=4846.60207356885,z=0
249,x= 5347.41359740059,Y=4852.75824856898,z=0
250,x= 5352.07316840219,Y=4852.70867056865,z=0
251,x= 5356.7147403998,Y=4852.88437056867,z=0
252,x= 5365.92409340054,Y=4854.11472056853,z=0
253,x= 5370.45300640061,Y=4862.73971556872,z=0
254,x= 5371.00207340071,Y=4865.1893385686,z=0
255,x= 5383.16404343897,Y=4866.43597113155,z=0
256,x= 5380.91391440068,Y=4892.03732056869,z=0
257,x= 5464.17153463658,Y=4901.68923462927,z=0
258,x= 5465.21175840066,Y=4904.82587856893,z=0
259,x= 5467.98022540065,Y=4917.31872356869,z=0
<P>注意,选择框点表不能自相交。</P> <P>我刚刚又试了一下,这下每次运行都能得到SelPoly.Count =7,真是奇怪,什么都没改啊有时正确有时又不正确,这样的程序谁敢用?拜托各位大侠帮忙找一下原因.</P>
<P>还有就是boundary命令用起也是头痛,同样的图形有时能生成边界有时又不能生成边界。不知大家能不能自己搞一个类似boundary命令功能来生成边界的程序(可能比较困难啊),这样的算法有么?</P> <P>arden </P>
<P>你是怎么解决使用SelectByPolygon acSelectionSetWindowPolygon时,当两边界重合时的问题?</P> <P>我的程序也有这个问题。</P>
<P>当图形简单、小时没有任何的错误出现</P>
<P>但当图形较大且复杂时出现这个错误,选不到图元,有时候能选到但这样的不多。</P>
<P>我怀疑是不是CAD提供的函数不稳定,有错误????????</P> dwg文件刚被打开时也选择不到对象,有没有人碰到这个问题啊?怎么解决的?
页:
[1]
2