Hi there,
My problem is as follows, my code below is for working out
the width of each object in a selection set. I have added a
line just to illustrate the measured section of each object.
I basically want to use these widths, else-where in my commeand, in
a collection. Or outside of the “for each”. For comparison
to each other
Is this possible or am I going about it in the wrong way?
Thanks,
Martin..
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Public Class lng
_
Public Sub lng()
'' Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
' For Each
For Each acSSObj As SelectedObject In acSSet
If Not IsDBNull(acSSObj) Then
Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite)
If Not IsDBNull(acEnt) Then
'' Draw Rectangles
Dim myExtents As Extents3d = (acEnt.GeometricExtents)
Dim P1 As Point3d = myExtents.MaxPoint
Dim P3 As Point3d = myExtents.MinPoint
Dim P2 As New Point3d(P3.X, P1.Y, 0)
Dim P4 As New Point3d(P1.X, P3.Y, 0)
' Draw Measure Line for Each object
Dim DimPCol As New Point3dCollection
DimPCol.Add(P1)
DimPCol.Add(P2)
Dim myPLine2 As New Polyline2d(Poly2dType.SimplePoly, DimPCol, 0, True, 0, 0, Nothing)
myPLine2.ColorIndex = 2 '1=Yellow 2=Red 3=Green 4=Cyan 5=Blue 6=Purple 7=White
' Get length of each line
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
btr.AppendEntity(myPLine2)
tr.AddNewlyCreatedDBObject(myPLine2, True)
tr.Commit()
End If
End If
Next
acTrans.Commit()
End If
End Using
End Sub
End Class
Edited by: quigs on Dec 20, 2009 12:01 PM
My name is Martin.. 😄