<CommandMethod("teste")>
Public Sub teste()
Dim opf As New OpenFileDialog
opf.Filter = "JPG|*.jpg"
If opf.ShowDialog <> DialogResult.OK Then Exit Sub
Dim pprIns = ED.GetPoint(vbNewLine & "insert point")
If pprIns.Status <> PromptStatus.OK Then Exit Sub
Dim ppoX As New PromptPointOptions(vbNewLine & "x vector")
ppoX.UseBasePoint = True
ppoX.BasePoint = pprIns.Value
Dim pprX = ED.GetPoint(ppoX)
If pprX.Status <> PromptStatus.OK Then Exit Sub
Dim ppoY As New PromptPointOptions(vbNewLine & "y vector")
ppoY.UseBasePoint = True
ppoY.BasePoint = pprIns.Value
Dim pprY = ED.GetPoint(ppoY)
If pprY.Status <> PromptStatus.OK Then Exit Sub
Dim doc = DocumentManager.MdiActiveDocument
Using trans As Transaction = doc.TransactionManager.StartTransaction
Dim imageDictId As ObjectId = RasterImageDef.GetImageDictionary(DB)
If imageDictId.IsNull Then imageDictId = RasterImageDef.CreateImageDictionary(DB)
Dim dictName As String = New FileInfo(opf.FileName).Name
Dim imageDef As RasterImageDef
Dim imageDefId As ObjectId
Dim imageDict As DBDictionary = imageDictId.GetObject(ForWrite)
If imageDict.Contains(dictName) Then
imageDefId = imageDict.GetAt(dictName)
imageDef = trans.GetObject(imageDefId, ForWrite)
Else
imageDict.UpgradeOpen()
imageDef = New RasterImageDef()
imageDefId = imageDict.SetAt(dictName, imageDef)
imageDef.SourceFileName = opf.FileName
imageDef.Load()
trans.AddNewlyCreatedDBObject(imageDef, True)
End If
Dim image As New RasterImage()
image.ImageDefId = imageDefId
image.Orientation = New CoordinateSystem3d(pprIns.Value, pprIns.Value.GetVectorTo(pprX.Value), pprIns.Value.GetVectorTo(pprY.Value))
' image.ImageTransparency = True
#If Not (CAD_2007 Or GSTAR Or ZwCAD) Then
image.ShowImage = True
#End If
Dim bt As BlockTable = trans.GetObject(DB.BlockTableId, ForRead)
Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), ForWrite)
btr.AppendEntity(image)
trans.AddNewlyCreatedDBObject(image, True)
#If Not (GSTAR Or ZWCAD Or BRCAD) Then
RasterImage.EnableReactors(True)
#End If
#If Not ZWCAD Then
image.AssociateRasterDef(imageDef)
#End If
trans.Commit()
End Using
End Sub