Example #1
0
        private void ExportImage()
        {
            using (var trans = new Transaction(ActiveDoc))
            {
                trans.Start("Export Image");
                try
                {
                    var imgFileName = Path.Combine(Path.GetTempPath(), "SmartBCF", Path.GetTempFileName() + ".png");
                    if (File.Exists(imgFileName))
                    {
                        File.Delete(imgFileName);
                    }

                    var options = new ImageExportOptions
                    {
                        FilePath = imgFileName,
                        HLRandWFViewsFileType = ImageFileType.PNG,
                        ShadowViewsFileType   = ImageFileType.PNG,
                        ExportRange           = ExportRange.VisibleRegionOfCurrentView,
                        ZoomType        = ZoomFitType.FitToPage,
                        ImageResolution = ImageResolution.DPI_72,
                        PixelSize       = 1000
                    };

                    ActiveDoc.ExportImage(options);
                    trans.Commit();

                    SetViewPoint(imgFileName);
                }
                catch (Exception)
                {
                    trans.RollBack();
                }
            }
        }
Example #2
0
        private ObservableCollection <Component> GetElements(string viewpoint_Guid)
        {
            var components = new ObservableCollection <Component>();

            try
            {
                switch (ViewPointViewModel.SelectedOption)
                {
                case ComponentOption.SelectedElements:
                    var selectedIds = m_app.ActiveUIDocument.Selection.GetElementIds();
                    foreach (var eId in selectedIds)
                    {
                        var element = ActiveDoc.GetElement(eId);
                        if (null != element)
                        {
                            var comp = new Component();
                            comp.Guid              = Guid.NewGuid().ToString();
                            comp.IfcGuid           = element.IfcGUID();
                            comp.Selected          = false;
                            comp.Visible           = true;
                            comp.OriginatingSystem = m_app.Application.VersionName;
                            comp.AuthoringToolId   = element.Id.IntegerValue.ToString();
                            comp.ViewPointGuid     = viewpoint_Guid;
                            comp.ElementName       = element.Name;

                            components.Add(comp);
                        }
                    }
                    break;

                case Utils.ComponentOption.OnlyVisible:
                    var currentView = ActiveDoc.ActiveView;
                    var collector   = new FilteredElementCollector(ActiveDoc, currentView.Id);
                    ICollection <Element> elements = collector.ToElements();
                    foreach (var element in elements)
                    {
                        var comp = new Component();
                        comp.Guid              = Guid.NewGuid().ToString();
                        comp.IfcGuid           = element.IfcGUID();
                        comp.Selected          = false;
                        comp.Visible           = true;
                        comp.OriginatingSystem = m_app.Application.VersionName;
                        comp.AuthoringToolId   = element.Id.IntegerValue.ToString();
                        comp.ViewPointGuid     = viewpoint_Guid;
                        comp.ElementName       = element.Name;

                        components.Add(comp);
                    }

                    break;
                }
            }
            catch (Exception)
            {
                // ignored
            }
            return(components);
        }
Example #3
0
        public void CreateBaseWallType()
        {
            ///Create the default material.
            ElementId baseMaterialid = null;
            Material  baseMaterial   = null;
            Color     colorGrey      = new Color(80, 80, 80);
            ///First check if the material already exist.
            Material existMa = new FilteredElementCollector(ActiveDoc)
                               .OfClass(typeof(Material))
                               .Select(e => e as Material).ToList()
                               .Where(m => m.Name == "AutoWallMaterial")
                               .FirstOrDefault();

            baseMaterialid = (existMa != null) ? existMa.Id :
                             Material.Create(ActiveDoc, "AutoWallMaterial");
            baseMaterial = ActiveDoc.GetElement(baseMaterialid) as Material;
            ///Set the material color.
            baseMaterial.SurfaceForegroundPatternColor = colorGrey;
            baseMaterial.SurfaceBackgroundPatternColor = colorGrey;
            baseMaterial.Color = colorGrey;

            ///Create the default wall type.
            ///First check if it exist.
            WallType existWt = new FilteredElementCollector(ActiveDoc)
                               .WhereElementIsElementType()
                               .OfCategory(BuiltInCategory.OST_Walls)
                               .Select(e => e as WallType)
                               .Where(w => w.Name == "AutoWall-240")
                               .ToList().FirstOrDefault();
            ///If not exist,create a new one.
            WallType baseWt = (existWt != null) ?
                              existWt : new FilteredElementCollector(ActiveDoc)
                              .WhereElementIsElementType()
                              .OfCategory(BuiltInCategory.OST_Walls)
                              .Select(e => e as WallType)
                              .Where(w => w.Kind == WallKind.Basic)
                              .FirstOrDefault()
                              .Duplicate("AutoWall-240") as WallType;

            ///Set the structure.
            baseWt.SetCompoundStructure(
                CompoundStructure.CreateSingleLayerCompoundStructure
                    (MaterialFunctionAssignment.Structure,
                    UnitUtils.ConvertToInternalUnits(240, DisplayUnitType.DUT_MILLIMETERS),
                    baseMaterialid)
                );

            ///Create the wallType list and add the base type.
            AutoWallTypes = new List <WallType> {
                baseWt
            };
        }
Example #4
0
        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name="cmd"></param>
        public clsSettings(ExternalCommandData cmd)
        {
            _cmd        = cmd;
            _dimensions = new List <Dimension>();

            try
            {
                if (_selCollection.Any())
                {
                    _dimensions = (from m_x in _selCollection
                                   let m_y = ActiveDoc.GetElement(m_x)
                                             where new DimensionFilter().AllowElement(m_y)
                                             select m_y as Dimension)
                                  .ToList();
                }
                else
                {
                    IList <Reference> m_selection = ActiveUiDoc.Selection.PickObjects(
                        ObjectType.Element,
                        new DimensionFilter(),
                        Settings.Default.Prompt_String);

                    _dimensions = (from m_x in m_selection
                                   let m_y = ActiveDoc.GetElement(m_x)
                                             let m_z = m_y as Dimension
                                                       select m_z)
                                  .ToList();
                }

                Dimensions = _dimensions;
                SegmentCounter();
            }
            catch
            {
                throw new Exception(Settings.Default.Error_String);
            }
        }