Example file is download from Frame3DD Example.
Now, can show only joints and members not included reactions, loads, displacment, internal forces.
source code : ReadFile2Model.py **** important note: if data file is not correct format,it will be run infinite loop(Fixed in Version2) ****
Code: Select all
import FreeCAD , Draft
from FreeCAD import Vector
class Node:
def __init__(self, id , x,y,z):
self.x = x
self.y = y
self.z = z
self.id = str(id)
# elmnt n1 n2 Ax Asy Asz Jx Iy Iz E G roll density
class Member:
def __init__(self, id , n1,n2):
self.n1 = n1
self.n2 = n2
self.id = str(id)
NodeList = {}
MemberList = {}
ProjectDescription = ''
numNode = 0
state = 1
path = 'D:\\StructurallAnalysis\\Frame3DD\\Data\\'
#factor = 25.42 ; fName = path+'exA.3dd'
#factor = 1.0 ;fName = path+'exB.3dd'
#factor = 25.42 ; fName = path+'exC.3dd'
factor = 25.42 ; fName = path+'exD.3dd'
#factor = 25.42 ; fName = path+'exG.3dd'
#factor = 25.42 ; fName = path+'exF.3dd'
fp = open(fName)
while 1:
line = fp.readline()
if not line:
break
line = line.strip()
if len(line)==0:
continue
if line[0]=='#':
continue
# process
if state==1:
ProjectDescription = line
Msg(ProjectDescription); Msg('\n\n')
state += 1
continue
if state==2: # Node
Msg('State2: ');Msg(line); Msg('\n')
data = line.split()
numNode = int(data[0])
nodeCount = 1
while 1:
line = fp.readline().strip()
if len(line)==0 or line[0]=='#':
continue
#Msg( line ); Msg('\n')
dataNode = line.split()
NodeList[dataNode[0]] = Node(dataNode[0] ,
float(dataNode[1]) ,float( dataNode[2]) , float( dataNode[3]) )
nodeCount+=1
if nodeCount>numNode:
break
state += 1
continue
if state==3: # Reaction
Msg('State3: '); Msg(line); Msg('\n')
data = line.split()
numReaction = int(data[0])
if numReaction==0:
state += 1
continue
reactionCount = 1
while 1:
line = fp.readline().strip()
if len(line)==0 or line[0]=='#':
continue
#Msg( line ); Msg('\n')
dataReaction = line.split()
#NodeList[dataNode[0]] = Node(dataNode[0] ,
# float(dataNode[1]) ,float( dataNode[2]) , float( dataNode[3]) )
reactionCount+=1
if reactionCount>numReaction:
break
state += 1
continue
#Msg('Member Data\n')
if state==4: # Member
Msg('State4: '); Msg(line); Msg('\n')
data = line.split()
numMember = int(data[0])
memberCount = 1
while 1:
line = fp.readline().strip()
if len(line)==0 or line[0]=='#':
continue
Msg( line ); Msg('\n')
dataMember = line.split()
MemberList[dataMember[0]] = Member(dataMember[0] ,dataMember[1] , dataMember[2])
memberCount+=1
if memberCount>numMember:
break
state += 1
continue
#Msg( line ); Msg('\n')
GrpNode =FreeCAD.ActiveDocument.getObject('Nodes')
GrpNode.removeObjectsFromDocument()
for id in NodeList:
#Msg(id ); Msg( iNode) ; Msg('\n')
iPoint = Draft.makePoint(NodeList[id].x*factor,NodeList[id].y*factor,NodeList[id].z*factor)
iPoint.Label = id
iPoint.ViewObject.PointColor = (0.667,0.000,0.000)
GrpNode.addObject(iPoint)
GrpMember =FreeCAD.ActiveDocument.getObject('Members')
GrpMember.removeObjectsFromDocument()
for id in MemberList:
n1 = MemberList[id].n1
n2 = MemberList[id].n2
points=[ Vector(NodeList[n1].x*factor,NodeList[n1].y*factor,NodeList[n1].z*factor ) ,
Vector(NodeList[n2].x*factor,NodeList[n2].y*factor,NodeList[n2].z*factor) ]
iMember = Draft.makeWire(points,closed=False,face=True,support=None)
iMember.Label = id
GrpMember.addObject(iMember)
Msg('Done!!\n\n')