Get the width and height of 3D View

Get the width and height of 3D View

Anonymous
Not applicable
929 Views
2 Replies
Message 1 of 3

Get the width and height of 3D View

Anonymous
Not applicable
private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(View3D));
            foreach (Element elem in fec)
            {
                View3D v = elem as View3D;
                if (!v.IsTemplate)
                    List3DView.Items.Add(v.Name);               
            }
        }

I could show a list of all 3D views in combobox. But I don't know how display width and height in textbox. How I can do this?

0 Likes
930 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Message 3 of 3

Anonymous
Not applicable
private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(View3D));
            foreach (Element elem in collector)
            {
                View3D view3D = elem as View3D;
                if (!view3D.IsTemplate)
                {
                    List3DView.Items.Add(view3D.Name);
                    if (List3DView.SelectedIndex == 0)
                    {
                        string messageInfo = "BoundingBoxXYZ : ";
                        messageInfo += "\nView name : " + view3D.Name;
                        BoundingBoxXYZ boundingBox = view3D.GetSectionBox();
                        if (!boundingBox.Enabled)
                        {
                            boundingBox.Enabled = true;
                        }
                        if (boundingBox.Enabled)
                        {
                            // Get max boundingbox
                            XYZ max = boundingBox.Max;
                            // Get min boundingbox
                            XYZ min = boundingBox.Min;

                            double width = Math.Round((max.X - min.X), 2);
                            double height = Math.Round((max.Y - min.Y), 2);
                            messageInfo += "\nWidth : " + width;
                            messageInfo += "\nHeight : " + height;

                            txtWidth.Text = width.ToString();
                            txtHeight.Text = height.ToString();
                        }
                        TaskDialog.Show("Revit", messageInfo);
                    }                  
                }         
            }
        }

What should I change that selected 3D view in list coincided with Width and Height in the textbox?

0 Likes