Author Topic: Creating a Block of a Raster Image  (Read 2097 times)

0 Members and 1 Guest are viewing this topic.

johne

  • Mosquito
  • Posts: 5
Creating a Block of a Raster Image
« on: January 19, 2015, 09:46:23 PM »
Can anyone point me in the right direction on how to create a block of a raster image?
I've managed to attach the image using the sample code on the autocad developer guide below

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-00A0BCD9-4519-4746-BC73-88544D75D789

But now I'm having some trouble now creating a block of this raster image.
I understand the process of adding other entities to a block, but I cant get my head around RasterImage and RasterImageDef.

Ultimately I'm looking to be able to scale the height and width of the block independently, something an image doesn't allow without converting to a block first.

Thanks in advance.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Creating a Block of a Raster Image
« Reply #1 on: January 20, 2015, 07:38:39 AM »
The width and height is set in the RasterImage.Orientation property.  I don't think you can include an image in a block, Images are kinda like Xrefs.
Revit 2019, AMEP 2019 64bit Win 10

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Creating a Block of a Raster Image
« Reply #2 on: January 20, 2015, 08:45:31 AM »
I'm not sure if this can be done with the API, though it is possible in AutoCAD.

If you attach an image to a new drawing, and save the drawing, then you can insert that drawing in another drawing as block. The image is shown correctly.

Because it is a block, it is also possible to scale independently.

If it is not possible to add the RasterImage to a block, you might put the image in a new database and save that as an external block.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

kaefer

  • Guest
Re: Creating a Block of a Raster Image
« Reply #3 on: January 20, 2015, 03:37:17 PM »
I'm not sure if this can be done with the API, though it is possible in AutoCAD.

If it's possible in AutoCAD, it's moderately likely to be possible with the API. You can certainly add a raster image to a block, as evidenced as f#ollows.

Code - F#: [Select]
  1. open Autodesk.AutoCAD.DatabaseServices
  2. open Autodesk.AutoCAD.EditorInput
  3. open Autodesk.AutoCAD.Geometry
  4. type acApp = Autodesk.AutoCAD.ApplicationServices.Application
  5.  
  6. // Command creates an anonymous block and adds raster image to it
  7. [<Autodesk.AutoCAD.Runtime.CommandMethod "RASBLK">]
  8. let RasBlk () =
  9.     let doc = acApp.DocumentManager.MdiActiveDocument
  10.     let ed = doc.Editor
  11.     let db = doc.Database
  12.  
  13.     // Select Raster Image
  14.     let opt = new PromptEntityOptions("Select Raster Image")
  15.     opt.SetRejectMessage "Only Raster Image allowed "
  16.     opt.AddAllowedClass(typeof<RasterImage>, true)
  17.     let res = ed.GetEntity opt
  18.     if res.Status = PromptStatus.OK then
  19.         use tr = db.TransactionManager.StartTransaction()
  20.  
  21.         // Create BlockTableRecord
  22.         let bt =
  23.             db.BlockTableId.GetObject OpenMode.ForWrite
  24.                 :?> BlockTable
  25.         use btr =
  26.             new BlockTableRecord(
  27.                 Origin = Point3d.Origin,
  28.                 Name = "*U" )
  29.         let btrId = bt.Add btr
  30.         tr.AddNewlyCreatedDBObject(btr, true)
  31.  
  32.         // Add object to block
  33.         let oidc = new ObjectIdCollection[| res.ObjectId |]
  34.         btr.AssumeOwnershipOf oidc
  35.  
  36.         // Create BlockReference for the new block
  37.         use br =
  38.             new BlockReference(
  39.                 Point3d.Origin,
  40.                 btrId )
  41.         let mspace =
  42.             SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject OpenMode.ForWrite
  43.                 :?> BlockTableRecord
  44.         mspace.AppendEntity br |> ignore
  45.         tr.AddNewlyCreatedDBObject(br, true)
  46.  
  47.         tr.Commit()

johne

  • Mosquito
  • Posts: 5
Re: Creating a Block of a Raster Image
« Reply #4 on: January 21, 2015, 06:35:18 PM »
Thanks Kaefer,
The AssumeOwnershipOf method was what I was looking for. Using the BlockReference ScaleFactors method I was able to independently set the X, Y (and Z) scales, ultimately this allowed me to convert some georeferenced imagery from nearmap to our local project grid.