Code: Select all
Public Sub teste()
Dim doc As Document = IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim Col As New Collection
Using tr As Transaction = IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction
Dim vt As ViewTable = tr.GetObject(db.ViewTableId, Teigha.DatabaseServices.OpenMode.ForRead)
For Each vti In vt
Dim vtr As ViewTableRecord = TryCast(tr.GetObject(vti, Teigha.DatabaseServices.OpenMode.ForRead), ViewTableRecord)
If Not IsNothing(vtr) Then
Col.Add(vtr)
End If
Next
Dim aView As ViewTableRecord = tr.GetObject(Col(1).objectid, Teigha.DatabaseServices.OpenMode.ForRead)
Dim fileDia As New IntelliCAD.Windows.SaveFileDialog(
"Open an Image file", Nothing,
"jpg; gif; tif; bmp", "Image File",
IntelliCAD.Windows.
OpenFileDialog.OpenFileDialogFlags.NoUrls)
' Show the dialog and test the result
Dim res As System.Windows.Forms.DialogResult =
fileDia.ShowDialog()
If res <> System.Windows.Forms.DialogResult.OK Then Return
aView.Thumbnail.Save(fileDia.Filename)
Dim Raster As New RasterImageDef
Raster.SourceFileName = "bitMarTemp"
Raster.Load()
Dim imageDictId As ObjectId =
RasterImageDef.GetImageDictionary(db)
If imageDictId.IsNull Then
' Image dictionary doesn't exist, create new
imageDictId = RasterImageDef.CreateImageDictionary(db)
End If
Dim imageDict As DBDictionary = tr.GetObject(
imageDictId, Teigha.DatabaseServices.OpenMode.ForRead)
Dim imageDef As RasterImageDef
Dim imageDefId As ObjectId
Dim dictName As String = "IMAGE"
imageDef = New RasterImageDef()
' And set its source image
imageDef.SourceFileName = "bitMarTemp" 'fileDia.Filename()
' finally load it
imageDef.Load()
imageDict.UpgradeOpen()
imageDefId = imageDict.SetAt(dictName, imageDef)
tr.AddNewlyCreatedDBObject(imageDef, True)
' Now create the raster image that references the definition
Dim image As New RasterImage()
image.ImageDefId = imageDefId
Dim X = "353917.0678034420"
Dim Y = "398701.9004743111"
Dim uCorner As New Vector3d(366, 0, 0)
Dim vOnPlane As New Vector3d(0, 278, 0)
Dim point As New Point3d(X, Y, 0.0)
Dim coordinateSystem As New CoordinateSystem3d(point, uCorner, vOnPlane)
image.Orientation = coordinateSystem
' And some other properties
image.ImageWidth.ToString(366)
image.ImageHeight.ToString(278)
image.ImageTransparency = True
image.ShowImage = True
' Add the image to ModelSpace
Dim bt As BlockTable = tr.GetObject(db.BlockTableId, Teigha.DatabaseServices.OpenMode.ForRead)
Dim msBtr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), Teigha.DatabaseServices.OpenMode.ForWrite)
msBtr.AppendEntity(image)
tr.AddNewlyCreatedDBObject(image, True)
RasterImage.EnableReactors(True)
image.AssociateRasterDef(imageDef)
Dim jigger As New EntitiesJig.AcadNetAddinCS.MoveRotationScaleJig
jigger.AddEntity(image)
jigger.Jig()
tr.Commit()
End Using
'Dim img = IntelliCAD.Internal.Utils.CreateIcon(vtr, width - 120, height, Color.White)
End Sub
Also, line code :
Dim fileDia As New IntelliCAD.Windows.SaveFileDialog(
"Open an Image file", Nothing,
"jpg; gif; tif; bmp", "Image File",
IntelliCAD.Windows.
OpenFileDialog.OpenFileDialogFlags.NoUrls)
Causes this problem.
Code line "aView.Thumbnail.Save(fileDia.Filename)" generates an error because aView.thumbnail is set to nothing.
I am trying to generate a Bitmap os predefined Views inside DWg PaperSpace file ... after that I'll try to produce a commandMethod to insert View inside Drawing PS just by two clicks.
First of all need to collect information about view and generate BitMap to user drag and drop over screen of any PS drawing. I am trying to use raster image to insert at PS 0,0,0 and then using JigEntity to user drag it around the DWG screen.
After user click at any place, information collected before will be used to append Xref file and creates ViewPort (PaperSpace)