The problem related to nonlinear analysis of steel frames by taking into account local and global imperfections is analyzed. A new method for estimation of optimal (can cause worst scenario- smallest buckling load) pattern for geometrical and material imperfections is developed. The method is based on structural topology optimization. The topology is optimized in the way that maximal compliance (minimal stiffness) and strain energy is reached. According to gradient of compliance function the pattern of geometrical and material imperfections is iteratively obtained. The global geometrical imperfections are applied by using buckling modes (Eigenmodes) with calculated weight coefficient according to compliance function for each buckling mode. The proposed methods showed to be robust and practically applicable for designing of complex steel structures.