运行成功,在C盘生成了图纸的png图片
-
- using System;
- using System.Drawing;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.GraphicsInterface;
- using Autodesk.AutoCAD.GraphicsSystem;
- using Autodesk.AutoCAD.Interop;
- using Autodesk.AutoCAD.Runtime;
- namespace 截图工具
- {
- public class Commands
- {
- [CommandMethod("OSS")]
- public static void OffscreenSnapshot()
- {
- CreateSphere();
- SnapshotToFile(
- "c:\\sphere-Wireframe2D.png",
- VisualStyleType.Wireframe2D
- );
- SnapshotToFile(
- "c:\\sphere-Hidden.png",
- VisualStyleType.Hidden
- );
- SnapshotToFile(
- "c:\\sphere-Basic.png",
- VisualStyleType.Basic
- );
- SnapshotToFile(
- "c:\\sphere-ColorChange.png",
- VisualStyleType.ColorChange
- );
- SnapshotToFile(
- "c:\\sphere-Conceptual.png",
- VisualStyleType.Conceptual
- );
- SnapshotToFile(
- "c:\\sphere-Flat.png",
- VisualStyleType.Flat
- );
- SnapshotToFile(
- "c:\\sphere-Gouraud.png",
- VisualStyleType.Gouraud
- );
- SnapshotToFile(
- "c:\\sphere-Realistic.png",
- VisualStyleType.Realistic
- );
- }
- public static void CreateSphere()
- {
- Document doc =
- Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- Transaction tr =
- doc.TransactionManager.StartTransaction();
- using (tr)
- {
- var bt =
- (BlockTable) tr.GetObject(
- db.BlockTableId,
- OpenMode.ForRead
- );
- var btr =
- (BlockTableRecord) tr.GetObject(
- bt[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite
- );
- var sol = new Solid3d();
- sol.CreateSphere(10.0);
- const string matname =
- "Sitework.Paving - Surfacing.Riverstone.Mortared";
- var matdict =
- (DBDictionary) tr.GetObject(
- db.MaterialDictionaryId,
- OpenMode.ForRead
- );
- if (matdict.Contains(matname))
- {
- sol.Material = matname;
- }
- else
- {
- ed.WriteMessage(
- "\nMaterial (" + matname + ") not found" +
- " - sphere will be rendered without it.",
- matname
- );
- }
- btr.AppendEntity(sol);
- tr.AddNewlyCreatedDBObject(sol, true);
- tr.Commit();
- }
- var acadApp =
- (AcadApplication)Application.AcadApplication;
- acadApp.ZoomExtents();
- }
- public static void SnapshotToFile(
- string filename,
- VisualStyleType vst
- )
- {
- Document doc =
- Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- Manager gsm = doc.GraphicsManager;
- // Get some AutoCAD system variables
- int vpn =
- Convert.ToInt32(
- Application.GetSystemVariable("CVPORT")
- );
- using (var view = new View())
- {
|