Jump to content

Working with huge amount of items.


mftbrothers

Recommended Posts

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) ] ?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 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

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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.AcSelect.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()

......

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...