Example #1
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);
        }
        private AcSmSubset CreateSubset(AcSmDatabase sheetSetDatabase, string name, string description, string newSheetLocation,
                                        string newSheetDWTLocation, string newSheetDWTLayout, bool promptForDWT)
        {
            // Create a subset with the provided name and description
            AcSmSubset subset = (AcSmSubset)sheetSetDatabase.GetSheetSet().CreateSubset(name, description);

            // Get the folder the sheet set is stored in
            string sheetSetFolder = sheetSetDatabase.GetFileName().Substring(0, sheetSetDatabase.GetFileName().LastIndexOf("\\"));

            // Create a reference to a File Reference object
            IAcSmFileReference fileReference = subset.GetNewSheetLocation();

            // Check to see if a path was provided, if not default
            // to the location of the sheet set
            if (!string.IsNullOrEmpty(newSheetLocation))
            {
                fileReference.SetFileName(newSheetLocation);
            }
            else
            {
                fileReference.SetFileName(sheetSetFolder);
            }

            // Set the location for new sheets added to the subset
            subset.SetNewSheetLocation(fileReference);

            // Create a reference to a Layout Reference object
            AcSmAcDbLayoutReference layoutReference = default(AcSmAcDbLayoutReference);

            layoutReference = subset.GetDefDwtLayout();

            // Check to see that a default DWT location and name was provided
            if (!string.IsNullOrEmpty(newSheetDWTLocation))
            {
                // Set the template location and name of the layout
                //for the Layout Reference object
                layoutReference.SetFileName(newSheetDWTLocation);
                layoutReference.SetName(newSheetDWTLayout);

                // Set the Layout Reference for the subset
                subset.SetDefDwtLayout(layoutReference);
            }

            // Set the Prompt for Template option of the subset
            subset.SetPromptForDwt(promptForDWT);
            return(subset);
        }
        private void SetSheetSetDefaults(AcSmDatabase sheetSetDatabase, string name, string description,
                                         string newSheetLocation, string newSheetDWTLocation, string newSheetDWTLayout,
                                         bool promptForDWT)
        {
            // Set the Name and Description for the sheet set
            sheetSetDatabase.GetSheetSet().SetName(name);
            sheetSetDatabase.GetSheetSet().SetDesc(description);

            // Check to see if a Storage Location was provided
            if (!string.IsNullOrEmpty(newSheetLocation))
            {
                // Get the folder the sheet set is stored in
                string sheetSetFolder = sheetSetDatabase.GetFileName().Substring(0, sheetSetDatabase.GetFileName().LastIndexOf("\\"));

                // Create a reference to a File Reference object
                IAcSmFileReference fileReference = default(IAcSmFileReference);
                fileReference = sheetSetDatabase.GetSheetSet().GetNewSheetLocation();

                // Set the default storage location based on the location of the sheet set
                fileReference.SetFileName(sheetSetFolder);

                // Set the new Sheet location for the sheet set
                sheetSetDatabase.GetSheetSet().SetNewSheetLocation(fileReference);
            }

            // Check to see if a Template was provided
            if (!string.IsNullOrEmpty(newSheetDWTLocation))
            {
                // Set the Default Template for the sheet set
                AcSmAcDbLayoutReference layoutReference = default(AcSmAcDbLayoutReference);
                layoutReference = sheetSetDatabase.GetSheetSet().GetDefDwtLayout();

                // Set the template location and name of the layout
                // for the Layout Reference object
                layoutReference.SetFileName(newSheetDWTLocation);
                layoutReference.SetName(newSheetDWTLayout);

                // Set the Layout Reference for the sheet set
                sheetSetDatabase.GetSheetSet().SetDefDwtLayout(layoutReference);
            }

            // Set the Prompt for Template option of the subset
            sheetSetDatabase.GetSheetSet().SetPromptForDwt(promptForDWT);
        }
Example #4
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);
        }