Example #1
0
        /// <summary>
        /// Imports a block with the given name from the outside file to the
        /// current drawing
        /// </summary>
        /// <param name="blockName">the given block name</param>
        /// <param name="filePath">the file path for the outside file</param>
        /// <returns></returns>
        public static DSBlock Import(string blockName, string filePath)
        {
            string kMethodName = "DSBlock.Import";

            filePath = DSGeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }

            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            helper.ImportBlockFromFile(filePath, blockName);
            return(new DSBlock(blockName, filePath));
        }