Example #1
0
        public static bool ExportNestedBlock(NestedBlock nested, string filePath)
        {
            var doc = new File3dm();

            // Add all instance definitions
            foreach (var references in nested.GetRootTreeByRootDepth().Reverse())
            {
                var nameIndexDict = new Dictionary <string, int>();
                foreach (var referencedBlock in references)
                {
                    if (!nameIndexDict.ContainsKey(referencedBlock.Definition.Name))
                    {
                        var objs  = referencedBlock.Definition.GetObjects();
                        var geos  = new GeometryBase[objs.Length];
                        var attrs = new ObjectAttributes[objs.Length];
                        for (int i = 0; i < objs.Length; i++)
                        {
                            geos[i]  = objs[i].Geometry;
                            attrs[i] = objs[i].Attributes;
                        }

                        var index = doc.AllInstanceDefinitions.Add(referencedBlock.Definition.Name, nested.Definition.Description,
                                                                   Point3d.Origin, geos, attrs);
                        nameIndexDict.Add(referencedBlock.Definition.Name, index);
                    }

                    doc.Objects.AddInstanceObject(nameIndexDict[referencedBlock.Definition.Name],
                                                  referencedBlock.BlockInsertionParameters.InstanceXform);
                }
            }

            return(doc.Write(filePath, RhinoApp.ExeVersion));
        }
Example #2
0
        private void GetNestedBlocks()
        {
            NestedBlocks = new NestedBlock[InstanceDefinitions.Length];

            for (int i = 0; i < NestedBlocks.Length; i++)
            {
                NestedBlocks[i] = new NestedBlock(InstanceDefinitions[i]);
                //NestedBlocks[i].CreatePreviewImage(_active_doc);
            }
        }
Example #3
0
        public static Bitmap GeneratePreview(NestedBlock nested, RhinoDoc doc)
        {
            var view        = doc.Views.ActiveView;
            var viewCapture = new ViewCapture
            {
                Height = Settings.BlockManagerPreviewHeight,
                Width  = Settings.BlockManagerPreviewWidth
            };

            // store old settings
            var cameraLocation  = view.ActiveViewport.CameraLocation;
            var cameraTarget    = view.ActiveViewport.CameraTarget;
            var cameraDirection = cameraTarget - cameraLocation;
            var cameraUp        = view.ActiveViewport.CameraUp;
            var displayMode     = view.ActiveViewport.DisplayMode;

            view.ActiveViewport.NextViewProjection();
            view.ActiveViewport.PushViewProjection();

            view.ActiveViewport.SetProjection(Settings.BlockManagerPreviewProjection, null, false);
            view.ActiveViewport.DisplayMode = Settings.BlockManagerPreviewDisplayModeDescription;
            var conduit = new BlockPreviewConduit(nested);

            conduit.Enabled         = true;
            doc.Views.RedrawEnabled = false;

            var bb = conduit.GetReferenceBoundingBox();

            bb.Inflate(0.8, 0.8, 0.8);
            //view.ActiveViewport.SetCameraLocation(bb.Corner(true, true, true), false);
            //view.ActiveViewport.SetCameraTarget(bb.Center, false);
            view.ActiveViewport.ZoomBoundingBox(bb);
            view.Redraw();

            var image = viewCapture.CaptureToBitmap(view);

            conduit.Enabled = false;

            var prev = view.ActiveViewport.PreviousViewProjection();

            //var popped = view.ActiveViewport.PopViewProjection();
            view.ActiveViewport.CameraUp = cameraUp;
            view.ActiveViewport.SetCameraLocation(cameraLocation, false);
            view.ActiveViewport.SetCameraDirection(cameraDirection, false);
            view.ActiveViewport.SetCameraTarget(cameraTarget, false);
            view.ActiveViewport.DisplayMode = displayMode;
            doc.Views.RedrawEnabled         = true;

            return(image);
        }
Example #4
0
        public BlockPreviewConduit(NestedBlock nested)
        {
            if (nested.HasParent)
            {
                NestedBlock parent      = nested.Parent;
                int         parentCount = 1;
                while (parent.HasParent)
                {
                    parent       = parent.Parent;
                    parentCount += 1;
                }
                var references  = parent.GetRootTree();
                var activeIndex = nested.Parent.GetActiveIndex(nested);

                MainReference = new ReferencedBlock(parent);
                ActivePart    = references[parentCount][activeIndex];
            }
            else
            {
                MainReference = new ReferencedBlock(nested);
            }
        }
Example #5
0
 public ReferencedBlock(NestedBlock nested)
 {
     Definition = nested.Definition;
     BlockInsertionParameters = nested.RelativeInsertion;
 }