From 747ed40293a8e036004539f3788117e7b0aa11d0 Mon Sep 17 00:00:00 2001 From: Vijai Kumar S Date: Wed, 15 May 2024 16:21:55 +0530 Subject: [PATCH] Modify python imports to work with SDK package too (Even if lib3mf is not installed through PyPI, the examples would work as long as the SDK structure is maintained) --- SDK/Examples/Python/3mf_convert.py | 2 -- SDK/Examples/Python/add_triangle.py | 2 -- SDK/Examples/Python/beam_lattice.py | 2 -- SDK/Examples/Python/color_cube.py | 2 -- SDK/Examples/Python/create_components.py | 2 -- SDK/Examples/Python/create_cube.py | 2 -- SDK/Examples/Python/extract_info.py | 2 -- SDK/Examples/Python/lib3mf_common.py | 22 +++++++++++++++++----- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/SDK/Examples/Python/3mf_convert.py b/SDK/Examples/Python/3mf_convert.py index 6df74a264..81a3a3cc5 100644 --- a/SDK/Examples/Python/3mf_convert.py +++ b/SDK/Examples/Python/3mf_convert.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: An example to convert between 3MF and STL Interface version: 2.3.1 diff --git a/SDK/Examples/Python/add_triangle.py b/SDK/Examples/Python/add_triangle.py index 809d500d5..311c71b87 100644 --- a/SDK/Examples/Python/add_triangle.py +++ b/SDK/Examples/Python/add_triangle.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: Simplest 3mf example that just includes a single triangle Interface version: 2.3.1 diff --git a/SDK/Examples/Python/beam_lattice.py b/SDK/Examples/Python/beam_lattice.py index 036f47747..f6ca9097a 100644 --- a/SDK/Examples/Python/beam_lattice.py +++ b/SDK/Examples/Python/beam_lattice.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: Beam Lattice example Interface version: 2.3.1 diff --git a/SDK/Examples/Python/color_cube.py b/SDK/Examples/Python/color_cube.py index a10eda52d..c7673d9e0 100644 --- a/SDK/Examples/Python/color_cube.py +++ b/SDK/Examples/Python/color_cube.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: Color cube example Interface version: 2.3.1 diff --git a/SDK/Examples/Python/create_components.py b/SDK/Examples/Python/create_components.py index 07be5b11b..63e4164e9 100644 --- a/SDK/Examples/Python/create_components.py +++ b/SDK/Examples/Python/create_components.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: An example that creates multiple components using transformations Interface version: 2.3.1 diff --git a/SDK/Examples/Python/create_cube.py b/SDK/Examples/Python/create_cube.py index d71b50887..1f82ecb0e 100644 --- a/SDK/Examples/Python/create_cube.py +++ b/SDK/Examples/Python/create_cube.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: Create a simple cube Interface version: 2.3.1 diff --git a/SDK/Examples/Python/extract_info.py b/SDK/Examples/Python/extract_info.py index 2bf23b05a..62e325587 100644 --- a/SDK/Examples/Python/extract_info.py +++ b/SDK/Examples/Python/extract_info.py @@ -24,8 +24,6 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: Extract info from a 3MF model Interface version: 2.3.1 diff --git a/SDK/Examples/Python/lib3mf_common.py b/SDK/Examples/Python/lib3mf_common.py index 64e5739cc..058a66c59 100644 --- a/SDK/Examples/Python/lib3mf_common.py +++ b/SDK/Examples/Python/lib3mf_common.py @@ -24,16 +24,28 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0-develop. - Abstract: Common set of functions that are used across all examples Interface version: 2.3.1 ''' -import lib3mf -from lib3mf import get_wrapper +import os +import sys + +try: + import lib3mf + from lib3mf import get_wrapper +except ImportError: + sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "Bindings", "Python")) + import Lib3MF as lib3mf + import Lib3MF + + + def get_wrapper(): + libpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "Bin") + wrapper = Lib3MF.Wrapper(os.path.join(libpath, "lib3mf")) + return wrapper def create_vertex(_mesh, x, y, z): @@ -63,7 +75,6 @@ def add_triangle(_mesh, p1, p2, p3): return triangle - def get_version(wrapper): major, minor, micro = wrapper.GetLibraryVersion() print("Lib3MF version: {:d}.{:d}.{:d}".format(major, minor, micro), end="") @@ -150,6 +161,7 @@ def create_beam(v0, v1, r0, r1, c0, c1): beam.CapModes[1] = convert_beam_string_to_enum(c1) return beam + def create_triangle_color(color_group, color_id1, color_id2, color_id3): triangle_properties = lib3mf.TriangleProperties() triangle_properties.ResourceID = color_group.GetResourceID()