コード例 #1
0
ファイル: Block.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        /// Instantiates the specified block by name with the orientation
        /// specified by the coordinate system into the target file.
        /// If the block does not exist in the target file, the block will be exported to the
        /// target file first.
        /// If the block already exists in the target file, the old block will be replaced with
        /// the new one.
        /// </summary>
        /// <param name="contextCoordinateSystem">
        /// Specifies the orientation of the block. Origin is the placement point.
        /// This coordinate system must be orthogonal, can be non-uniformly scaled
        /// </param>
        /// <param name="targetFileName">the outside file name</param>
        /// <returns>If the insertion succeeds, returns true</returns>
        public bool ByCoordinateSystem(CoordinateSystem contextCoordinateSystem, string targetFileName)
        {
            string kMethodName = "Block.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(targetFileName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "blockName");
            }

            targetFileName = Geometry.GetFullPath(targetFileName);

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

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

            return(helper.InsertBlockInTargetFile(contextCoordinateSystem.CSEntity, Name, targetFileName));
        }
コード例 #2
0
ファイル: Block.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        /// Exports the geometries of the block to the outside file.
        /// This is similar to AutoCAD's wblock operation.
        /// </summary>
        /// <param name="filePath">The outside file path</param>
        /// <returns>Returns true if the export operation is successful</returns>
        public bool ExportGeometry(string filePath)
        {
            filePath = Geometry.GetFullPath(filePath);

            string kMethodName = "Block.ExportGeometry";

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

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

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

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

            return(helper.ExportBlock(filePath, Name));
        }