Skip to main content

PySharpInventor - Autodesk Inventor Automation for Python

This library aims to simplify writing .NET/CLR Automation scripts for Autodesk Inventor with Python.

It talks to Inventor through the official .NET Interop assembly (Autodesk.Inventor.Interop.dll) using pythonnet, so you get the full, typed Inventor API from Python.

Requires:

  • Windows

  • Python 3

  • pythonnet>=3.0.0

  • Autodesk Inventor (2020+)

Features:

  • Dynamic Inventor version detection (picks the newest installed version)

  • Lazy loading of the Interop assembly, so modules can be imported in any order

  • Efficient objects iteration and searching

  • .NET/CLR interface to Inventor API

  • Document type casting (Part, Assembly, Drawing, Presentation)

  • Geometry casting for edges and faces (LineSegment, Circle, Plane, Cylinder, …)

  • Extension methods on Inventor objects, e.g. edge.cast_edge_geometry()

  • Custom error handling with specific exceptions

  • Support for connecting to active Inventor instances or creating new ones

Installation:

pip install pysharpinventor

For development, install from a clone in editable mode:

git clone https://github.com/Nandhakumarpro/PySharpInventor.git
cd pysharpinventor
pip install -e .

Usage Example:

from pysharpinventor import Inventor, InventorInterop

# Connect to active Inventor instance
inv = Inventor()

# Or create new instance if Inventor is not running
inv = Inventor(create_if_not_exists=True)

# Or point at a specific Inventor Interop DLL
inv = Inventor(inventor_path=r"C:\Program Files\Autodesk\Inventor 2025\Bin\Public Assemblies\Autodesk.Inventor.Interop.dll")

# Access active document
doc = inv.doc

# Cast document to specific type
part_doc = inv.cast_document(doc, InventorInterop.PartDocument)

# Or auto-detect document type
casted_doc = inv.cast_document(doc)

The Inventor object

Inventor(create_if_not_exists=False, visible=True, inventor_path=None)

  • create_if_not_exists - start a new Inventor if none is running.

  • visible - whether a newly started Inventor window is visible.

  • inventor_path - path to Autodesk.Inventor.Interop.dll. When omitted, the newest installation under C:\Program Files\Autodesk\Inventor * is used.

Properties and methods:

  • inv.app (alias inv.Application) - the Inventor.Application. Connects on first use.

  • inv.doc (alias inv.ActiveDocument) - the active document.

  • inv.cast_document(document, target_type=None) - cast a document to PartDocument, AssemblyDocument, DrawingDocument or PresentationDocument. Without target_type the type is detected from document.DocumentType.

InventorInterop

InventorInterop is the Inventor .NET namespace (Inventor.* in C#). Use it for classes and enums:

from pysharpinventor import InventorInterop

InventorInterop.PartDocument
InventorInterop.SurfaceTypeEnum.kPlaneSurface

It is safe to import anywhere, at any time. The Interop assembly is loaded the first time an attribute is accessed. If you need a custom DLL path, create Inventor(inventor_path=...) before touching InventorInterop; once loaded, the assembly cannot be swapped for another version in the same process.

Geometry casting

Edge.Geometry and Face.Geometry are returned by the API as a bare System.__ComObject. The helpers in pysharpinventor.geometry read the geometry type and cast it to the matching Inventor class:

from pysharpinventor.geometry import cast_edge_geometry, cast_face_geometry

body = part_doc.ComponentDefinition.SurfaceBodies[1]

curve_type, curve = cast_edge_geometry(body.Edges[1])
if curve_type == InventorInterop.CurveTypeEnum.kCircleCurve:
    print(curve.Radius)

surface_type, surface = cast_face_geometry(body.Faces[1])
if surface_type == InventorInterop.SurfaceTypeEnum.kCylinderSurface:
    print(surface.Radius, surface.AxisVector.X, surface.AxisVector.Y, surface.AxisVector.Z)

Edge curve type

Geometry class

kLineCurve

Line

kLineSegmentCurve

LineSegment

kCircleCurve

Circle

kCircularArcCurve

Arc3d

kEllipseFullCurve

EllipseFull

kEllipticalArcCurve

EllipticalArc

kBSplineCurve

BSplineCurve

kPolylineCurve

Polyline3d

Face surface type

Geometry class

kPlaneSurface

Plane

kCylinderSurface

Cylinder

kEllipticalCylinderSurface

EllipticalCylinder

kConeSurface

Cone

kEllipticalConeSurface

EllipticalCone

kTorusSurface

Torus

kSphereSurface

Sphere

kBSplineSurface

BSplineSurface

For unknown types (kUnknownCurve / kUnknownSurface) Inventor usually cannot provide the geometry; the helpers then return None as the geometry. Use edge.Evaluator / face.Evaluator for such entities.

get_edge_curve_type(edge) and get_face_surface_type(face) return only the type.

Extension methods

After import pysharpinventor, the geometry helpers are also available as methods on Edge, EdgeProxy, Face and FaceProxy objects, similar to C# extension methods:

curve_type, curve = body.Edges[1].cast_edge_geometry()
surface_type, surface = body.Faces[1].cast_face_geometry()

You can attach your own functions the same way:

from pysharpinventor._interop import register_extension

def area(face):
    return InventorInterop.Face(face).Evaluator.Area

register_extension('Face', 'area', area)
body.Faces[1].area()

Things to know

  • Units. The Inventor API works in internal units: centimetres for length and radians for angles, regardless of the document’s display units.

  • Indexing is 1-based. body.Faces[1] is the first face.

  • Iterating collections returns untyped objects. for e in body.Edges yields System.__ComObject values, which do not have the typed properties or extension methods. Cast them first: InventorInterop.Edge(e). Indexing (body.Edges[1]) returns typed objects.

  • Plane normals may point into the solid. Plane.Normal is not guaranteed to be the outward direction of a face. Flip it when face.IsParamReversed is True.

  • .NET API names differ from VBA in places. For example, use ExtrudeFeatures.Add(definition) rather than AddByDefinition.

Errors

  • InventorVersionNotFoundError - the Interop DLL could not be found. Pass inventor_path.

  • InventorConnectionError - pythonnet is missing, the DLL failed to load, or Inventor is not running (and create_if_not_exists is False).

Both can be imported from pysharpinventor.

Examples

examples/hello_world.py creates a new part containing a 5 cm cube and prints each face’s type, area and outward normal. Run it from the repository root:

python -m examples.hello_world

Metadata

Release files for pysharpinventor 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysharpinventor 0.2.0
File Size Uploaded Provenance Actions
pysharpinventor-0.2.0.tar.gz 11.8 kB Without provenance Details for pysharpinventor-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysharpinventor 0.2.0
File Interpreter ABI Platform Actions
pysharpinventor-0.2.0-py3-none-any.whl Python 3 none any Details for pysharpinventor-0.2.0-py3-none-any.whl

Total release size: 23.4 kB

Release files / pysharpinventor-0.2.0.tar.gz

Download URL pysharpinventor-0.2.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aa3295cbebf56a464179b4af88e67e62c74326699137a184ccd7f220e74946cf
BLAKE2b-256 checksum
How to use checksums
c74efda5ea99e29a7337339eecef918bd8f09fd0f981a49ebd77e7faab19539f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release files / pysharpinventor-0.2.0-py3-none-any.whl

Download URL pysharpinventor-0.2.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a11826ff1d798fbb4186ee24be65a637d2809d0242cc75b8040f65cba6caa2b9
BLAKE2b-256 checksum
How to use checksums
e58b32fc8246364a0f6792b1296f336f98937abb57d17c977a8b26ed840b04a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Security for pysharpinventor 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page