Ejemplo n.º 1
0
        public static void ShowExceptionDialog(Exception e, NewSheetFormat nsf, double parentLeft, double parentTop)
        {
            ErrorReport errorReport = new ErrorReport();

            errorReport.ParentLeft = parentLeft;
            errorReport.ParentTop  = parentTop;

            errorReport.WindowTitle = LocalResMgr.WinTitleErrorReport;

            errorReport.tblkMessage.Text = AppStrings.R_ErrCannotProceed;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(AppStrings.R_ErrEmailTo);
            sb.AppendLine(AppStrings.R_EmailAddress).AppendLine();
            sb.Append(logMsgDbS("root exception")).AppendLine(AppStrings.R_ErrCreateSheetFailDesc ?? "none");
            sb.Append(logMsgDbS("primary exception")).AppendLine(e.Message ?? "none");
            sb.Append(logMsgDbS("inner exception")).AppendLine(e.InnerException?.Message ?? "none");
            sb.AppendLine(logMsgDbS("stack trace")).AppendLine(e.StackTrace ?? "none").AppendLine();
            sb.AppendLine(logMsgDbS("nsf")).Append(nsf?.ToString() ?? "is null").AppendLine();

            errorReport.ErrReport = sb.ToString();

            errorReport.ShowDialog();
        }
Ejemplo n.º 2
0
        // create a single blank sheet with a title block - if
        // wanted and using the parameters from the
        // selected sheet if wanted
        public ViewSheet CreateOneEmptySheet(NewSheetFormat nsf)
        {
            ViewSheet vsDestinationSheet;

            ElementId tbId = ElementId.InvalidElementId;

            if (nsf.TitleBlockName != null)
            {
                tbId = GetTitleBlockFs(nsf.TitleBlockName).Id;
            }

            // create a sheet
            vsDestinationSheet = ViewSheet.Create(_doc, tbId);

            if (vsDestinationSheet == null)
            {
                throw new Exception(AppStrings.R_ErrCreateSheetFailDesc);
            }

            // give the new sheet a number and name
            vsDestinationSheet.SheetNumber = nsf.newSheetNumber;
            vsDestinationSheet.Name        = nsf.newSheetName;


            if (nsf.UseParameters && nsf.SelectedSheet.SheetView != null)
            {
                CopyParameters(nsf.FcSelViewSht, vsDestinationSheet);
            }

            return(vsDestinationSheet);
        }
Ejemplo n.º 3
0
        public static bool Process(ExternalCommandData commandData, NewSheetFormat nsf)
        {
//			USettings.Read();

            ViewSheet vs = null;

            ShDbMgr dbMgr = new ShDbMgr(commandData);

//			NewSheetFormat nsf = USet.OneClick;


            if (nsf.Defined)
            {
                View v;

                if (nsf.UseTemplateSheet)
                {
                    nsf.TemplateSheetView = dbMgr.FindExistSheet(nsf.TemplateSheetNumber);

                    if (nsf.TemplateSheetView == null)
                    {
                        ErrorTemplateNotFound(nsf.TemplateSheetNumber, nsf.TemplateSheetName);
                        return(false);
                    }

                    vs = nsf.TemplateSheetView;
                }
                else
                {
                    v = dbMgr.ActiveGraphicalView;

//					if (nsf.NewSheetOption == NewShtOptions.FromCurrent)
//					{
                    if (v.ViewType == ViewType.DrawingSheet)
                    {
                        vs = v as ViewSheet;
                    }
                    else
                    {
                        ErrorNotSheetView();
                        return(false);
                    }
//				}
                }

//				nsf.SelectedSheet = new SheetData(vs.SheetNumber, vs.ViewName, vs);
                nsf.SelectedSheet = new SheetData(vs.SheetNumber, vs.Name, vs);

                dbMgr.Process2(nsf);
            }
            else
            {
                ErrorSettingsNotDefined();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public bool Process2(NewSheetFormat nsf)
        {
            bool result = false;
            int  seq    = 0;

            try
            {
                nsf.TitleBlockName = SelectTitleBlock(nsf);

#if DEBUG
                logMsg2(nl);
                logMsgLn2("process2| Titleblock name", nsf.TitleBlockName ?? "null");
#endif

                for (int i = 1; i < nsf.Copies + 1; i++)
                {
                    // part A - determine the new sheet number depending
                    // on newsheetformat
                    // find sheet number and determine the sequence number
                    nsf.newSheetNumber = FindNextSheetNumber(nsf, seq, out nsf.seq);

                    // part B - determine the new sheet name depending
                    // on newsheetformat
                    nsf.newSheetName = GetNewSheetName(nsf);

                    // got the new sheet number and name
#if DEBUG
                    DebugInfo1(nsf, i);
#endif
                    switch (nsf.OperationOption)
                    {
                    case OperOpType.CreateEmptySheets:
                    {
                        CreateOneEmptySheet(nsf);
                        result = true;
                        break;
                    }

                    case OperOpType.DupSheet:
                    {
                        DuplicateOneSheet(nsf);
                        result = true;
                        break;
                    }

                    case OperOpType.DupSheetAndViews:
                    {
                        DuplicateOneSheet(nsf);
                        result = true;
                        break;
                    }
                    }

                    // make sure that the list of sheet numbers is current
                    // and includes the sheet just created
                    GetAllSheetNumbers();
                }
            }
            catch (Exception e)
            {
                ShUtil.ShowExceptionDialog(e, nsf, _parentLeft, _parentTop);

                return(false);
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Duplicate one existing sheet
        /// </summary>
        /// <param name="shtNumber">The new sheet number</param>
        /// <param name="shtName">The new sheet name</param>
        /// <param name="tbName">The title block for the new sheet</param>
        /// <param name="vsSourceSheet">The ViewSheet to copy</param>
//		public void DuplicateOneSheet(string shtNumber, string shtName, string tbName, ViewSheet vsSourceSheet)
        public void DuplicateOneSheet(NewSheetFormat nsf)
        {
            ViewSheet vsDestinationSheet;

            try
            {
                // try to create the sheet
                // see below about copy parameters
                vsDestinationSheet = CreateOneEmptySheet(nsf);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            // at this point we have a source and destination ViewSheet
            // here we copy the elements on the source ViewSheet and
            // place them onto the destination ViewSheet
            // except, we don't copy the title block as this was added
            // when the ViewSheet was created

            // first, get a collection of elements that exist on the source sheet
            FilteredElementCollector colViewSheet =
                new FilteredElementCollector(_doc, nsf.FcSelViewSht.Id);

            // prepare for the elements to "copy" and "paste"
            ICollection <ElementId> copyIds = new List <ElementId>();

            // this may fail, prepare for the failure and capture the failure message
            try
            {
                // in order to copy detail lines directly onto the sheet, we need to
                // setup a SketchPlane on the "blank" sheet

                SketchPlane sketch = CreateSketchPlane(vsDestinationSheet);

                List <Viewport> vpList       = new List <Viewport>(10);
                List <Viewport> vpListNoCopy = new List <Viewport>(10);

                copyIds.Clear();

                // the ViewSheet has been setup to copy / paste or duplicate the elements
                // held by the ViewSheet - with the exceptions that ViewPorts cannot be copied
                foreach (Element sourceElem in colViewSheet)
                {
                    // ignore GuideGrids
                    if (sourceElem.Category.Id == _cats.get_Item(BuiltInCategory.OST_GuideGrid).Id)
                    {
                        continue;
                    }

                    // is the current element a titleblock? - this is the source titleblock
                    if (sourceElem.Category.Id == _cats.get_Item(BuiltInCategory.OST_TitleBlocks).Id)
                    {
                        ConfigureNewTitleBlock(sourceElem, vsDestinationSheet);
                        continue;
                    }

                    // we cannot copy some viewports or GuideGrids
                    if (sourceElem.Category.Id == _cats.get_Item(BuiltInCategory.OST_Viewports).Id)
                    {
                        Viewport vp = (Viewport)sourceElem;
                        View     vw = (View)_doc.GetElement(vp.ViewId);

                        if (Viewport.CanAddViewToSheet(_doc, vsDestinationSheet.Id, vw.Id))
                        {
                            vpList.Add(vp);                             // got a viewport to copy
                        }
                        else
                        {
                            vpListNoCopy.Add(vp);                             // got a viewport I cannot copy
                        }
                        continue;
                    }

                    // process a not viewport items
                    copyIds.Add(sourceElem.Id);
                }

                // preform the actual copy of the elements
                if (copyIds.Count > 0)
                {
                    ElementTransformUtils.CopyElements((ViewSheet)nsf.SelectedSheet.SheetView, copyIds, vsDestinationSheet,
                                                       Transform.Identity, new CopyPasteOptions());
                }

                // processed all of the items on the view sheet except for the viewports
                // we have a list of viewports we can copy and place onto the sheet
                // here we process the list of viewports that cannot be copy / pasted and replicate
                // them matching their original location
                if (vpList.Count > 0)
                {
                    foreach (Viewport vpSource in vpList)
                    {
                        View vw = _doc.GetElement(vpSource.ViewId) as View;

                        PlaceViewportOnSheet(vsDestinationSheet, vpSource, vw);
                    }
                }

                if (vpListNoCopy.Count > 0 && nsf.OperationOption == OperOpType.DupSheetAndViews)
                {
                    // get all of the view names here to make sure it is current
                    GetAllViewNames();

                    foreach (Viewport vpSource in vpListNoCopy)
                    {
                        View vwSource = _doc.GetElement(vpSource.ViewId) as View;

                        if (!vwSource.CanViewBeDuplicated(ViewDuplicateOption.WithDetailing))
                        {
                            continue;
                        }

                        View vwCopy;

                        // if PrimaryViewId is not InvalidElementId, view is dependant
                        if (vwSource.GetPrimaryViewId() == ElementId.InvalidElementId)
                        {
                            vwCopy = _doc.GetElement(vwSource.Duplicate(ViewDuplicateOption.WithDetailing)) as View;
                        }
                        else
                        {
                            vwCopy = _doc.GetElement(vwSource.Duplicate(ViewDuplicateOption.AsDependent)) as View;
                        }

                        if (vwCopy != null)
                        {
                            vwCopy.Name = FindNextViewName(vwSource.Name, nsf);
//							vwCopy.Name = FindNextViewName(vwSource.Name, nsf.newSheetNumber);

                            PlaceViewportOnSheet(vsDestinationSheet, vpSource, vwCopy);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(AppStrings.R_ErrDupSheetFailDesc + nl + e.Message);
            }
        }
Ejemplo n.º 6
0
        private void DebugInfo1(NewSheetFormat nsf, int idx)
        {
            logMsgLn2("process2| copy", idx);

            logMsgLn2("process2| number", new int[] { 22 }, nsf.newSheetNumber, "name", nsf.newSheetName);
        }