I have code that works fine if the UCS is set to TOP. The way my code is supposed to work is, you select entities that you want to make up the block, and it keeps the entities positions in the drawing. If the UCS is changed to anything but TOP, when the block is created in the drawing it is moved to another place in the drawing. Would it make sense to change the UCS to TOP when the user runs the command or is there a better way to do this? Here is the code I am working with. Thank you.
-Ted
Function CreateABlock(ByVal pos As Point3d, ByVal blname As String) As ObjectId
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim newBtrId As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase()
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
Dim res As PromptSelectionResult = ed.GetSelection
Dim oid As New ObjectIdCollection(res.Value.GetObjectIds())
Dim pt As Point3d = pos.TransformBy(ed.CurrentUserCoordinateSystem)
If res.Status = PromptStatus.OK Then
Try
Dim newBtr As BlockTableRecord = New BlockTableRecord()
newBtr.Name = blname
newBtrId = bt.Add(newBtr)
trans.AddNewlyCreatedDBObject(newBtr, True)
For Each id In res.Value.GetObjectIds()
Dim ent = TryCast(trans.GetObject(id, OpenMode.ForRead), Entity)
If ent <> Nothing Then
Dim newent = TryCast(ent.Clone(), Entity)
If newent <> Nothing Then
End If
End If
Next
Dim disp As Vector3d = pt.GetVectorTo(Point3d.Origin)
For Each id As ObjectId In oid
Dim ent As Entity = DirectCast(trans.GetObject(id, OpenMode.ForWrite), Entity)
ent.TransformBy(Matrix3d.Displacement(disp))
Next
newBtr.AssumeOwnershipOf(oid)
Catch ex As System.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbLf & ex.StackTrace)
trans.Dispose()
End Try
End If
End If
trans.Commit()
End Using
Return newBtrId
End Function