Skip to content

Instantly share code, notes, and snippets.

@eibre
Created June 8, 2021 20:57
Show Gist options
  • Save eibre/7f7f0f9d964589ff8d9459906ef88afe to your computer and use it in GitHub Desktop.
Save eibre/7f7f0f9d964589ff8d9459906ef88afe to your computer and use it in GitHub Desktop.
Revit macro to get an image from clipboard an paste it to a selected position in the active view
public void PasteImage(){
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
string path = @"C:\dev\pasted\image.jpeg";
if(Clipboard.ContainsImage()) {
Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else {
TaskDialog.Show("Error:", "No image on clipoboard");
return;
}
XYZ imageLocation = uidoc.Selection.PickPoint("Pick insertion point (midpoint)");
using(Transaction t1 = new Transaction(doc, "paste image")) {
t1.Start();
ImageTypeOptions opt = new ImageTypeOptions(path, false, ImageTypeSource.Import);
ImagePlacementOptions pOpt = new ImagePlacementOptions();
pOpt.Location = imageLocation;
pOpt.PlacementPoint = BoxPlacement.Center;
ImageType imageType = ImageType.Create(doc, opt);
ImageInstance.Create(doc, doc.ActiveView, imageType.Id, pOpt );
t1.Commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment