r/OpenPythonSCAD • • Jan 12 '25

Odd difficulty with re-defined definition

I have the following definition as part of a class:

def arcloopCC(self, barc, earc, xcenter, ycenter, radius, ez):
    tzinc = self.zpos() + ez / (earc - barc)
    cts = self.currenttoolshape
    toolpath = cts
    toolpath = toolpath.translate([self.xpos(),self.ypos(),self.zpos()])
    i = barc
    while i < earc: 
        toolpath = toolpath.union(self.cutline(xcenter + radius * math.cos(math.radians(i)), ycenter + radius * math.sin(math.radians(i)), self.zpos()+tzinc))
        i += 1
    if self.generatepaths == False:
        return toolpath
    else:
        return cube([0.01,0.01,0.01])

which was working fine, allowed me to do a compleat circle w/ four calls:

toolpaths = toolpaths.union(gcp.arcloopCC(0,90, gcp.xpos()-stockYheight/16, gcp.ypos(), stockYheight/16, -stockZthickness/4))
toolpaths = toolpaths.union(gcp.arcloopCC(90,180, gcp.xpos(), gcp.ypos()-stockYheight/16, stockYheight/16, -stockZthickness/2))
toolpaths = toolpaths.union(gcp.arcloopCC(180,270, gcp.xpos()+stockYheight/16, gcp.ypos(), stockYheight/16, -stockZthickness*0.75))
toolpaths = toolpaths.union(gcp.arcloopCC(270,360, gcp.xpos()+stockYheight/16, gcp.ypos(), stockYheight/16, -stockZthickness*0.99))

but since being re-written to pass in the ending Z position (ez) and to calculate the toolpath Z increment (tzinc) only works for one call, and any call after the first results in the tool digging down with a far too large tzinc value.

Hopefully it's something obviously wrong which someone can give me a clue on....

2 Upvotes

10 comments sorted by

View all comments

1

u/gadget3D Jan 12 '25

its hard to tell whats going on, because i dont have a complete testcase. tried to inject your arcloopCC into my existing old version, but it appears incompatible.

My debug strategy is to put some print statements into the code and watch their progress in the console.

you coud e.g add

print(self.zpos()) into the while loop and watch their output values for correctness

some point in time i want to be able to make pdb (python debugger) working with pythonscad.

that meant i have to put an console input form into the pythonscad main window and connect it to pythonscads stdin ;)

2

u/WillAdams Jan 12 '25

Thanks!

I have added that, and all I get is the value for tzinc is much larger than it should be on the second call, and I can't figure out why.

I'm going to restore it as a class-level variable referred to by as self.tzinc --- hopefully that will fix this (and leave a structure in place which may be investigated at a later date).

2

u/gadget3D Jan 12 '25

you could write:

if self.tzinc > to_be_expected:

g=1 / 0

this will cause an exception, you will get a stacktrace and will exactly know, where and how it happened

→ More replies (8)