Draw sectional view of object – Done

Today, I wrote the below code and by using this code, user can easily draw the sectional view of the object by simply write only two commands.

sec_obj = section_view_specs("Compound", 10, 10, 0, 0, 0, 1, 0, 100, 100, 2, 0)
draw_section_view(sec_obj, "Page")

In the below code I made a one constructor in class section_view_specs which will store all the information which will require to draw the sectional view of the object and function draw_section_view actually draw the sectional view of the given object by the information section_view_specs object.

class section_view_specs:
    def __init__(self, obj, x_dir, y_dir, z_dir, axis_x, axis_y, axis_z,
            angle2axis, x_pos, y_pos, scale, rotation):
        self.obj = obj
        self.x_dir = x_dir
        self.y_dir = y_dir
        self.z_dir = z_dir
        self.axis_x = axis_x
        self.axis_y = axis_y
        self.axis_z = axis_z
        self.angle2axis = angle2axis
        self.x_pos = x_pos
        self.y_pos = y_pos
        self.scale = scale
        self.rotation = rotation

def draw_section_view(view, page_name):
    obj_ref = App.ActiveDocument.getObject(view.obj)
    view_ref = Arch.makeSectionPlane([obj_ref])
    view_ref.Placement = App.Placement(App.Vector(view.x_dir, view.y_dir,
        view.z_dir), App.Rotation(App.Vector(view.axis_x, view.axis_y,
            view.axis_z), view.angle2axis))
    Draft.makeShape2DView(view_ref)
    page_ref = App.ActiveDocument.getObject(page_name)
    draw_ref = Draft.makeDrawingView(view_ref, page_ref)
    draw_ref.X = view.x_pos
    draw_ref.Y = view.y_pos
    draw_ref.Scale = view.scale
    draw_ref.Rotation = view.rotation
    App.ActiveDocument.recompute()

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().addObject("Part::Compound","Compound")             
App.activeDocument().Compound.Links = obj_list                                 
                                                                        
App.ActiveDocument.addObject('Drawing::FeaturePage','Page')             
App.ActiveDocument.Page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'
                                                                        
App.ActiveDocument.addObject('Drawing::FeatureViewPart','View')         
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.Page.addObject(App.ActiveDocument.View)                                                        
                                                                        
App.ActiveDocument.addObject('Drawing::FeatureViewPart','ViewIso')      
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                                  
App.ActiveDocument.Page.addObject(App.ActiveDocument.ViewIso)           
App.ActiveDocument.recompute()                                          

Output when you run the above macro:
Drawing of building

Source code:
https://github.com/amrit3701/Drawing-FreeCAD/blob/master/macro_building_drawing.py