Get the size of the stock in a custom postprocessor

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
thomas-huber
Posts: 13
Joined: Wed Jan 26, 2022 4:02 pm
Location: Oberneukirchen, Bavaria

Get the size of the stock in a custom postprocessor

Post by thomas-huber »

Hello everybody.

I'm trying to write a post processor for our scm record 110 cnc maschine (xilog based).

So far progress is good, but im stuck with the following:
Programs for our cnc must include header-line where the size (height, width, depth) of the stock object is defined. In FreeCAD the stock geometry is defined with a Job but I can't figure out how to access it from withing the postprocessor. :?

Thank's in advance, please let me know if you need more information.

Best
Thomas
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Get the size of the stock in a custom postprocessor

Post by chrisb »

It is too long ago that I programmed my postprocessor, and I'm sure that I didn't access the job at all. If you have access to the Job and it is stored in a variable called "job", then you can get the information you are looking for with

Code: Select all

job.Stock.Shape.BoundBox
For a default 10x10x10 cube and a default job the result would be

Code: Select all

BoundBox (-1, -1, -1, 11, 11, 11)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
thomas-huber
Posts: 13
Joined: Wed Jan 26, 2022 4:02 pm
Location: Oberneukirchen, Bavaria

Re: Get the size of the stock in a custom postprocessor

Post by thomas-huber »

Hi chrisb,
thank's for your answer.
The postprocessor's export function only gets a list of objects but not the job itself. So it was a bit tricky to access it.
Here is what I did:

Code: Select all

    doc = None
    for obj in objectslist:
        if hasattr(obj, "Document"):
            doc = obj.Document
    box = doc.Job.Stock.Shape.BoundBox
It feels a like a hack, and it will not work if Job is named to something else, but it will do the trick for me.
User avatar
dubstar-04
Posts: 698
Joined: Mon Mar 04, 2013 8:41 pm
Location: Chester, UK
Contact:

Re: Get the size of the stock in a custom postprocessor

Post by dubstar-04 »

thomas-huber wrote: Thu Jan 27, 2022 10:16 am It feels a like a hack, and it will not work if Job is named to something else, but it will do the trick for me.
Is this any use:

https://github.com/FreeCAD/FreeCAD/blob ... ls.py#L393

Thanks,

Dan
thomas-huber
Posts: 13
Joined: Wed Jan 26, 2022 4:02 pm
Location: Oberneukirchen, Bavaria

Re: Get the size of the stock in a custom postprocessor

Post by thomas-huber »

Oh thanks, that's perfect!
Post Reply