Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop
Namespace Test
Public Class MyCommands
'<CommandMethod("Test", CommandFlags.Session)> _
' Убрал CommandFlags.Session
<CommandMethod("Test")> _
Public Sub MyMain()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using myTrans As Transaction = db.TransactionManager.StartTransaction()
Using LockDoc As DocumentLock = doc.LockDocument()
Dim bt As BlockTable = myTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = myTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
'' создаем Solid3d -клин
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Wedge As Solid3d = New Solid3d()
Wedge.CreateWedge(10, 15, 20)
Wedge.ColorIndex = 1
btr.AppendEntity(Wedge)
myTrans.AddNewlyCreatedDBObject(Wedge, True)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
LayoutManager.Current.CurrentLayout = "Layout1"
Dim PVpCenter(0 To 2) As Double, PVpWidth As Double = 200, PVpheight As Double = 150
PVpCenter(0) = 142 : PVpCenter(1) = 110
' создаем обьект Viewport
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim PSbtr As BlockTableRecord = myTrans.GetObject(bt(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
Using PVportObj As Viewport = New Viewport()
PVportObj.CenterPoint = New Point3d(PVpCenter) : PVportObj.Width = PVpWidth : PVportObj.Height = PVpheight
PSbtr.AppendEntity(PVportObj) : myTrans.AddNewlyCreatedDBObject(PVportObj, True)
PVportObj.ViewDirection = New Vector3d(1, -1, 0.5) ' изменяем направление взгляда
PVportObj.On = True
doc.Editor.SwitchToModelSpace()
End Using
Call Zoom(pMin:=Wedge.Bounds.Value.MinPoint, pMax:=Wedge.Bounds.Value.MaxPoint, Centr:=New Point3d(), SFactor:=4) 'зуммируем клин
Dim res As PromptSelectionResult = doc.Editor.SelectAll ' выбираем все
' выполняем команду solprof
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim App As AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
Dim myDoc As AcadDocument = App.ActiveDocument
'myDoc.SendCommand("_solprof" & vbCr & "_Previous" & vbCr & vbCr & "_Y" & vbCr & "_Y" & vbCr & "_N" & vbCr)
' Заменил myDoc.SendCommand на Editor.Command
Dim ed As Editor = doc.Editor
ed.Command("_solprof", "_Previous", "", "_Y", "_Y", "_N")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
res = doc.Editor.SelectAll ' опять выбираем все
Dim n As Integer = 0, blockObj1 As BlockReference = Nothing, blockObj2 As BlockReference = Nothing
For Each id As ObjectId In res.Value.GetObjectIds() 'определяем блоки на слоях PV и PH
Dim ent As Entity = myTrans.GetObject(id, OpenMode.ForWrite, True)
If Left(ent.Layer, 2) = "PV" Then blockObj1 = ent 'блок видимых линий
If Left(ent.Layer, 2) = "PH" Then blockObj2 = ent : n = 1 'блок невидимых линий
Next id
'удаляем блок невидимых линий
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If n <> 0 Then blockObj2.Erase()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' уводим клин в сторону
Wedge.TransformBy(Matrix3d.Displacement(New Point3d(0, 0, 0).GetVectorTo(New Point3d(30, 0, 0))))
End Using
myTrans.Commit()
End Using
End Sub
Public Sub Zoom(ByVal pMin As Point3d, ByVal pMax As Point3d, ByVal Centr As Point3d, ByVal SFactor As Double)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim Db As Database = doc.Database
Using acTrans As Transaction = Db.TransactionManager.StartTransaction()
Using myView As ViewTableRecord = doc.Editor.GetCurrentView()
Dim dWidth As Double, dHeight As Double, CentPt As Point2d
dWidth = pMax.X - pMin.X
dHeight = pMax.Y - pMin.Y
CentPt = New Point2d(((pMax.X + pMin.X) / 2), ((pMax.Y + pMin.Y) / 2))
myView.Height = dHeight * SFactor : myView.Width = dWidth * SFactor
myView.CenterPoint = CentPt
doc.Editor.SetCurrentView(myView)
End Using
acTrans.Commit()
End Using
End Sub
End Class
End Namespace