-
- <CommandMethod("twoarcs")> _
- Public Sub AddArcsOnLine()
- Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
- Dim ed As Editor = acDoc.Editor
- Dim db As Database = acDoc.Database
- Dim mtx As Matrix3d = ed.CurrentUserCoordinateSystem
- Dim ucs As CoordinateSystem3d = mtx.CoordinateSystem3d
- Try
- Using tr As Transaction = db.TransactionManager.StartTransaction
- Dim peo As New PromptEntityOptions(vbLf & "Select line >>")
- peo.SetRejectMessage(vbLf & "Selected is not a line>>")
- peo.AddAllowedClass(GetType(Line), False)
- Dim res As PromptEntityResult
- res = ed.GetEntity(peo)
- If res.Status <> PromptStatus.OK Then
- Return
- End If
- Dim ent As Entity = DirectCast(tr.GetObject(res.ObjectId, OpenMode.ForRead), Entity)
- If ent Is Nothing Then
- Return
- End If
- Dim lin As Line = Nothing
- If TypeOf ent Is Line Then
- lin = DirectCast(ent, Line)
- End If
- Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) '<-- get current space
- Dim plan As Plane = New Plane(Point3d.Origin, ucs.Zaxis)
- Dim p1 As Point3d = lin.StartPoint
- Dim p2 As Point3d = lin.EndPoint
- Dim ang = lin.Angle
- Dim mpt As Point3d = New Point3d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2)
- Dim cpt1 As Point3d = New Point3d((p1.X + mpt.X) / 2, (p1.Y + mpt.Y) / 2, (p1.Z + mpt.Z) / 2)
- Dim cpt2 As Point3d = New Point3d((mpt.X + p2.X) / 2, (mpt.Y + p2.Y) / 2, (mpt.Z + p2.Z) / 2)
- Dim arc1 As Arc = New Arc(cpt1, lin.GetDistAtPoint(cpt1), ang, Math.PI + ang)
- arc1.Normal = lin.Normal
- btr.AppendEntity(arc1)
- tr.AddNewlyCreatedDBObject(arc1, True)
- Dim arc2 As Arc = New Arc(cpt2, lin.GetDistAtPoint(cpt1), ang, Math.PI + ang)
- arc1.Normal = lin.Normal
- btr.AppendEntity(arc2)
- tr.AddNewlyCreatedDBObject(arc2, True)
- tr.Commit()
- End Using
- Catch ex As System.Exception
- Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(String.Format( _
- "ERROR: " & Environment.NewLine & "{0}" & Environment.NewLine _
- & "TRACE: " + Environment.NewLine + "{1}", ex.Message, ex.StackTrace))
- Finally
- 'do nothing
- End Try
- End Sub
|