ThisDrawing.ModelSpace.AddRaster(ImageFileName, InsertPoint, ScaleFactor, RotAngle)
http://bbs.xdcad.net/thread-709228-1-1.html
[本日志由 tiancao1001 于 2017-07-04 06:44 PM 编辑]
|
tiancao1001 于 2017-07-04 06:44 PM 发表评论:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Using db As Database = doc.Database
Using tm As Transaction = db.TransactionManager.StartTransaction()
Try
Dim imageDictID As ObjectId = RasterImageDef.GetImageDictionary(db)
If imageDictID.OldId = 0 Then
imageDictID = RasterImageDef.CreateImageDictionary(db)
End If
Dim rasterImageDef__1 As New RasterImageDef()
Dim imageDict As DBDictionary = CType(tm.GetObject(imageDictID, OpenMode.ForWrite), DBDictionary)
Dim rasterImageDefID As ObjectId
If imageDict.Contains(bname) Then
rasterImageDefID = imageDict.GetAt(bname)
rasterImageDef__1 = CType(tm.GetObject(rasterImageDefID, OpenMode.ForWrite), RasterImageDef)
Else
rasterImageDefID = imageDict.SetAt(bname, rasterImageDef__1)
rasterImageDef__1.SourceFileName = fname
rasterImageDef__1.Load()
rasterImageDef__1.ImageModified = True
rasterImageDef__1.ResolutionUnits = Unit.Millimeter
tm.AddNewlyCreatedDBObject(rasterImageDef__1, True)
End If
Dim rasterImage As New RasterImage()
rasterImage.ImageDefId = rasterImageDef__1.ObjectId
rasterImage.Orientation = New CoordinateSystem3d(pt, New Vector3d(xx, 0, 0), New Vector3d(0, yy, 0))
rasterImage.Rotation = (rot * pi) / 180
Dim bt As BlockTable = CType(tm.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, False), BlockTable)
Dim btr As BlockTableRecord = CType(tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord)
btr.AppendEntity(rasterImage)
tm.AddNewlyCreatedDBObject(rasterImage, True)
tm.Commit()
tm.Dispose()
Catch e As System.Exception
System.Windows.Forms.MessageBox.Show(e.ToString())
End Try
End Using
End Using
End Sub
tiancao1001 于 2017-07-04 06:34 PM 发表评论:
ThisDrawing.ModelSpace.AddRaster(ImageFileName, InsertPoint, ScaleFactor, RotAngle)