mftbrothers Posted June 30, 2010 Share Posted June 30, 2010 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) ] ? Quote Link to comment Share on other sites More sharing options...
SEANT Posted June 30, 2010 Share Posted June 30, 2010 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? Quote Link to comment Share on other sites More sharing options...
mftbrothers Posted July 1, 2010 Author Share Posted July 1, 2010 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) Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted July 1, 2010 Share Posted July 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
mftbrothers Posted July 1, 2010 Author Share Posted July 1, 2010 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?? Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted July 1, 2010 Share Posted July 1, 2010 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 Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted July 1, 2010 Share Posted July 1, 2010 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 Autodesk.AutoCAD.Interop.Common.AcadViewportClass LowerLeftCorner UpperRightCorner [Added] Have a look for ActiveViewport in the on-line net help .. the AutoCAD .NET Developer's Guide Quote Link to comment Share on other sites More sharing options...
10west Posted July 13, 2010 Share Posted July 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
RMS Posted July 14, 2010 Share Posted July 14, 2010 Purge the drawing first then try.......... Quote Link to comment Share on other sites More sharing options...
mftbrothers Posted July 16, 2010 Author Share Posted July 16, 2010 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() ...... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.