代码在这里
Public Class Jig_CCopy
Inherits DrawJig
Dim sourcePt, targetPt, curPt As Point3d
Dim keyword As String
Dim i, k, few As Integer
Dim entCopy (,), entCopy1 (), oldEnt () As Entity, ids As ObjectId ()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Sub testCCopy ()
keyword = "C"
Dim res As PromptSelectionResult
Dim sSet As SelectionSet
Dim opt As New PromptSelectionOptions
res = ed.SelectImplied()
If res.Status = PromptStatus.OK Then
sSet = res.Value
ids = sSet.GetObjectIds()
Else
opt.MessageForAdding = "请选择对象:"
opt.AllowDuplicates = True
res = ed.GetSelection(opt)
If res.Status PromptStatus.OK Then Return
sSet = res.Value
ids = sSet.GetObjectIds()
End If
Dim optPoint As New PromptPointOptions(vbCrLf & "请输入基点:" )
optPoint.AllowNone = True
Dim resPoint As PromptPointResult = ed.GetPoint(optPoint)
If resPoint.Status PromptStatus.OK Then Return
sourcePt = resPoint.Value
ReDim entCopy1 (ids.Length - 1 )
ReDim oldEnt (ids.Length - 1 )
Using trans As Transaction = db.TransactionManager.StartTransaction()
For i = 0 To ids.Length - 1
oldEnt(i) = trans.GetObject(ids(i), OpenMode.ForWrite)
Next
trans.Commit ()
End Using
Dim lop As Boolean = True
Do While lop = True
For i = 0 To ids.Length - 1
oldEnt (i).Highlight ()
entCopy1(i) = oldEnt(i).Clone ()
Next
targetPt = sourcePt
curPt = targetPt
Dim jigRes As PromptResult = ed.Drag(Me )
If jigRes.Status = PromptStatus.OK Then
For i = 0 To ids.Length - 1
AppendEntity (entCopy1(i))
Next
ElseIf keyword = "A" Then
targetPt = sourcePt
curPt = targetPt
jigRes = ed.Drag(Me)
If jigRes.Status = PromptStatus.OK Then
For k = 0 To few - 1
For i = 0 To ids.Length - 1
AppendEntity (entCopy(k, i))
Next
Next
For i = 0 To ids.Length - 1
oldEnt (i).Unhighlight ()
Next
lop = False
ElseIf keyword = "F" Then
targetPt = sourcePt
curPt = targetPt
jigRes = ed.Drag(Me)
If jigRes.Status = PromptStatus.OK Then
For k = 0 To few - 1
For i = 0 To ids.Length - 1
AppendEntity (entCopy(k, i))
Next
Next
For i = 0 To ids.Length - 1
oldEnt (i).Unhighlight ()
Next
lop = False
Else
lop = False
For i = 0 To ids.Length - 1
oldEnt (i).Unhighlight ()
Next
End If
Else
lop = False
For i = 0 To ids.Length - 1
oldEnt (i).Unhighlight ()
Next
End If
Else
lop = False
For i = 0 To ids.Length - 1
oldEnt (i).Unhighlight ()
Next
End If
Loop
End Sub
Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus
If keyword = "C" Then
Dim optJig As New JigPromptPointOptions(vbCrLf & "请指定第二点[阵列(A)]:" )
optJig.Cursor = CursorType.RubberBand
optJig.BasePoint = sourcePt
optJig.UseBasePoint = True
optJig.Keywords.Add("A" , "A" , "A" , False , True )
'optJig .Keywords.Add ("C" , "C" , "C" , False, True)
'' 默认关键字
'optJig .Keywords.Default = "C"
Dim resJig As PromptPointResult = prompts.AcquirePoint(optJig)
targetPt = resJig.Value
If resJig.Status = PromptStatus.Keyword Then
keyword = "A"
Dim optfew As New PromptIntegerOptions(vbCrLf & "请输入等分数量" )
Dim resfew As PromptIntegerResult = ed.GetInteger(optfew)
If resfew.Status PromptStatus.OK Then Return True
few = resfew.Value
ReDim entCopy (0 To few - 1 , ids.Length - 1 )
For k = 0 To few - 1
For i = 0 To ids.Length - 1
entCopy(k, i) = oldEnt(i).Clone ()
Next
Next
Else
If curPt targetPt Then
Dim moveMt As Matrix3d = Matrix3d.Displacement(targetPt - curPt)
For i = 0 To ids.Length - 1
entCopy1 (i).TransformBy (moveMt)
Next
curPt = targetPt
Return SamplerStatus.OK
Else
Return SamplerStatus.NoChange
End If
End If
ElseIf keyword = "A" Then
Dim optJig As New JigPromptPointOptions(vbCrLf & "请指定第二点[布满(F)]:" )
optJig.Cursor = CursorType.RubberBand
optJig.BasePoint = sourcePt
optJig.UseBasePoint = True
optJig.Keywords.Add("F" , "F" , "F" , False , True )
'optJig .Keywords.Add ("C" , "C" , "C" , False, True)
'' 默认关键字
'optJig .Keywords.Default = "C"
Dim resJig As PromptPointResult = prompts.AcquirePoint(optJig)
targetPt = resJig.Value
If resJig.Status = PromptStatus.Keyword Then
keyword = "F"
For k = 0 To few - 1
For i = 0 To ids.Length - 1
entCopy(k, i) = oldEnt(i).Clone ()
Next
Next
Else
If curPt targetPt Then
'Dim moveMt As Matrix3d = Matrix3d.Displacement ((targetPt - curPt) / few * (k + 1 ))
For k = 0 To few - 1
For i = 0 To ids.Length - 1
entCopy (k, i).TransformBy (Matrix3d.Displacement((targetPt - curPt) * (k + 1 )))
Next
Next
curPt = targetPt
Return SamplerStatus.OK
Else
Return SamplerStatus.NoChange
End If
End If
ElseIf keyword = "F" Then
Dim optJig As New JigPromptPointOptions(vbCrLf & "请指定第二点:" )
optJig.Cursor = CursorType.RubberBand
optJig.BasePoint = sourcePt
optJig.UseBasePoint = True
Dim resJig As PromptPointResult = prompts.AcquirePoint(optJig)
targetPt = resJig.Value
If curPt targetPt Then
'Dim moveMt As Matrix3d = Matrix3d.Displacement ((targetPt - curPt) / few * (k + 1 ))
For k = 0 To few - 1
For i = 0 To ids.Length - 1
entCopy(k, i ).TransformBy (Matrix3d.Displacement ((targetPt - curPt) / few * (k + 1 )))
Next
Next
curPt = targetPt
Return SamplerStatus.OK
Else
Return SamplerStatus.NoChange
End If
End If
End Function
Protected Overrides Function WorldDraw(ByVal draw As WorldDraw) As Boolean
If keyword = "C" Then
For i = 0 To ids.Length - 1
draw.Geometry .Draw (entCopy1(i ))
Next
Else
For k = 0 To few - 1
For i = 0 To ids.Length - 1
draw.Geometry .Draw (entCopy(k, i ))
Next
Next
End If
Return True
End Function
Public Shared Function AppendEntity(ByVal ent As Entity) As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim entId As ObjectId
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
entId = btr.AppendEntity(ent)
trans.AddNewlyCreatedDBObject(ent, True )
trans.Commit ()
End Using
Return entId
End Function
End Class