Skip to main content

pySldWrap

PySldWrap is a python library used for altering and interacting with SolidWorks models through the SolidWorks API. A number of python functions are implemented to interact with the SolidWorks software. This includes features like

  • opening parts and assemblies
  • modifying sketches and extrudes
  • exporting to .STEP
  • exporting the mass properties of a part
  • replacing parts of an assembly

Installation

The package can be installed through pip by running the following command.

    pip install pySldWrap

Getting started

Before running a script, SolidWorks should be opened. This can be the default blank screen at start up. An example on how to open and close a part is given below.

opening/closing a part

    import pySldWrap.sw_tools as sw_tools
    from pathlib import Path

    sw_tools.connect_sw("2019")  # open connection and pass Solidworks version

    path = 'part.SLDPRT'
    # path = Path(path)  # a path object can also be used for a number of functions
    model = sw_tools.open_part(path)  # open the model, link is returned
    sw_tools.close(path)  # close the model

editing a part

A part can be modified when it is opened. When you are done editing a part, it should be saved before closing again.Saving can be done with save_model() or open_save_part(). The latter function also triggers a rebuild of the part before saving which could be necessary for some modifications.

    path = 'part.SLDPRT'
    model = sw_tools.open_part(path)

    # the part can be edited here

    sw_tools.save_model(model)
    sw_tools.close(path)

Another convenient way of modifying a part is by using EditPart() which uses python's context manager.

    path = 'part.SLDPRT'
    with sw_tools.EditPart(path) as model:
        # the part can be edited here

Upon entering the with block, the part is opened. Within this block the part can then be edited. The part is then automatically rebuild and saved before exiting the with block.

modifying a sketch of a part

Lets say the part 'part.SLDPRT' has a sketch 'shape' with a dimension called 'length'. The value of this dimension can then be modified with the function edit_dimension_sketch().

    new_length = 0.5
    sw_tools.edit_dimension_sketch(model, "shape", "length", new_length)

The part can then be rebuilt and saved with save_model().

    sw_tools.open_save_part(model)

Or with the context manager.

    path = 'part.SLDPRT'
    with sw_tools.EditPart(path) as model:
        new_length = 0.5
        sw_tools.edit_dimension_sketch(model, "shape", "length", new_length)

modifying the value of an extrude

    new_length = 0.35
    sw_tools.edit_dimension_extrude(model, "extrude_name", new_length)

get the mass properties of a part

THe function mass_properties() extracts the mass properties along a certain coordinate system and returns the properties in a python dictionary. The properties COM, volume, surface, mass and moment of inertia I around all axes.

    coord_sys_name = "CoordinateSystem_API"
    properties = sw_tools.mass_properties(model, coord_sys_name=coord_sys_name)

exporting to .STEP

A part or assembly can be exported to a destination directory with export_to_step().

    dst = './export_name.STEP'
    res = sw_tools.export_to_step(path_model, dst=dst)

editing a pattern

    sw_tools.edit_pattern(model, "pattern_name", D1TotalInstances=8)

opening an assembly

    path_asm = 'assembly.SLDASM'    # should be absolute path here
    sw_tools.open_assembly(path_asm)

More info on the available functions and their arguments can be found in the docstrings.

How does it work

This library uses the pywin32 project (win32com python library) to communicate with the COM interface of the Solidworks API. Python functions are then wrapped around a subset of the Solidworks API.

Metadata

Release files for pySldWrap 0.2

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

Source distribution (sdist)

Source distribution for pySldWrap 0.2
File Size Uploaded Provenance Actions
pySldWrap-0.2.tar.gz 8.2 kB Without provenance Details for pySldWrap-0.2.tar.gz

Built distribution (wheel)

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

Total release size: 16.9 kB

Release files / pySldWrap-0.2.tar.gz

Download URL pySldWrap-0.2.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f58ff951bddbba32a6b6d55cfbebadf2858ffddf863ca7f8921c64b89e02b641
BLAKE2b-256 checksum
How to use checksums
5ad9c848697f1930d33f892406451d3040d96dce4b49a715abf7a164ca9b8d7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.4

Release files / pySldWrap-0.2-py3-none-any.whl

Download URL pySldWrap-0.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6add753b5f26a3f9f20b5c1b97e4c2b9b19018c8dea3c758d717bdc23dc9829
BLAKE2b-256 checksum
How to use checksums
25339e1cf1f81ce9beaa059d759ca0aa0bc871b58930b4e2377035ab3779e0c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.4

Security for pySldWrap 0.2

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 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