Macro for making a drawing of the building in FreeCAD

Today, I make a macro which automates the drawing of the building on drawing sheet. Here is the code of macro.

obj_list = FreeCAD.ActiveDocument.Objects                                      
App.activeDocument().Compound.Links = obj_list                                 
App.ActiveDocument.Page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'
App.ActiveDocument.View.Source = App.ActiveDocument.Compound            
App.ActiveDocument.View.Direction = (0.0,0.0,1.0)                       
App.ActiveDocument.View.X = 30.0                                        
App.ActiveDocument.View.Y = 100.0                                       
App.ActiveDocument.View.ShowHiddenLines = False                         
App.ActiveDocument.View.Scale = 2.0                                     
App.ActiveDocument.ViewIso.Source = App.ActiveDocument.Compound         
App.ActiveDocument.ViewIso.Direction = (1, 1, 1)                        
App.ActiveDocument.ViewIso.X = 335.0                                    
App.ActiveDocument.ViewIso.Y = 60.0                                     
App.ActiveDocument.ViewIso.ShowHiddenLines = True                       
App.ActiveDocument.ViewIso.Rotation = 120                               
App.ActiveDocument.ViewIso.Scale = 2.0                                  

Output when you run the above macro:
Drawing of building

Source code:

Draw whole building on drawing paper – Done

The last two-three days I stuck to drew the drawing of whole building because at present FreeCAD have not the capability for recording everything in a macro because some code is written in C++ and in Python.
After struggling, today I discussed my problem with sir and he gave me many ideas that how I can overcome this problem.

I also chat on IRC of FreeCAD channel and discuss my problem with Yorik that how to draw the drawing of the whole building through Python console. I was using fuse function of FreeCAD in ‘Part’ workbench and he told me not to use fuse function. He told to use Part MakeCompound tool and which was solved my problem. He also told that compound is much, much faster and corrected than fusing.

In python use Part.makeCompound( [list of shapes] )


Today, the whole day in TCC was bored. Some small stuff of FreeCAD I discussed with Mandeep. I have wasted the whole day and did nothing, just solved the small problems of other GD members.

Daily diary

Today, I asked the question on FreeCAD forum that macro not storing all actions that I performed in FreeCAD. At present, no response came from the FreeCAD side. If no action will come up to tomorrow then I trying to look more inside the FreeCAD source code.

I also cleared my doubts related to the pointer in C++ by making some program on linked list (transversal and insertion in linked list).

Making circle in C++ without using and Graphics libraies

Making a circle or any geometrical object by using graphics libraries is not a big deal but if we can create the geometrical object without using any graphics libraries is a little bit tricky.
Today, I made a circle without using any graphics libraries. This can be done by using the two-dimensional array and parametric equation of a circle. Here is the given below code:


using namespace std;

int main(){
    int width = 80, height = 25, radius;
    char ch;
    cout << "Enter the radius of circles less than or equal to 12: "; cin >> radius;
    cout << "\nEnter the character by which you make a circle: "; cin >>  ch;   

    // Initialise a two dimensional array
    char display[width][height];

    // Create a empty display 
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
           display[i][j] = ' '; // Every element of display equal to empty
    // Create a circle by using parametric equations of circle
    for(int angle = 0; angle < 360; angle += 1){
        // Calculate x and y by using parametic formulas of circle
        int x = (radius * cos(angle)); 
        int y = (radius * sin(angle));
        // Moving cordinates toward center of the display
        int cx = height/2 + x;
        int cy = width/2 + y;
        // Character which made the circle
        display[cx][cy] = ch;

    // Display all elements present in display array
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
           cout << display[i][j];
        cout << endl;

    return 0;


Seminar day

Today, I gave a presentation on Drawing module of FreeCAD. During the presentation, many doubts are cleared and sir told us that which things should be done to complete this project. Many interesting things I learnt today related to XML.

Daily diary

Today, I to understand Vikas Mahajan Building script. First of all, it is very difficult to understand the code written by other and also I am very new to terms like what is plinth level but after changing the dimensions of each entity in file I understand all the stuff.

pdb – The Python Debugger

The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.
By using the pdb debugger, I had set many breakpoints in the code and understand all the code of Building script.

FreeCAD Drawing module

Today, I tried to elaborate that is FreeCAD capable of converting 3D drawing to 2D and at the end of the day I said that FreeCAD fully capable of converting 3D drawing to 2D drawing by using Drawing module.

The Drawing module allows you to put your 3D work on paper. That is, to put views of your models in a 2D window and to insert that window in a drawing, for example a sheet with a border, a title and your logo and finally print that sheet. The Drawing module is currently under construction and more or less a technology preview!

When I copy paste the code present onĀ it gave the below output.

The below is updated code:

# First of all you need the Part and the Drawing module
import FreeCAD, Part, Drawing

# Create a small sample part,100,100).cut(Part.makeCylinder(80,100)).cut(Part.makeBox(90,40,100)).cut(Part.makeBox(20,85,100)))

# Direct projection. The G0 means hard edge, the G1 is tangent continuous.
Shape = App.ActiveDocument.Shape.Shape
[visibleG0,visibleG1,hiddenG0,hiddenG1] = Drawing.project(Shape)
print "visible edges:", len(visibleG0.Edges)
print "hidden edges:", len(hiddenG0.Edges)

# Everything was projected on the Z-plane:
print "Bnd Box shape: X=",Shape.BoundBox.XLength," Y=",Shape.BoundBox.YLength," Z=",Shape.BoundBox.ZLength
print "Bnd Box project: X=",visibleG0.BoundBox.XLength," Y=",visibleG0.BoundBox.YLength," Z=",visibleG0.BoundBox.ZLength

# Different projection vector
[visibleG0,visibleG1,hiddenG0,hiddenG1] = Drawing.project(Shape,App.Vector(1,1,1))

# Project to SVG
resultSVG = Drawing.projectToSVG(Shape,App.Vector(1,1,1))
print resultSVG

# Create the body
# Fuse two boxes and the cylinder
App.ActiveDocument.Fusion.Base = App.ActiveDocument.Cylinder
App.ActiveDocument.Fusion.Tool = App.ActiveDocument.Box1
App.ActiveDocument.Fusion1.Base = App.ActiveDocument.Box2
App.ActiveDocument.Fusion1.Tool = App.ActiveDocument.Fusion
# Cut the fused shapes from the first box
App.ActiveDocument.Shape.Base = App.ActiveDocument.Box 
App.ActiveDocument.Shape.Tool = App.ActiveDocument.Fusion1
# Hide all the intermediate shapes 

# Insert a Page object and assign a template
App.ActiveDocument.Page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'

# Create a view on the "Shape" object, define the position and scale and assign it to a Page
App.ActiveDocument.View.Source = App.ActiveDocument.Shape
App.ActiveDocument.View.Direction = (0.0,0.0,1.0)
App.ActiveDocument.View.X = 10.0
App.ActiveDocument.View.Y = 10.0

# Create a second view on the same object but this time the view will be rotated by 90 degrees.
App.ActiveDocument.ViewRot.Source = App.ActiveDocument.Shape
App.ActiveDocument.ViewRot.Direction = (0.0,0.0,1.0)
App.ActiveDocument.ViewRot.X = 80.0
App.ActiveDocument.ViewRot.Y = 100.0
App.ActiveDocument.ViewRot.Scale = 1.0
App.ActiveDocument.ViewRot.Rotation = 90.0

# Create a third view on the same object but with an isometric view direction. The hidden lines are activated too.
App.ActiveDocument.ViewIso.Source = App.ActiveDocument.Shape
App.ActiveDocument.ViewIso.Direction = (1.0,1.0,1.0)
App.ActiveDocument.ViewIso.X = 335.0
App.ActiveDocument.ViewIso.Y = 140.0
App.ActiveDocument.ViewIso.ShowHiddenLines = True

# Change something and update. The update process changes the view and the page.
App.ActiveDocument.View.X = 160.0
App.ActiveDocument.View.Y = 140.0
App.ActiveDocument.View.Scale = 1.0

# Get the SVG fragment of a single view
ViewSVG = App.ActiveDocument.View.ViewResult
print ViewSVG

print "Resulting SVG document: ",App.ActiveDocument.Page.PageResult
file = open(App.ActiveDocument.Page.PageResult,"r")
print "Result page is ",len(file.readlines())," lines long"

del file

# Insert a view with your content
App.ActiveDocument.ViewSelf.ViewResult = """
del ViewSVG

By running the above code we have two outputs. First is 3D design of the object.

Second is the image which is converted by using Drawing module in FreeCAD.

However, I understand the code little bit and changed the code little bit because positions of object on the drawing was not very good and they overlap with eachother.

There are many templates of drawing sheet present in FreeCAD are

Build and test SyntaxNet

Today, I tried to build and test SyntaxNet by installing all the dependencies. Testing of SyntaxNet takes one-two hours by using bazel. Bazel should complete reporting all tests passed. Here is the given below command.

bazel test syntaxnet/... util/utf8/...

But when I run the above command it gave an error.

ERROR: /home/ambu/.cache/bazel/_bazel_root/e2272cbf3f6b78513eb1686f9629a1cd/external/tf/tensorflow/core/kernels/BUILD:934:1: C++ compilation of rule '@tf//tensorflow/core/kernels:argmax_op' failed: gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -Wl,-z,-relro,-z,now -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 ... (remaining 91 argument(s) skipped): Process exited with status 4.
gcc: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.

The above error came after one hour when I run the above command. My laptop hanged and temperature of my laptop increases upto 59.0 degrees C. Then, I run the same above command, again and again, it gave the same error. Then I discuss the above error with Mandeep and he gave me a small hint and told that above same error came when he complied FreeCAD from source code. Some initial search lead to several threads that said it’s because GCC doesn’t have enough memory, so I can try following some of their advice to see if it’ll help (e.g.
When I searched it on the internet and found that how to fix this error. By adding this flag --local_resources 2048,.5,1.0 in the above command we can reducing a number of parallel builds by passing which would instruct bazel to spawn no more than one compiler process at the time. Then after adding the --local_resources 2048,.5,1.0 the above command looks like this
sudo bazel test --local_resources 2048,.5,1.0 syntaxnet/... util/utf8/... . After the run, this command SyntaxNet executed 12 out of 12 tests and 10 tests pass and 2 tests fails.
Here is the output of the above command.

INFO: Elapsed time: 2104.407s, Critical Path: 2085.13s
//syntaxnet:arc_standard_transitions_test                                PASSED in 0.0s
//syntaxnet:beam_reader_ops_test                                         PASSED in 20.0s
//syntaxnet:graph_builder_test                                           PASSED in 15.4s
//syntaxnet:lexicon_builder_test                                         PASSED in 6.4s
//syntaxnet:parser_features_test                                         PASSED in 0.1s
//syntaxnet:sentence_features_test                                       PASSED in 0.1s
//syntaxnet:shared_store_test                                            PASSED in 0.6s
//syntaxnet:tagger_transitions_test                                      PASSED in 0.5s
//syntaxnet:text_formats_test                                            PASSED in 1.8s
//util/utf8:unicodetext_unittest                                         PASSED in 0.1s
//syntaxnet:parser_trainer_test                                          FAILED in 0.1s
//syntaxnet:reader_ops_test                                              FAILED in 5.1s

Executed 12 out of 12 tests: 10 tests pass and 2 fail locally.

During whole the process, my laptop temperature increased up to 70.0 degrees C. However many errors came but at the end of the, I fixed all the errors.


Daily diary

Today, I solved the problem of my friends regarding configured Apache with CGI. There was a small problem. During running c++ program it gave an internal server error occurred. Then I see error logs of apache and solve it.

Now currently, I am working on SyntaxNet (Neural Models of Syntax).