Witam,
Chciałbym wykonać prosty program, który korzystająć z SolidWorks API otworzy konkretny plik i zapisze go do innego formatu (np. .step).
Na stronie Solidworksa znalazłem gotowy program jednak po wklejeniu go do visual studio nie moge go skompilować.
Tutaj link do strony:
Import STEP File Example (C#) - 2018 - SOLIDWORKS API Help
tutaj kod:
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace ImportStepDataCSharp.csproj
{
public partial class SolidWorksMacro
{
static void Main()
{
PartDoc swPart = default(PartDoc);
ModelDoc2 swModel = default(ModelDoc2);
ModelDocExtension swModelDocExt = default(ModelDocExtension);
ImportStepData swImportStepData = default(ImportStepData);
bool status = false;
int errors = 0;
int warnings = 0;
string fileName = null;
string stepFileName = null;
//Open the SOLIDWORKS part document to export to a STEP file
fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\db9 male.sldprt";
swPart = (PartDoc)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
swModel = (ModelDoc2)swPart;
swModelDocExt = (ModelDocExtension)swModel.Extension;
//Export the SOLIDWORKS part document to a STEP file
stepFileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\db9 male.STEP";
status = swModelDocExt.SaveAs(stepFileName, 0, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
swPart = null;
swApp.CloseDoc("db9 male.sldprt");
//Get import information
swImportStepData = (ImportStepData)swApp.GetImportFileData(stepFileName);
//If ImportStepData::MapConfigurationData is not set, then default to
//the environment setting swImportStepConfigData; otherwise, override
//swImportStepConfigData with ImportStepData::MapConfigurationData
swImportStepData.MapConfigurationData = true;
//Import the STEP file
swPart = (PartDoc)swApp.LoadFile4(stepFileName, "r", swImportStepData, ref errors);
swModel = (ModelDoc2)swPart;
swModelDocExt = (ModelDocExtension)swModel.Extension;
//Run diagnostics on the STEP file and repair the bad faces
errors = swPart.ImportDiagnosis(true, false, true, 0);
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
Przy próbie kompilacji visual wyrzuca taki błąd:
Zmiana "public void Main();" na: "static void Main();" nie pomaga, wtedy pojawiają się takie błedy:
Czy ktoś jest w stanie mi z tym pomóc? Gdzie jest błąd? Dlaczego gotowy kod nie chce się kompilować?
Z góry dzięki za pomoc.