#Fixed elastic frame structure (static analysis for distributed load) with loops to write nodes and elements for a 4x3 2D structure
#unit system: force(N) - length(m) - mass(kg)
#wipe

#Initial variables
set b 	0.3
set E 	2.e+10
set A 	[expr $b**2.]
set Iz 	[expr $b**4./12.]

#number of alignments in the x direction
set nx 4
#number of alignments in the y direction
set ny 3

set columns {0.0 4.0 8.0 12.0}
set floors {0.0 3.0 6.0}

#ModelBuilder
#model BasicBuilder -ndm 2 -ndf 3

#Nodes
#node $nodeTg (ndm $coords)
puts "frame nodes"
#iterate over nx
for {set i 0} {$i < $nx} {incr i} {
	#iterate over ny
    for {set j 0} {$j < $ny} {incr j} {
		#node id is made of two digits, xy
        set node_id [expr $i+1][expr $j+1]
		#x coordinate
        set nodex [lindex $columns $i]
		#y coordinate
        set nodey [lindex $floors $j]
        puts "node $node_id $nodex $nodey"
    }
}

#Geometric transformation
#columns
set transfTagbea 1
#geomTransf Linear $transfTagbea 0.0 0.0 1.0
#beams
set transfTagcol 2
#geomTransf Linear $transfTagcol 1.0 0.0 0.0


#Elements
#element elasticBeamColumn $eleTag $iNode $jNode $A $E $Iz $transfTag

#create a counter for elements tags
set k 1

puts "\nframe elements"
#iterate over nx
for {set i 0} {$i < $nx} {incr i} {
	#iterate over nY
    for {set j 0} {$j < $ny} {incr j} {
        #skip the elements if the top node of the column is 0 
        if {$j > 0} {
            set node_bot [expr $i+1]$j
            set node_top [expr $i+1][expr $j+1]
                puts "element elasticBeamColumn $k $node_bot $node_top $A $E $Iz $transfTagcol"
                incr k
			#and skip the elements if the beams are aligned at x = 0 
            if {$i > 0} {
                set node_lef $i[expr $j+1]
                set node_rig [expr $i+1][expr $j+1]
                puts "element elasticBeamColumn $k $node_lef $node_rig $A $E $Iz $transfTagbea"
                incr k
            }
        }
    }
    puts "..."
}

#You can continue...