0

I followed this blog post about Svf generation using Inventor, and I was able to achieve the functionality described in the example.

Speed up viewable generation when using Design Automation for Inventor

Since this workflow skips the use of the Model Derivative API, I am wondering if there is a way to access the thumbnail of my model through the resulting Svf files that come from the Inventor translator output.

I am assuming that it exists somewhere in the output files, but after some searching I haven’t found an obvious way to access it.

I have tried decompressing the gz files in the output directory, but I can not find the thumbnail data in the resulting json files.

image of svf output files

1 Answers1

0

I would say, there is no thumbnail you can access in SVF output. BUT you can ask Inventor to generate it for you. This is how we are doing it https://github.com/autodesk-platform-services/aps-configurator-inventor/blob/master/AppBundles/CreateThumbnailPlugin/CreateThumbnailAutomation.cs

LogTrace("Processing " + doc.FullFileName);
                dynamic invDoc = doc;

                // TODO: only IAM and IPT are supported now, but it's not validated
                invDoc.ObjectVisibility.AllWorkFeatures = false;
                invDoc.ObjectVisibility.Sketches = false;
                invDoc.ObjectVisibility.Sketches3D = false;

                if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    invDoc.ObjectVisibility.WeldmentSymbols = false;
                }

                string fileNameLarge = "thumbnail-large.png";
                string filePathLarge = Path.Combine(Directory.GetCurrentDirectory(), fileNameLarge);


                _inventorApplication.DisplayOptions.Show3DIndicator = false;
                Camera cam = _inventorApplication.TransientObjects.CreateCamera();
                cam.SceneObject = invDoc.ComponentDefinition;
                cam.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation;
                cam.Fit();
                cam.ApplyWithoutTransition();

                Color backgroundColor = _inventorApplication.TransientObjects.CreateColor(0xEC, 0xEC, 0xEC, 0.0); // hardcoded. Make as a parameter

                // generate image twice as large, and then downsample it (antialiasing)
                cam.SaveAsBitmap(filePathLarge, ThumbnailSize * 2, ThumbnailSize * 2, backgroundColor, backgroundColor);

                // based on https://stackoverflow.com/a/24199315
                using (var image = Image.FromFile(filePathLarge))
                using (var destImage = new Bitmap(ThumbnailSize, ThumbnailSize))
                {
                    destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

                    using (var graphics = Graphics.FromImage(destImage))
                    {
                        graphics.CompositingMode = CompositingMode.SourceCopy;
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.SmoothingMode = SmoothingMode.HighQuality;
                        graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                        using (var wrapMode = new ImageAttributes())
                        {
                            wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                            var destRect = new Rectangle(0, 0, ThumbnailSize, ThumbnailSize);
                            graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                        }
                    }

                    string fileName = "thumbnail.png";
                    string filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
                    destImage.Save(filePath);

                    LogTrace($"Saved thumbnail as {filePath}");
                }

                System.IO.File.Delete(filePathLarge);