Projektdateien hinzufügen.

This commit is contained in:
Max Richter
2025-06-11 15:01:17 +02:00
parent d4065f4938
commit 5a9085b0be
24 changed files with 1207 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3978D155-2657-4BA1-96E2-852C35E11E35}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>DebugPluginLocally</RootNamespace>
<AssemblyName>DebugPluginLocally</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<MultipleProjects>true</MultipleProjects>
<PackagePath>..\..\packages</PackagePath>
<PackagePath Condition="Exists('..\packages')">..\packages</PackagePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autodesk.Inventor.Interop, Version=23.0.0.0, Culture=neutral, PublicKeyToken=d84147f8b4276564, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>True</EmbedInteropTypes>
<HintPath>$(PackagePath)\autodesk\autodesk.inventor.interop.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="InventorConnector.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="inputFiles\box.ipt" />
<None Include="inputFiles\params.json" />
</ItemGroup>
<Choose>
<When Condition="$(MultipleProjects) == 'true'">
<ItemGroup>
<ProjectReference Include="..\MachinePlannerExportPlugin\MachinePlannerExportPlugin.csproj">
<Project>{f1c9d7e2-53a8-4e4e-af9e-931ca891715d}</Project>
<Name>MachinePlannerExportPlugin</Name>
</ProjectReference>
<!-- other ProjectReference elements -->
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<!-- other ProjectReference elements -->
</ItemGroup>
</Otherwise>
</Choose>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,95 @@
using System;
using System.Runtime.InteropServices;
using Inventor;
namespace DebugPluginLocally
{
internal class InventorConnector : IDisposable
{
Application _Instance;
bool _CreatedByUs;
const string PROG_ID = "Inventor.Application";
public InventorConnector()
{
}
public InventorServer GetInventorServer()
{
Connect();
_Instance.SilentOperation = true;
return _Instance as InventorServer;
}
private void Connect()
{
if (_Instance == null)
{
_Instance = TryConnectToRunningInstance();
if (_Instance == null)
{
_Instance = TryCreateInstance();
_CreatedByUs = _Instance != null;
}
if (_Instance == null)
throw new ApplicationException("Could not connect to Inventor.");
}
}
private static Application TryCreateInstance()
{
Console.WriteLine("Trying to create instance of Inventor...");
Application app = null;
try
{
Type type = Type.GetTypeFromProgID(PROG_ID);
app = Activator.CreateInstance(type) as Application;
Console.WriteLine($"Connected to Inventor {app.SoftwareVersion.DisplayName}");
// show Inventor UI
app.Visible = true;
}
catch (Exception e)
{
Console.WriteLine($"No running Inventor instance... ({e.Message})");
}
return app;
}
private static Application TryConnectToRunningInstance()
{
Console.WriteLine("Trying to connect to Inventor...");
Application app = null;
try
{
app = Marshal.GetActiveObject(PROG_ID) as Application;
Console.WriteLine($"Connected to Inventor {app.SoftwareVersion.DisplayName}");
}
catch /*(Exception e)*/
{
//Console.WriteLine($"Could not connect to running Inventor Instance... ({e.Message})");
}
return app;
}
public void Dispose()
{
if (_Instance != null)
{
Console.WriteLine("Closing all documents...");
_Instance.Documents.CloseAll(UnreferencedOnly: false);
if (_CreatedByUs)
{
// Uncomment to close the Inventor instance
//_Instance.Quit();
}
Console.WriteLine("Detaching from Inventor...");
Marshal.ReleaseComObject(_Instance);
_Instance = null;
}
}
}
}

View File

@ -0,0 +1,95 @@
using System;
using System.IO;
using Inventor;
namespace DebugPluginLocally
{
internal class Program
{
static void Main(string[] args)
{
using (var inv = new InventorConnector())
{
InventorServer server = inv.GetInventorServer();
try
{
Console.WriteLine("Running locally...");
// run the plugin
DebugSamplePlugin(server);
}
catch (Exception e)
{
string message = $"Exception: {e.Message}";
if (e.InnerException != null)
message += $"{System.Environment.NewLine} Inner exception: {e.InnerException.Message}";
Console.WriteLine(message);
}
finally
{
if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Press any key to exit. All documents will be closed.");
Console.ReadKey();
}
}
}
}
/// <summary>
/// Opens box.ipt and runs SamplePlugin
/// </summary>
/// <param name="app"></param>
private static void DebugSamplePlugin(InventorServer app)
{
// get project directory
string projectdir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
// get box.ipt absolute path
string boxPath = System.IO.Path.Combine(projectdir, @"inputFiles\", "box.ipt");
string boxPathCopy = System.IO.Path.Combine(projectdir, @"inputFiles\", "boxcopy.ipt");
try
{
// delete an existing file
System.IO.File.Delete(boxPathCopy);
}
catch (IOException)
{
Console.WriteLine("The specified file is in use. It might be open by Inventor");
return;
}
// create a copy
System.IO.File.Copy(boxPath, boxPathCopy);
// open box.ipt by Inventor
Document doc = app.Documents.Open(boxPathCopy);
// get params.json absolute path
string paramsPath = System.IO.Path.Combine(projectdir, @"inputFiles\", "params.json");
// create a name value map
Inventor.NameValueMap map = app.TransientObjects.CreateNameValueMap();
// add parameters into the map, do not change "_1". You may add more parameters "_2", "_3"...
map.Add("_1", paramsPath);
// add extra parameters to showcase newly supported parsing and new helper class NameValueMapHelper
map.Add("intIndex", "1");
map.Add("stringIndex", "test");
map.Add("stringCollectionIndex", "str1, str2, str3");
map.Add("intCollectionIndex", "34, 256, 9999, 500, 43");
// create an instance of MachinePlannerExportPlugin
MachinePlannerExportPlugin.SampleAutomation plugin = new MachinePlannerExportPlugin.SampleAutomation(app);
// run the plugin
plugin.RunWithArguments(doc, map);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DebugPluginLocally")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DebugPluginLocally")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3978d155-2657-4ba1-96e2-852c35e11e35")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1 @@
{"length":"20","width":"10"}