Message 1 of 11

Not applicable
12-07-2010
08:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been trying to find helpful documentation to start writing applications for my CAD team, but with the move to Cad 2011, Windows 7 64Bit, ect...there's nothing I can find that will show me even basic stuff like attaching to AutoCAD and grabbing the area of all entities. Here's what I have writen down. I know it doesn't work, because it comes up with an error message and crashed before it gets into the Sub.
Option Explicit On Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Imports System.Text Imports System Public Class Form1 Friend Sub DoStuff() Handles Button1.Click MsgBox("Neat") ' Get active AutoCAD Application Dim app As Application = GetObject(, "AutoCAD.Application") ' Get active document Dim doc As Document = app.DocumentManager.MdiActiveDocument ' Create the database object Dim dwg As Database = doc.Editor.Document.Database ' Populate the selection set with objects that match the filter criteria Dim sel As SelectionSet = doc.Editor.SelectAll().Value ' Start a transaction Dim trans As Transaction = dwg.TransactionManager.StartTransaction ' Loop through each selected object in the selection set Dim entSet As New DBObjectCollection Try For Each selEnt As SelectedObject In sel Dim ent As Entity = trans.GetObject(selEnt.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite) Dim entType As String = ent.GetType.ToString Dim entArea Select Case ent.GetType.ToString Case "Autodesk.AutoCad.DatabaseServices.DBArc" Dim arcEnt As Arc = ent entArea = arcEnt.Area Case "Autodesk.AutoCad.DatabaseServices.DBCircle" Dim cirEnt As Circle = ent entArea = cirEnt.Area Case "Autodesk.AutoCad.DatabaseServices.DBEllipse" Dim eliEnt As Ellipse = ent entArea = eliEnt.Area Case "Autodesk.AutoCad.DatabaseServices.DBPolyline" Dim plyEnt As Polyline = ent entArea = plyEnt.Area Case "Autodesk.AutoCad.DatabaseServices.DBRegion" Dim regEnt As Region = ent entArea = regEnt.Area Case "Autodesk.AutoCad.DatabaseServices.DBSpline" Dim splEnt As Spline = ent entArea = splEnt.Area Case Else End Select Next Catch ex As Autodesk.AutoCAD.Runtime.Exception End Try End Sub End Class
It's simple. All I want to do is go to each entitiy in the drawing and find their area. I plan on combining the areas to show total area. But the program crashes before I can even get it to work. I have two warnings right now displaying, so those may be it.
Warning 1 Possible problem detected while building assembly 'TestTestTestTest': Referenced assembly 'mscorlib.dll' targets a different processor TestTestTestTest Warning 2 Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated. U:\settings\My Documents\Visual Studio 2010\Projects\TestTestTestTest\TestTestTestTest\Form1.vb 21 31 TestTestTestTest
Solved! Go to Solution.