コード例 #1
0
        private void ApplyTemplateSettings()
        {
            try
            {
                if (toolSettings.ViewTemplateId != -1)
                {
                    ViewSection viewSection = m_doc.GetElement(new ElementId(toolSettings.ViewTemplateId)) as ViewSection;
                    if (null != viewSection)
                    {
                        ICollection <ElementId> parameterIds = viewSection.GetTemplateParameterIds();
                        int viewScaleImperial = (int)BuiltInParameter.VIEW_SCALE_PULLDOWN_IMPERIAL;
                        int viewScaleMetric   = (int)BuiltInParameter.VIEW_SCALE_PULLDOWN_METRIC;
                        int viewScale         = (int)BuiltInParameter.VIEW_SCALE;

                        var selectedIds = from paramId in parameterIds where paramId.IntegerValue == viewScaleImperial || paramId.IntegerValue == viewScaleMetric || paramId.IntegerValue == viewScale select paramId;
                        if (selectedIds.Count() > 0)
                        {
                            using (Transaction trans = new Transaction(m_doc, "SetViewTemplate"))
                            {
                                trans.Start();
                                try
                                {
                                    if (toolSettings.ScaleByTemplate)
                                    {
                                        toolSettings.CustomScale = viewSection.Scale;
                                    }
                                    else
                                    {
                                        viewSection.SetNonControlledTemplateParameterIds(selectedIds.ToList());
                                    }

                                    trans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    trans.RollBack();
                                    MessageBox.Show("Failed to include or exclude View Scale parameter from the view template.\n" + ex.Message, "View Template", MessageBoxButton.OK, MessageBoxImage.Warning);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to apply template settings.\n" + ex.Message, "Elevation Creator : ApplyTemplateSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }