Author Topic: bricscad 2016 64bits insert image  (Read 1972 times)

0 Members and 1 Guest are viewing this topic.

neyton

  • Newt
  • Posts: 68
bricscad 2016 64bits insert image
« on: March 03, 2016, 01:24:24 PM »
I try to implement this code :

http://adndevblog.typepad.com/autocad/2012/05/how-to-insert-a-rasterimage-using-the-net-api.html

On AutoCAD, works fine.

But, on bricscad 2016 64bits...

Visit my website: http://tbn2.blogspot.com

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: bricscad 2016 64bits insert image
« Reply #1 on: March 04, 2016, 09:33:33 PM »
it works,
there's an order issue, I think you need to set database defaults to imageDef after
imageDef = New RasterImageDef()

or move
 imageDefId = imageDict.SetAt(dictName, imageDef)
just after
 imageDef = New RasterImageDef()
« Last Edit: March 04, 2016, 09:40:32 PM by nullptr »

neyton

  • Newt
  • Posts: 68
Re: bricscad 2016 64bits insert image
« Reply #2 on: March 07, 2016, 12:46:46 PM »
Hi,

works, but if rotate image, it not show:



Code - Visual Basic: [Select]
  1. <CommandMethod("teste")>
  2.     Public Sub teste()
  3.         Dim opf As New OpenFileDialog
  4.         opf.Filter = "JPG|*.jpg"
  5.         If opf.ShowDialog <> DialogResult.OK Then Exit Sub
  6.  
  7.         Dim pprIns = ED.GetPoint(vbNewLine & "insert point")
  8.         If pprIns.Status <> PromptStatus.OK Then Exit Sub
  9.  
  10.         Dim ppoX As New PromptPointOptions(vbNewLine & "x vector")
  11.         ppoX.UseBasePoint = True
  12.         ppoX.BasePoint = pprIns.Value
  13.         Dim pprX = ED.GetPoint(ppoX)
  14.         If pprX.Status <> PromptStatus.OK Then Exit Sub
  15.  
  16.  
  17.         Dim ppoY As New PromptPointOptions(vbNewLine & "y vector")
  18.         ppoY.UseBasePoint = True
  19.         ppoY.BasePoint = pprIns.Value
  20.         Dim pprY = ED.GetPoint(ppoY)
  21.         If pprY.Status <> PromptStatus.OK Then Exit Sub
  22.  
  23.         Dim doc = DocumentManager.MdiActiveDocument
  24.  
  25.         Using trans As Transaction = doc.TransactionManager.StartTransaction
  26.  
  27.             Dim imageDictId As ObjectId = RasterImageDef.GetImageDictionary(DB)
  28.  
  29.             If imageDictId.IsNull Then imageDictId = RasterImageDef.CreateImageDictionary(DB)
  30.  
  31.             Dim dictName As String = New FileInfo(opf.FileName).Name
  32.             Dim imageDef As RasterImageDef
  33.             Dim imageDefId As ObjectId
  34.  
  35.             Dim imageDict As DBDictionary = imageDictId.GetObject(ForWrite)
  36.  
  37.             If imageDict.Contains(dictName) Then
  38.                 imageDefId = imageDict.GetAt(dictName)
  39.                 imageDef = trans.GetObject(imageDefId, ForWrite)
  40.             Else
  41.                 imageDict.UpgradeOpen()
  42.                 imageDef = New RasterImageDef()
  43.                 imageDefId = imageDict.SetAt(dictName, imageDef)
  44.                 imageDef.SourceFileName = opf.FileName
  45.                 imageDef.Load()
  46.                 trans.AddNewlyCreatedDBObject(imageDef, True)
  47.             End If
  48.  
  49.             Dim image As New RasterImage()
  50.             image.ImageDefId = imageDefId
  51.  
  52.             image.Orientation = New CoordinateSystem3d(pprIns.Value, pprIns.Value.GetVectorTo(pprX.Value), pprIns.Value.GetVectorTo(pprY.Value))
  53.  
  54.             ' image.ImageTransparency = True
  55. #If Not (CAD_2007 Or GSTAR Or ZwCAD) Then
  56.             image.ShowImage = True
  57. #End If
  58.  
  59.             Dim bt As BlockTable = trans.GetObject(DB.BlockTableId, ForRead)
  60.             Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), ForWrite)
  61.             btr.AppendEntity(image)
  62.             trans.AddNewlyCreatedDBObject(image, True)
  63.  
  64. #If Not (GSTAR Or ZWCAD Or BRCAD) Then
  65.             RasterImage.EnableReactors(True)
  66. #End If
  67.  
  68. #If Not ZWCAD Then
  69.             image.AssociateRasterDef(imageDef)
  70. #End If
  71.  
  72.             trans.Commit()
  73.         End Using
  74.     End Sub
  75.  
Visit my website: http://tbn2.blogspot.com