2016-08-26 4 views
-1

안녕하세요 이것은 내 코드이며이 코드를 실행하고 출력하는 방법을 모르겠습니다. 나에게 this.And에 대한 대답을 제안 하고이 요구 사항에 따라 제안이 코드를 사용하여 autocad에 대한 명령을 만들고 싶습니다.다음 코드가 autocad에서 실행됩니까?

using System; 
using System.IO; 
using System.Globalization; 
using UDC; 
using AutoCAD = Autodesk.AutoCAD.Interop; 

namespace AutoCADtoPDF 
{ 
class Program 
{ 
    static void PrintAutoCADtoPDF(string AutoCADFilePath) 
    { 
     //Create a UDC object and get its interfaces 
     IUDC objUDC = new APIWrapper(); 
     IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter"); 
     IProfile Profile = Printer.Profile; 

     //Use Universal Document Converter API to change settings of converterd drawing 

     //Load profile located in folder "%APPDATA%\UDC Profiles". 
     //Value of %APPDATA% variable should be received using Environment.GetFolderPath method. 
     //Or you can move default profiles into a folder you prefer.   
     string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 
     string ProfilePath = Path.Combine(AppDataPath, @"UDC Profiles\Drawing to PDF.xml"); 
     Profile.Load(ProfilePath); 

     Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED; 
     Profile.OutputLocation.FolderPath = @"c:\UDC Output Files"; 

     Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER; 

     AutoCAD.AcadApplication App = new AutoCAD.AcadApplicationClass(); 

     double Version = double.Parse(App.Version.Substring(0, 4), new CultureInfo("en-US")); 

     //Open drawing from file 
     Object ReadOnly = false; 
     Object Password = Type.Missing; 
     AutoCAD.AcadDocument Doc = App.Documents.Open(AutoCADFilePath, ReadOnly, Password); 

     //AutoCAD.Common.AcadPaperSpace ActiveSpace; 
     AutoCAD.Common.AcadLayout Layout; 

     //Change AutoCAD preferences for scaling the drawing to page 
     if (Doc.ActiveSpace == 0) 
      Layout = Doc.PaperSpace.Layout; 
     else 
      Layout = Doc.ModelSpace.Layout; 

     Layout.PlotType = AutoCAD.Common.AcPlotType.acExtents; 
     Layout.UseStandardScale = true; 
     Layout.StandardScale = AutoCAD.Common.AcPlotScale.acScaleToFit; 
     Layout.CenterPlot = true; 

     Object nBACKGROUNDPLOT = 0, nFILEDIA = 0, nCMDDIA = 0; 
     if (Version >= 16.1f) 
     { 
      nBACKGROUNDPLOT = Doc.GetVariable("BACKGROUNDPLOT"); 
      nFILEDIA = Doc.GetVariable("FILEDIA"); 
      nCMDDIA = Doc.GetVariable("CMDDIA"); 

      Object xNull = 0; 
      Doc.SetVariable("BACKGROUNDPLOT", xNull); 
      Doc.SetVariable("FILEDIA", xNull); 
      Doc.SetVariable("CMDDIA", xNull); 
     } 

     Doc.Plot.QuietErrorMode = true; 

     //Plot the drawing 
     Doc.Plot.PlotToDevice("Universal Document Converter"); 

     if (Version >= 16.1f) 
     { 
      //Restore AutoCAD default preferences 
      Doc.SetVariable("BACKGROUNDPLOT", nBACKGROUNDPLOT); 
      Doc.SetVariable("FILEDIA", nFILEDIA); 
      Doc.SetVariable("CMDDIA", nCMDDIA); 
     } 

     //Close drawing 
     Object SaveChanges = false; 
     Doc.Close(SaveChanges, Type.Missing); 

     //Close Autodesk AutoCAD 
     App.Quit(); 
    } 

    static void Main(string[] args) 
    { 
     string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.dwg"); 
     PrintAutoCADtoPDF(TestFilePath); 
    } 
} 
} 
+1

다음 코드는 어떻게 실행됩니까? StackOverflow 당신에게 말하지 않을거야 .. 혼자 시도하십시오 ... – karan

+0

나는 그 안에 commandmethod를 추가 할 수 있습니까? – jackson

답변

3

original source에있는 의견을 읽었습니까?

이 코드는 dwg 파일의 활성 공간을 pdf 파일로 인쇄하는 독립 실행 형 응용 프로그램 (exe)을 빌드 할 때 세 번째 부분 응용 프로그램 이름 Universal Document Converter (UDC)을 사용하는 예입니다. UDC 소프트웨어를 설치해야합니다. AutoCAD 플러그인 (CommandMethod의 dll)으로 변환 할 수 없습니다. UDC Support으로 확실하게 자세한 정보를 얻을 수 있습니다.

이해할 수없는 웹에있는 코드를 복사하고 여기 또는 다른 사람에게 사용자의 요구에 맞게 수정 코드를 요청하여 .NET 및 AutoCAD API를 배우지는 않습니다.

+0

아 ... 전 코드 전체를 읽지도 않았어요. 두 번째 성명서에 관하여 : 사실 :-) – Alain

0

: 먼저 런타임에 using을 추가하십시오.

using Autodesk.AutoCAD.Runtime; 

다음으로 메소드에 속성을 추가하십시오.

[CommandMethod("YOURCOMMANDNAMEINAUTOCAD")] 

마지막 : AutoCAD에서 클래스 및 메소드를 공개해야 클래스와 메소드를 볼 수 있습니다.

업데이트 : (마지막) : 귀하의 방법은 매개 변수를 사용할 수 없습니다.

+0

이것은 작동하지 않습니다, 내 대답을 참조하십시오. – gileCAD