Пример #1
0
        public static Sheet AddToSubSetBefore(SubSet subset, string filename, Sheet indexSheet, string desc = "")
        {
            Sheet retSheet = null;

            if (subset != null)
            {
                Database database = subset.Database;
                try
                {
                    if (Database.LockDatabase(database, true))
                    {
                        // get the base object of the index sheet
                        AcSmSheet exSheet = indexSheet.BaseObject;
                        // add the new sheet to the subset
                        AcSmSheet sheet = subset.BaseObject.AddNewSheet(filename, desc);
                        // add the sheet to the subset
                        subset.BaseObject.InsertComponent(sheet, exSheet);
                        retSheet = new Sheet(sheet);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    Database.LockDatabase(database, false);
                }
            }
            return(retSheet);
        }
Пример #2
0
        /// <summary>
        /// Import an existing sheet file to a subset before a sheet.
        /// </summary>
        /// <param name="subset">The subset to receive the new sheet.</param>
        /// <param name="filename">The file and path of the existing sheet.</param>
        /// <param name="layoutName">The paperspace layout name.</param>
        /// <param name="indexSheet">The sheet to insert before.</param>
        /// <returns></returns>
        /// [IsVisibleInDynamoLibrary(true)]
        public static Sheet ImportLayoutToSubSetBefore(SubSet subset, string filename, string layoutName, Sheet indexSheet)
        {
            Sheet retSheet = null;

            if (subset != null)
            {
                try
                {
                    if (Database.LockDatabase(subset.Database, true))
                    {
                        // create a layout reference object
                        AcSmAcDbLayoutReference layoutReference = new AcSmAcDbLayoutReference();
                        // initialize the reference to the sheet set
                        layoutReference.InitNew(subset.BaseObject);
                        // set the layout and drawing file to the inputs
                        layoutReference.SetFileName(filename);
                        layoutReference.SetName(layoutName);
                        // import the sheet into the sheet set
                        AcSmSheet newSheet;
                        newSheet = subset.BaseObject.ImportSheet(layoutReference);
                        // get the base object of the index sheet
                        AcSmSheet exSheet = indexSheet.BaseObject;
                        subset.BaseObject.InsertComponent(newSheet, exSheet);
                        retSheet = new Sheet(newSheet);
                    }
                }
                catch (Exception ex)
                { Debug.WriteLine(ex.Message); }
                finally { Database.LockDatabase(subset.Database, false); }
            }
            return(retSheet);
        }
Пример #3
0
        /// <summary>
        /// Create and add a new Subset to the Sheet Set.
        /// </summary>
        /// <param name="sheetSet">The sheet set to contain the new subset.</param>
        /// <param name="name">The name of the new subset.</param>
        /// <param name="description">The optional description of the new subset.</param>
        /// <param name="newSheetDWTLayout">The optional layout tab of an alterante DWT to create new sheets from.</param>
        /// <param name="newSheetDWTLocation">The optional location of an alternate DWT to create new sheets from.</param>
        /// <param name="newSheetLocation">An optional new location to create new sheets for this subset.</param>
        /// <param name="promptForDWT">Optional setting to force the user to select a template with each new sheet.</param>
        /// <returns>The new subset.</returns>
        public static SubSet CreateNewSubset(SheetSet sheetSet, string name, string description = "", string newSheetLocation = "", string newSheetDWTLocation = "", string newSheetDWTLayout = "", bool promptForDWT = false)
        {
            SubSet retVal = null;

            if ((sheetSet != null) || (name != null) || (name != ""))
            {
                try
                {// lock the database
                    if (Database.LockDatabase(sheetSet.Database, true))
                    {
                        //create the new subset
                        AcSmSubset newSubset = (AcSmSubset)sheetSet.BaseObject.CreateSubset(name, description);
                        // get thet folder the sheet set is stored in
                        IAcSmFileReference sheetSetFolder = sheetSet.BaseObject.GetNewSheetLocation();

                        // create a file reference
                        IAcSmFileReference fileReference = newSubset.GetNewSheetLocation();
                        // check if a new path was provided, if not, default to the sheet set location
                        if (newSheetLocation != "")
                        {
                            fileReference.SetFileName(newSheetLocation);
                        }
                        else
                        {
                            fileReference.SetFileName(sheetSetFolder.GetFileName());
                        }
                        // set the location for new sheets added to the subset
                        newSubset.SetNewSheetLocation(fileReference);

                        // check if a default DWT location and name was provided
                        if ((newSheetDWTLocation != "") && (newSheetDWTLayout != ""))
                        {
                            // create a reference to a layout reference object
                            AcSmAcDbLayoutReference layoutReference = newSubset.GetDefDwtLayout();
                            layoutReference.SetFileName(newSheetDWTLocation);
                            layoutReference.SetName(newSheetDWTLayout);
                            // set the layout reference for the subset
                            newSubset.SetDefDwtLayout(layoutReference);
                        }

                        // set the prompt for template option
                        newSubset.SetPromptForDwt(promptForDWT);

                        // create our version of a subset
                        retVal = new SubSet((AcSmSubset)newSubset);
                    }
                    // if it couldn't be locked, fail
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                { Debug.WriteLine(ex.Message); }
                finally
                {
                    // unlock the database
                    Database.LockDatabase(sheetSet.Database, false);
                }
            }
            return(retVal);
        }