How piping macros are made

From Open Source Ecology
Jump to: navigation, search

The piping macros are not more developed. Instead we focus on OSE piping workbench

For general FreeCAD programming see video tutorial FreeCAD Programming 101 and slides FreeCAD Workbench Programming 101 from Stephen. Here is Ruslan's way to make piping macros:

This is a rough description of my work flow.

  1. At first, I realize that I do an annoying repetitive task. Repetitive has two meanings: first, you will perform this task multiple times; second, the task is performed by multiple people with different parameters.
  2. I think about geometry and possible geometries. I try not to reinvent the wheel and stick to parameters given by manufactures as much as possible.
  3. I think about number of parameters. Try to use as view parameters as possible.
  4. Often I literally make a back-of-the-envelope calculation. (Why waste paper for it?). I also have a little white board (Actually I have multiple, at my bed, at my desk... You never know when an idea will suddenly visit you and keep your mind in hostage until you write it down). I use the white board to make calculations which involve a lot of corrections. And no -- I do not write on glass surfaces, like Hollywood tries to suggest to you.
  5. I create a 2D-drawing in LibreCAD. I will use it for documentation and GUI later. I also look at it during programming.
  6. I take my recent macro, which is similar to my task remove GUI and Table parts and make a basic macro. A basic macro means, it creates a part with default parameters. Always have default parameters for testing. This process involves many experiments with python console of FreeCAD. Do not forget to switch on Report view from main Menu, for debugging and error messages: View->Panels->Report View.
  7. I add a "Table"-Feature to my macro. This involve reading a CSV-file and put corresponding parameters into basic macro and run the basic macro. I have some test function, which creates all the parts from my parameter tables. "add" means here, copy from the previous macro and adjust.
  8. Finally I add GUI to my macro.
  9. Modularity-schmodularity. Parts of my code are redundant, because I had problems to share code between macros in FreeCAD. But I hope to figure out how to fix it. A little advantage of non-modular structure is that one needs only a macro file create-xy.FCMacro and a table xy.csv to create a macro.

Example Pipe frame box for D3D printer

Important remark: This attempt, to create a frame box macro, was a failure. I will keep it for historical reasons.

  1. I spent hours trying to make a frame box of PVC pipe. Moving parts precisely, when you do not see them properly is not very simple in FreeCAD. The pipes must be aligned to the internal structure of the corners. Even the frame-view is little bit confusing. Once you realized that you select a wrong corner or pipe in the middle of process, you need to do everything again. This is a annoying task. I need to perform it each time, I have another corner part or different pipe dimensions. Mixing metric units and the strange units (😉 + 😭) makes the process not easier. Because of availability of corner-parts and different box sizes, this task needs to be customized by any other developer. Each developer will perform this task.
  2. Number of parameters are: box dimensions in x, y and z direction, measured between the center lines of the pipes; corner dimension "G", which describes the distance from the corner "center" to the edge of a pipe; outer diameter of the pipe. All other dimensions, will be derived from them. Mechanically, you can have a more optimal structure, if you select different pipe dimensions adjusted to different structural stresses. But too many different parts increase product complexity. We want to keep it simple and interchange parts if necessary.
    When I choose test dimensions I try to use different number. This will help me to check, if the parts are positioned properly. For exmple the box dimensions are: G = 2", LX = 12", LY = 10", and LZ = 8".
  3. My envelope calculations:
  4. I make a LibreCAD drawing File:Pipe-frame-box.dxf. I export it to png. I scale the suggested pictures size by 0.5
    I realize that I do not need the pipe outer diameter.
  5. It is time to create a new branch of my git repository and add my 2D graphics to it:
    git checkout -b pipe-box
    I should have done it earlier -- when I started to draw the LibreCAD.
    git add doc/pipe-frame-box.dxf
    git add macros/pipe-frame-box-dimensions.png
    git commit
  6. I have chosen to modify create-outer-corner.FCMacro and call the macro create-frame-box.FCMacro. The basic macro results to
    I send the first version of the macro to github:
    git add macros/create-frame-box.FCMacro
    git push origin pipe-box
  7. I add GUI part from create-pipe.FCMacro. There I remove part with table loading, because I do not have table in box-GUI. I create create-frame-box.ui from create-pipe.ui. Convert it python.
    pyside-uic --indent=0 create-frame-box.ui -o
    add add corresponding lines to create-frame-box.FCMacro.
    After I get the GUI working, I send the results again to github.
  8. I merged the branch to the main branch
    git checkout master
    git merge pipe-box
  9. Realized that the create-frame-box.FCMacro is a failure. Stop the development.
  10. After talking with developer team, I decided to reuse some ideas of the frame macro in [D3D Workbench in FreeCAD].

Failure analysis

It was a mistake to automatize the frame creation through a macro. I spent too much time for it. The reason for large development time was that a frame-box is very different from the single parts. I consists from multiple parts, therefore I could not reuse previous macros in an efficient way by just changing view things.


Focus on Flamingo. This could be solution for this kind of problems.