Message 1 of 3

Not applicable
03-12-2015
06:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to pass an array of entities so that I can mirror them. At the moment, I can only do so with 1 entity at a time. Code below:
Imports System.Text Imports System.Linq Imports System.Xml Imports System.Reflection Imports System.ComponentModel Imports System.Collections Imports System.Collections.Generic Imports System.Windows Imports System.Windows.Media.Imaging Imports System.Windows.Forms Imports System.Drawing Imports System.IO Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.Windows Imports MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application Imports MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document Imports AcWindowsNS = Autodesk.AutoCAD.Windows Public Class MirrorJig Inherits EntityJig #Region "Fields" Public mCurJigFactorIndex As Integer = 1 Private m2ndPoint As New Point3d Private m1stPoint As Point3d #End Region #Region "Constructors" Public Sub New(ent As Entity, basePoint As Point3d) MyBase.New(ent) m1stPoint = basePoint.TransformBy(UCS) End Sub #End Region #Region "Properties" Private ReadOnly Property Editor() As Editor Get Return MgdAcApplication.DocumentManager.MdiActiveDocument.Editor End Get End Property Private ReadOnly Property UCS() As Matrix3d Get Return Editor.CurrentUserCoordinateSystem End Get End Property #End Region #Region "Overrides" Private mLastMat As Matrix3d = Matrix3d.Identity Protected Overrides Function Update() As Boolean Dim mat As Matrix3d = Matrix3d.Mirroring(New Line3d(m1stPoint, m2ndPoint)) Entity.TransformBy(mLastMat.Inverse().PostMultiplyBy(mat)) mLastMat = mat Return True End Function Protected Overrides Function Sampler(prompts As JigPrompts) As SamplerStatus Select Case mCurJigFactorIndex Case 1 Dim prOptions1 As New JigPromptPointOptions(vbLf & "The second point of the mirror line: ") prOptions1.UserInputControls = UserInputControls.GovernedByUCSDetect Or UserInputControls.UseBasePointElevation Or UserInputControls.Accept3dCoordinates prOptions1.BasePoint = m1stPoint Dim prResult1 As PromptPointResult = prompts.AcquirePoint(prOptions1) If prResult1.Status = PromptStatus.Cancel Then Return SamplerStatus.Cancel End If If prResult1.Value.Equals(m2ndPoint) Then Return SamplerStatus.NoChange Else m2ndPoint = prResult1.Value Return SamplerStatus.OK End If Case Else Exit Select End Select Return SamplerStatus.OK End Function #End Region #Region "Methods to Call" Public Shared Function Jig(ent As Entity, basePt As Point3d) As Boolean Dim jigger As MirrorJig = Nothing Try jigger = New MirrorJig(ent, basePt) Dim pr As PromptResult Do pr = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.Drag(jigger) ' Add keyword handling code below If pr.Status = PromptStatus.Keyword Then Else jigger.mCurJigFactorIndex += 1 End If Loop While pr.Status <> PromptStatus.Cancel AndAlso pr.Status <> PromptStatus.[Error] AndAlso jigger.mCurJigFactorIndex <= 1 If pr.Status = PromptStatus.Cancel OrElse pr.Status = PromptStatus.[Error] Then If jigger IsNot Nothing AndAlso jigger.Entity IsNot Nothing Then jigger.Entity.Dispose() End If Return False Else Return True End If Catch If jigger IsNot Nothing AndAlso jigger.Entity IsNot Nothing Then jigger.Entity.Dispose() End If Return False End Try End Function #End Region #Region "Test Commands" <CommandMethod("TestMirrorJigger")> _ Public Shared Sub TestMirrorJigger() Dim ed As Editor = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor Dim db As Database = HostApplicationServices.WorkingDatabase Try Dim selRes As PromptEntityResult = ed.GetEntity(vbLf & "Pick an entity:") Dim ptRes As PromptPointResult = ed.GetPoint(vbLf & "The first point of the mirror line: ") If selRes.Status = PromptStatus.OK AndAlso ptRes.Status = PromptStatus.OK Then Using tr As Transaction = db.TransactionManager.StartTransaction() Dim ent As Entity = TryCast(tr.GetObject(selRes.ObjectId, OpenMode.ForWrite), Entity) If ent IsNot Nothing Then Using tr1 As Transaction = db.TransactionManager.StartTransaction() ent.Highlight() tr1.Commit() End Using If MirrorJig.Jig(ent, ptRes.Value) Then tr.Commit() Else tr.Abort() End If End If End Using End If Catch ex As System.Exception ed.WriteMessage(ex.ToString()) End Try End Sub #End Region End Class
If I want to pass multiple entities I need to inherit DrawJig instead of EntityJig right? If that's the case, I would need to change quite a bit of stuff ... While also implementing WorldDraw...?
I'm kind of on the fence about this, not too sure how to approach the solution.
Solved! Go to Solution.