Ejemplo n.º 1
0
        /// <summary>
        /// Collect the parameters and export
        /// </summary>
        /// <returns></returns>
        public override bool Import()
        {
            using (Transaction t = new Transaction(m_activeDoc))
            {
                t.SetName("Import");
                t.Start();

                // Step 1: Create an ImageType
                //ImageTypeOptions specify the source of the image
                // If the source is a PDF file then ImageTypeOptions can be used to:
                //   - Select a specific page from the PDF
                //   - Select a Resolution (in dots-per-inch) at which to rasterize the PDF
                // For other image types the page number should be 1, and the resolution is only used to determine the size of the image

                ImageTypeOptions typeOptions = new ImageTypeOptions(m_importFileFullName);
                ImageType        imageType   = ImageType.Create(m_activeDoc, typeOptions);

                // Step 2: Create an ImageInstance, but only if the active view is able to contain images.
                View view = CommandData.Application.ActiveUIDocument.Document.ActiveView;
                if (ImageInstance.IsValidView(view))
                {
                    // ImagePlacementOptions
                    ImagePlacementOptions placementOptions = new ImagePlacementOptions();
                    placementOptions.PlacementPoint = Autodesk.Revit.DB.BoxPlacement.TopLeft;
                    placementOptions.Location       = new XYZ(1, 1, 1);

                    ImageInstance imageInstance = ImageInstance.Create(m_activeDoc, view, imageType.Id, placementOptions);
                }

                t.Commit();
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Collect the parameters and export
        /// </summary>
        /// <returns></returns>
        public override bool Import()
        {
            using (Transaction t = new Transaction(m_activeDoc))
            {
                t.SetName("Import");
                t.Start();

                // Step 1: Create an ImageType
                //ImageTypeOptions specifies the source of the image, and how to create the ImageType.
                // It can be used to specify:
                //   - The image file.  Either as a local file path, or as an ExternalResourceRef
                //   - Whether to store the local file path as an absolute path or a relative path.
                //   - Whether to create an Import or a Link image.
                // In addition, if the source is a PDF file, then ImageTypeOptions can be used to specify:
                //   - which page from the PDF to use
                //   - the resolution (in dots-per-inch) at which to rasterize the PDF
                // For other image types the page number should be 1 (the default),
                // and the resolution is only used to determine the size of the image.

                ImageTypeOptions typeOptions = new ImageTypeOptions(m_importFileFullName, true, ImageTypeSource.Import);
                ImageType        imageType   = ImageType.Create(m_activeDoc, typeOptions);

                // Step 2: Create an ImageInstance, but only if the active view is able to contain images.
                View view = CommandData.Application.ActiveUIDocument.Document.ActiveView;
                if (ImageInstance.IsValidView(view))
                {
                    // ImagePlacementOptions
                    ImagePlacementOptions placementOptions = new ImagePlacementOptions();
                    placementOptions.PlacementPoint = Autodesk.Revit.DB.BoxPlacement.TopLeft;
                    placementOptions.Location       = new XYZ(1, 1, 1);

                    ImageInstance imageInstance = ImageInstance.Create(m_activeDoc, view, imageType.Id, placementOptions);
                }

                t.Commit();
            }

            return(true);
        }
Ejemplo n.º 3
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            string Path          = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string ImageFileName = "GitHub\\TokyoAECIndustryDevGroup-Revit\\TokyoAECDev.extension\\TokyoAECDev.tab\\cstest.panel\\OgreCall.pushbutton\\Image\\Ogre.jpg";

            string ImagePath = Path + "\\" + ImageFileName;

            ImagePlacementOptions Opt = new ImagePlacementOptions();

            // Create View

            ViewSheet vs = null;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create View");
                vs      = ViewSheet.Create(doc, ElementId.InvalidElementId);
                vs.Name = "Ogre";
                ImageType     IT           = ImageType.Create(doc, ImagePath);
                ImageInstance ImageonSheet = ImageInstance.Create(doc, vs, IT.Id, Opt);

                Guid   schemaGuid = new Guid("67DA32DE-E851-4DAD-B5EA-5450897DBFF0");
                Schema schema     = Schema.Lookup(schemaGuid);

                if (schema == null)
                {
                    SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);

                    schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                    schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
                    schemaBuilder.SetVendorId("TokyoAECIndustryDevGroup");
                    schemaBuilder.SetSchemaName("OgreSample");
                    schemaBuilder.SetDocumentation("Sheet & ImageInstance ElementId");
                    FieldBuilder sheetBuilder = schemaBuilder.AddSimpleField("CreatedSheet", typeof(ElementId));
                    sheetBuilder.SetDocumentation("Sheet ElementId");

                    FieldBuilder imageBuilder = schemaBuilder.AddSimpleField("CreatedImage", typeof(ElementId));
                    imageBuilder.SetDocumentation("Sheet ElementId");

                    schema = schemaBuilder.Finish();
                }

                DataStorage createdData = DataStorage.Create(vs.Document);
                Entity      entity      = new Entity(schema);
                Field       sheetfield  = schema.GetField("CreatedSheet");
                entity.Set <ElementId>(sheetfield, vs.Id, DisplayUnitType.DUT_UNDEFINED);
                Field imagefield = schema.GetField("CreatedImage");
                entity.Set <ElementId>(imagefield, ImageonSheet.Id, DisplayUnitType.DUT_UNDEFINED);
                createdData.SetEntity(entity);
                tx.Commit();
            }

            if (vs != null)
            {
                uidoc.ActiveView = (View)vs;
            }

            return(Result.Succeeded);
        }
Ejemplo n.º 4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            string filename = "pastedImage" + "_" + DateTime.Now.ToString("yyyy-MM-dd HH.mm") + ".jpeg";
            string path = "";
            if (doc.IsModelInCloud || doc.IsDetached || doc.PathName == null)
            {
                path = Path.Combine(Path.GetTempPath(), filename);
            }
            else if(doc.IsWorkshared) {
                path = Path.Combine(Path.GetDirectoryName(doc.GetWorksharingCentralModelPath().CentralServerPath), "PastedImages", filename);
            }
            else
            {
                path = Path.Combine(Path.GetDirectoryName(doc.PathName), "PastedImages", filename);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(path));

            if (Clipboard.ContainsImage())
            {
                Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
                Debug.Print(path);
                image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                message = "No image on clipoboard";
                return Result.Failed;
            }

            XYZ imageLocation = new XYZ();

            try
            {
                imageLocation = uidoc.Selection.PickPoint("Pick insertion point (midpoint)");
            }
            catch(Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                message = "Command cancelled";
                return Result.Cancelled;
            }


            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();
            }


            return Result.Succeeded;
        }