View Full Version : Working with huge amount of items.
mftbrothers
30th Jun 2010, 02:14 pm
i am using visual studio 2005 and checking areas of polylines object in an active autocad(2007) file.
i am using [ item1 = ThisDrawing.ModelSpace.Item(i) ] to get item properties. But when the number of items in model space is large like 10000+, with this method it makes the program run very slow. Is there some function to get items on screen or is there any fast way to get item properties other than [ item1 = ThisDrawing.ModelSpace.Item(i) ] ?
SEANT
30th Jun 2010, 10:40 pm
Visual Studio 2005 usually implies the use of managed ARX (.NET API), though using COM Interop - especially from an out of process executable - is fairly common. The lines of code in the original post, though, have a familiar VBA appearance.
From which direction are you hooking into AutoCAD?
mftbrothers
1st Jul 2010, 06:56 am
I dont have such knowledge to answer you. But you can decide it from my code i think. This is a sample code from my software: (visual studio <vb> 2005 code)
Dim MyAcad As Autodesk.AutoCAD.Interop.AcadApplication
Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument
Dim itemAd AsString
Dim i, cn AsInteger
Dim a, KNk(1) AsDouble
Dim item1 As Autodesk.AutoCAD.Interop.Common.AcadObject
MyAcad = CType(GetObject(, "AutoCAD.Application.17"), Autodesk.AutoCAD.Interop.AcadApplication)
ThisDrawing = MyAcad.ActiveDocument
cn = ThisDrawing.ModelSpace.Count
i = 0
a = 0
DoWhile (i < cn)
item1 = ThisDrawing.ModelSpace.Item(i)
itemAd = item1.ObjectName
If itemAd = "AcDbPolyline"Or itemAd = "AcDbCircle"Or itemAd = "AcDbEllipse"Then
If itemAd = "AcDbPolyline"Then
KNk(0) = item1.Coordinates(0)
KNk(1) = item1.Coordinates(1)
Else
KNk(0) = item1.Center(0)
KNk(1) = item1.Center(1)
EndIf
a = a + item1.Area()
EndIf
i = i + 1
Loop
MsgBox(a)
Kerry Brown
1st Jul 2010, 07:11 am
This :-
Dim item1 As Autodesk.AutoCAD.Interop.Common.AcadObject
MyAcad = CType(GetObject(, "AutoCAD.Application.17"), Autodesk.AutoCAD.Interop.AcadApplication)
indicates you are using COM, so you're effectively using ActiveX, similar to VBA.
mftbrothers
1st Jul 2010, 09:59 am
To make it faster what should i do?
for 30000 object, it spends like 6-7 minutes.
What i am doing is that. i am putting some rectangles created inside new layers uniquely named by program.
program calculates the polyline, circle, ellipse inside these rectangles. i can zoom to these rectangles. if i can get the items on screen then i dont need to cope with 30000 objects but only 100 objects seen on screen. And it will increase speed enourmously. Is there a way to get only items on screen??
Kerry Brown
1st Jul 2010, 01:30 pm
Drawing variable VIEWSIZE stores the height of the view displayed in the current viewport, measured in drawing units.
.. in conjunction with VIEWCTR
You may be able to make use of those ... but there should be an easier way ..
Perhaps save a temporary VIEW, then interigate the dimensions of that.
... but there still should be an easier way :)
Kerry Brown
1st Jul 2010, 01:50 pm
< .. >if i can get the items on screen then i dont need to cope with 30000 objects but only 100 objects seen on screen.
Have a look at AcadViewportClass (http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Autodesk.AutoCAD.Interop.Common:18.1.0.0:eed84259d 7cbf30b/Autodesk.AutoCAD.Interop.Common.AcadViewportClass)
Autodesk.AutoCAD.Interop.Common.AcadViewportClass
LowerLeftCorner (http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Autodesk.AutoCAD.Interop.Common:18.1.0.0:eed84259d 7cbf30b/Autodesk.AutoCAD.Interop.Common.AcadViewportClass/property:LowerLeftCorner:Object)
UpperRightCorner (http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Autodesk.AutoCAD.Interop.Common:18.1.0.0:eed84259d 7cbf30b/Autodesk.AutoCAD.Interop.Common.AcadViewportClass/property:UpperRightCorner:Object)
[Added]
Have a look for ActiveViewport in the on-line net help .. the AutoCAD .NET Developer's Guide
10west
13th Jul 2010, 10:19 am
Run it in VBA, which generally is 10 times faster than the VB external connection, since it then runs in AutoCAD's memory space.
I think also you can go through the polyline collection, instead of the whole drawing, or create a dummy drawing and dump evrything non Polyline,
But again, try running that same code through the VBAIDE interior to AutoCAD
RMS
14th Jul 2010, 02:50 am
Purge the drawing first then try..........
mftbrothers
16th Jul 2010, 06:56 am
I want to make program very precise and usable. In fact it is a good solution to delete all other objects other than polylines but I dont want users to do such things. What i come up with is that i am using selectionsets using select by window/polygon window method i get polylines,circles and ellips inside only that object. So it makes my calculation enormously fast as much as my expectations.
Run it in VBA, which generally is 10 times faster than the VB external connection i am gonna try it. Thanks for your advice 10west
Samples in my code:
dim altsx(2),ustsx(2) as double
oSel = ThisDrawing.SelectionSets.Add("IMRAPKSecimi")
oSel.Select(Autodesk.AutoCAD.Interop.Common.AcSele ct.acSelectionSetWindow, altsx, ustsx)
ForEach item1 In oSel
itemAd = item1.ObjectName
If itemAd = "AcDbPolyline"Or itemAd = "AcDbCircle"Or itemAd = "AcDbEllipse"Then
For KatmanNo = 0 To KtmnSy
KatmanAd = KatmanAdLB.Items.Item(KatmanNo)
If item1.Layer = KatmanAd Then
Alan(KatNo, KatmanNo) = Alan(KatNo, KatmanNo) + item1.Area()
......
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.