| Name | cadvectorgraphics JSON |
| Version |
1.0.0
JSON |
| download |
| home_page | None |
| Summary | A python package for generating beautiful SVG from CAD data |
| upload_time | 2024-08-26 08:29:25 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|

# Converting CAD-files to beautiful Scalable Vector Graphics
## Motivation
Have you ever gotten annoyed by MS Word minimizing the resolution of your images? Did you ever feel the frustration of losing the fine details in your illustrations in just a few pixels? - Then you are in the right place!
This python project aims to provide a possibility to render a CAD object as a vector graphic, namely a SVG.
## Implemented Features ... so far
Integreted features are:
* importing `.step` files or importing `cadquery`-objects
* import of single part or assemblies
* creating a triangular surface mesh of the imported model using a simplified interface to the `gmsh` library
* colorizing each imported model
* setting the material properties ka, kd, ks and the shininess for rendering the object
* setting a view position
* adding multiple light sources, given by color and position
* rendering which includes shading of the object
* adding different edge line styles and face outline styles
* adding and configuring a coordinate system
* scaling the resulting image, giving margins and zooming into the object
* exporting the image as SVG
## What's next?
Although the use case is very specific, there are still several features that might be nice to have:
* exporting the created meshes
* generating volume meshes for external simulations, also non-linear elements
* importing simulation data
* displaying simulation data requires implementing a legend
* cutting models and showing the cut surfaces using line patterns similair to technical drawings
* annotations using arrows and labels
* shallow dimensioning
* illustrating rotation axes
* exporting images as EMF, PDF, TIKZ ...
* anything that comes to mind by the users
## Installation
Before installation, please make sure to have the right versions of gmsh, numpy, meshio and cadquery installed
```
pip install cadquery, meshio, gmsh, numpy==1.26.0
```
The package can then be installed using pip with the following command:
```
pip install cadvectorgraphics
```
## Troubleshooting
### SVG not really working for MS office applications
A scalable vector graphic might not be the best choice for the use in MS office applications. A better option would be to use the Enhanced Meta File (EMF). However it's quite easy to convert an SVG to an EMF file using Inkscape. You can either open the SVG in Inkscape directly and save it as a new file with the suitable extension.

The other method is to use Inksckape from the command line.
```bat
cd [DIR_TO_MY_FILE]
inkscape "[FILENAME].svg" --export-filename="[FILENAME].emf" --export-dpi="[DPI]"
```
Of coarse you have to adjust `DIR_TO_MY_FILE`, `FILENAME` and `DPI` according to your needs. You can find more information on that [here](https://wiki.inkscape.org/wiki/Using_the_Command_Line). Do not forget to add the `inkscape.exe` to your PATH before executing the command.
## Example
In the following, a small example script is provided.
```python
from cadvectorgraphics import *
from cadquery import Workplane, exporters
# providing an initial model with cadquery
# the CAD-file can be obtained from any prefered CAD-system
box = Workplane().box( 10, 10, 10 ).edges( "|Z" ).fillet( 1 ).faces(">Z").workplane().cboreHole( 5, 7, 3 )
exporters.export( box, "model.step" )
# importing the file to a CAD-model representation
part = PartRepresentation( "model.step" )
part.color( 0, ( 100, 200, 100 ) )
# creating a mesh from the CAD-file
part.tessellateAll( size = MeshSize.GRAINY )
# creating a scene to assemble all necessary objects such as the view, the ligths and the model
scene = VirtualScene( part )
scene.setCameraPosition( position = ( 15, 15, 15 ) )
# adding a light source
# multiple lights can be added
# if none is added, the object will be displayed with the given base color
lightSource = LightSource( position = ( 20, 10, 0 ) )
lightSource.color = ( 150, 50, 255 )
scene.appendLightSource( light = lightSource )
# adding the scene with all components to a renderer
renderer: VirtualRenderer = VirtualRenderer( scene )
renderer.render()
# creating an image from the renderer result
image = Image( renderer )
# zooming into the geometry
image.zoom = ( 10, 10 )
# scaling all elements of the image
image.scale = ( 1, 1 )
# setting margins
image.margins = ( 5, 5 )
# creating line styles for special edges and curves
# if none is added, only the mesh is visible
visibleOutlineStyle = LineStyle( EdgeRepresentationType.VISIBLEOUTLINE )
visibleOutlineStyle.width = 0.25
visibleOutlineStyle.color = ( 0, 0, 0 )
image.addLineStyle( visibleOutlineStyle )
visibleSharpStyle = LineStyle( EdgeRepresentationType.VISIBLESHARPWIRE )
visibleSharpStyle.width = 0.25
visibleSharpStyle.color = ( 0, 0, 0 )
image.addLineStyle( visibleSharpStyle )
visibleSmoothStyle = LineStyle( EdgeRepresentationType.VISIBLESMOOTHWIRE )
visibleSmoothStyle.width = 0.1
visibleSmoothStyle.color = ( 0, 0, 0 )
visibleSmoothStyle.dash = ( 1, 0.2, 0.2, 0.2 )
image.addLineStyle( visibleSmoothStyle )
# creating style information for the coordinate system
coordStyle = CoordSystemStyle( size = 30 )
image.setCoordSystemStyle( coordStyle )
# export the image as svg
image.write()
```
This script has the following output then.

Raw data
{
"_id": null,
"home_page": null,
"name": "cadvectorgraphics",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Dennis Schulz <dennisschulz2000@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a8/7d/85569a1d033948cf8e0a3c7f43055b1dd2caa9928032c706464fc8e7cac5/cadvectorgraphics-1.0.0.tar.gz",
"platform": null,
"description": "\r\n\r\n# Converting CAD-files to beautiful Scalable Vector Graphics\r\n\r\n## Motivation\r\nHave you ever gotten annoyed by MS Word minimizing the resolution of your images? Did you ever feel the frustration of losing the fine details in your illustrations in just a few pixels? - Then you are in the right place! \r\nThis python project aims to provide a possibility to render a CAD object as a vector graphic, namely a SVG. \r\n\r\n## Implemented Features ... so far\r\nIntegreted features are:\r\n* importing `.step` files or importing `cadquery`-objects\r\n* import of single part or assemblies\r\n* creating a triangular surface mesh of the imported model using a simplified interface to the `gmsh` library\r\n* colorizing each imported model\r\n* setting the material properties ka, kd, ks and the shininess for rendering the object\r\n* setting a view position\r\n* adding multiple light sources, given by color and position\r\n* rendering which includes shading of the object\r\n* adding different edge line styles and face outline styles\r\n* adding and configuring a coordinate system\r\n* scaling the resulting image, giving margins and zooming into the object\r\n* exporting the image as SVG\r\n\r\n## What's next?\r\nAlthough the use case is very specific, there are still several features that might be nice to have:\r\n* exporting the created meshes\r\n* generating volume meshes for external simulations, also non-linear elements\r\n* importing simulation data\r\n* displaying simulation data requires implementing a legend\r\n* cutting models and showing the cut surfaces using line patterns similair to technical drawings\r\n* annotations using arrows and labels\r\n* shallow dimensioning\r\n* illustrating rotation axes\r\n* exporting images as EMF, PDF, TIKZ ...\r\n* anything that comes to mind by the users\r\n\r\n## Installation\r\nBefore installation, please make sure to have the right versions of gmsh, numpy, meshio and cadquery installed\r\n```\r\npip install cadquery, meshio, gmsh, numpy==1.26.0\r\n```\r\n\r\nThe package can then be installed using pip with the following command:\r\n```\r\npip install cadvectorgraphics\r\n```\r\n\r\n## Troubleshooting\r\n\r\n### SVG not really working for MS office applications\r\nA scalable vector graphic might not be the best choice for the use in MS office applications. A better option would be to use the Enhanced Meta File (EMF). However it's quite easy to convert an SVG to an EMF file using Inkscape. You can either open the SVG in Inkscape directly and save it as a new file with the suitable extension. \r\n\r\n\r\n\r\nThe other method is to use Inksckape from the command line.\r\n```bat\r\ncd [DIR_TO_MY_FILE]\r\ninkscape \"[FILENAME].svg\" --export-filename=\"[FILENAME].emf\" --export-dpi=\"[DPI]\"\r\n```\r\nOf coarse you have to adjust `DIR_TO_MY_FILE`, `FILENAME` and `DPI` according to your needs. You can find more information on that [here](https://wiki.inkscape.org/wiki/Using_the_Command_Line). Do not forget to add the `inkscape.exe` to your PATH before executing the command.\r\n\r\n## Example\r\n\r\nIn the following, a small example script is provided.\r\n\r\n```python\r\nfrom cadvectorgraphics import *\r\n\r\nfrom cadquery import Workplane, exporters\r\n\r\n# providing an initial model with cadquery\r\n# the CAD-file can be obtained from any prefered CAD-system\r\nbox = Workplane().box( 10, 10, 10 ).edges( \"|Z\" ).fillet( 1 ).faces(\">Z\").workplane().cboreHole( 5, 7, 3 )\r\nexporters.export( box, \"model.step\" )\r\n\r\n# importing the file to a CAD-model representation\r\npart = PartRepresentation( \"model.step\" )\r\npart.color( 0, ( 100, 200, 100 ) )\r\n\r\n# creating a mesh from the CAD-file\r\npart.tessellateAll( size = MeshSize.GRAINY )\r\n\r\n# creating a scene to assemble all necessary objects such as the view, the ligths and the model\r\nscene = VirtualScene( part )\r\nscene.setCameraPosition( position = ( 15, 15, 15 ) )\r\n\r\n# adding a light source\r\n# multiple lights can be added\r\n# if none is added, the object will be displayed with the given base color\r\nlightSource = LightSource( position = ( 20, 10, 0 ) )\r\nlightSource.color = ( 150, 50, 255 )\r\nscene.appendLightSource( light = lightSource )\r\n\r\n# adding the scene with all components to a renderer\r\nrenderer: VirtualRenderer = VirtualRenderer( scene )\r\nrenderer.render()\r\n\r\n# creating an image from the renderer result\r\nimage = Image( renderer )\r\n\r\n# zooming into the geometry\r\nimage.zoom = ( 10, 10 )\r\n\r\n# scaling all elements of the image\r\nimage.scale = ( 1, 1 )\r\n\r\n# setting margins\r\nimage.margins = ( 5, 5 )\r\n\r\n# creating line styles for special edges and curves\r\n# if none is added, only the mesh is visible\r\nvisibleOutlineStyle = LineStyle( EdgeRepresentationType.VISIBLEOUTLINE )\r\nvisibleOutlineStyle.width = 0.25\r\nvisibleOutlineStyle.color = ( 0, 0, 0 )\r\nimage.addLineStyle( visibleOutlineStyle )\r\n\r\nvisibleSharpStyle = LineStyle( EdgeRepresentationType.VISIBLESHARPWIRE )\r\nvisibleSharpStyle.width = 0.25\r\nvisibleSharpStyle.color = ( 0, 0, 0 )\r\nimage.addLineStyle( visibleSharpStyle )\r\n\r\nvisibleSmoothStyle = LineStyle( EdgeRepresentationType.VISIBLESMOOTHWIRE )\r\nvisibleSmoothStyle.width = 0.1\r\nvisibleSmoothStyle.color = ( 0, 0, 0 )\r\nvisibleSmoothStyle.dash = ( 1, 0.2, 0.2, 0.2 )\r\nimage.addLineStyle( visibleSmoothStyle )\r\n\r\n# creating style information for the coordinate system\r\ncoordStyle = CoordSystemStyle( size = 30 )\r\nimage.setCoordSystemStyle( coordStyle )\r\n\r\n# export the image as svg\r\nimage.write()\r\n```\r\nThis script has the following output then. \r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A python package for generating beautiful SVG from CAD data",
"version": "1.0.0",
"project_urls": {
"Repository": "https://github.com/sxhulzenstein/CADToVectorGraphics"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "709c47bdc71d4ad029a3b0abae5516736cfc2013becae52920b30666a7264dcd",
"md5": "489314fa0abdb6df8e5928bdafbb3310",
"sha256": "2151d83a4c4d2a1d742e4930e338bd93121de5b79e8e05a465c52fe60e64d6a1"
},
"downloads": -1,
"filename": "cadvectorgraphics-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "489314fa0abdb6df8e5928bdafbb3310",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 28416,
"upload_time": "2024-08-26T08:29:23",
"upload_time_iso_8601": "2024-08-26T08:29:23.323464Z",
"url": "https://files.pythonhosted.org/packages/70/9c/47bdc71d4ad029a3b0abae5516736cfc2013becae52920b30666a7264dcd/cadvectorgraphics-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a87d85569a1d033948cf8e0a3c7f43055b1dd2caa9928032c706464fc8e7cac5",
"md5": "e5cbfaf6a2088bf4e359e80011301f80",
"sha256": "5a2ca21d785f623b420d01ecb942deea578d725e9b5c925d08c17dad41421f38"
},
"downloads": -1,
"filename": "cadvectorgraphics-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "e5cbfaf6a2088bf4e359e80011301f80",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 24302,
"upload_time": "2024-08-26T08:29:25",
"upload_time_iso_8601": "2024-08-26T08:29:25.373620Z",
"url": "https://files.pythonhosted.org/packages/a8/7d/85569a1d033948cf8e0a3c7f43055b1dd2caa9928032c706464fc8e7cac5/cadvectorgraphics-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-26 08:29:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sxhulzenstein",
"github_project": "CADToVectorGraphics",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "cadvectorgraphics"
}