Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept dict or object as import_scad destination argument #14

Closed
wants to merge 1 commit into from

Conversation

ipsod
Copy link

@ipsod ipsod commented Mar 17, 2023

No description provided.

@ipsod ipsod changed the title let import_scad destination be object or dict accept dict as import_scad destination argument Mar 17, 2023
@ipsod ipsod changed the title accept dict as import_scad destination argument accept dict or object as import_scad destination argument Mar 17, 2023
@jeff-dh
Copy link
Owner

jeff-dh commented Mar 17, 2023

hmmmmm.....

myDict = import_scad("MCAD").__dict__

?

@ipsod
Copy link
Author

ipsod commented Mar 17, 2023

Oops. I meant for either of these to work:

my_dict: dict = import_scad("MCAD", {})
my_obj: ExpSolidNamespace = import_scad("MCAD")

So, code should be:

def import_scad(filename, dest=None, use_not_include=True, skip_render=False):
    if dest == None:
        dest = ExpSolidNamespace(filename)

    try:
        to_dict = dest.__dict__
    except AttributeError:
        to_dict = dest

    load_scad_file_or_dir_into_dict(filename, to_dict, use_not_include, skip_render)

    return dest

or, instead of modifying, add a new function, would probably be better?

def import_scad_to_dict(filename, dest=None, use_not_include=True, skip_render=False):
    if dest == None:
        dest = {}

    load_scad_file_or_dir_into_dict(filename, to_dict, use_not_include, skip_render)

    return dest

plus add the new function to init.py ?

@jeff-dh
Copy link
Owner

jeff-dh commented Mar 17, 2023

Furthermore -- it's still about the code from the other pr -- what about this:

polyGear = import_scad("/gk/shapes/PolyGear/PolyGear.scad")
class What:
    def ever(...):
        [...]
        polyGear.spur_gear(....)
        [...]

@jeff-dh
Copy link
Owner

jeff-dh commented Mar 17, 2023

I don't see why you need it, this code should be fine:

mydict: dict = import_scad("MCAD").__dict__
mynamespace: ExpSolidNamespace = import_scad("MCAD")

@ipsod
Copy link
Author

ipsod commented Mar 17, 2023

That works, thanks!

@ipsod ipsod closed this Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants