Skip to content

Commit

Permalink
added import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
KaratasD committed Aug 14, 2022
1 parent 6fd5481 commit be6f901
Show file tree
Hide file tree
Showing 3 changed files with 372 additions and 0 deletions.
Binary file added __pycache__/safpy.cpython-39.pyc
Binary file not shown.
365 changes: 365 additions & 0 deletions safpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,365 @@
import pandas as pd

class StructuralSchema():

def __init__(self):

self.modelDict = {
'fields' : [
'Name',
'Description',
'Discipline',
'Level of detail',
'Status',
'Owner',
'Revision number',
'Created',
'Last update',
'Source type',
'Source application',
'Source company',
'Global coordinate system',
'LCS of cross-section',
'System of units',
'SAF Version',
'Module version',
'Ignored objects',
'Ignored groups',
'Id'
],
'responses': [
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
]
}

self.projectDict = {
'fields' : [
'Name',
'Description',
'Project nr',
'Created',
'Last update',
'Project type',
'Project kind',
'Building type',
'Status',
'Location'
],
'responses' :[
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
]
}

self.materialDict = {
'Name' : [],
'Type' : [],
'Subtype' : [],
'Quality' : [],
'Unit mass [kg/m3]' : [],
'E modulus [MPa]' : [],
'G modulus [MPa]' : [],
'Poisson Coefficient' : [],
'Thermal expansion [1/K]' : [],
'Design properties' : [],
'Id' : []
}

self.sectionDict = {
'Name' : [],
'Material' : [],
'Cross-section type' : [],
'Shape' : [],
'Parameters [mm]' : [],
'Profile' : [],
'Form code' : [],
'Description ID of the profile' : [],
'Iy [m4]' : [],
'Iz [m4]' : [],
'It [m4]' : [],
'Iw [m6]' : [],
'Wply [m3]' : [],
'Wplz [m3]' : [],
'Id' : []
}

self.pointDict = {
'Name' : [],
'Coordinate X [m]' : [],
'Coordinate Y [m]' : [],
'Coordinate Z [m]' : [],
'Id' : []
}

def getModelInfo(self):

return self.modelDict

def addModelInfo(self,
modelName: str = "",
modelDesc: str = "",
modelDisp: str = "",
modelDetail: str = "",
modelStatus: str = "",
modelOwner: str = "",
modelRevNum: str = "",
modelCreated: str = "",
modelLastUpdate: str = "",
modelSourceType: str = "",
modelSourceApp: str = "",
modelSourceCompany: str = "",
modelGlobalCoords: str = "",
modelLCS: str = "",
modelUnits: str = "",
modelSAFVersion: str = "",
modelModuleVersion: str = "",
modelIgnoredObjects: str = "",
modelIgnoredGroups: str = "",
modelID: str = ""):

self.modelName = modelName
self.modelDesc = modelDesc
self.modelDisp = modelDisp
self.modelDetail = modelDetail
self.modelStatus = modelStatus
self.modelOwner = modelOwner
self.modelRevNum = modelRevNum
self.modelCreated = modelCreated
self.modelLastUpdate = modelLastUpdate
self.modelSourceType = modelSourceType
self.modelSourceApp = modelSourceApp
self.modelSourceCompany = modelSourceCompany
self.modelGlobalCoords = modelGlobalCoords
self.modelLCS = modelLCS
self.modelUnits = modelUnits
self.modelSAFVersion = modelSAFVersion
self.modelModuleVersion = modelModuleVersion
self.modelIgnoredObjects = modelIgnoredObjects
self.modelIgnoredGroups = modelIgnoredGroups
self.modelID = modelID

self.modelDict['responses'][0]=(self.modelName)
self.modelDict['responses'][1]=(self.modelDesc)
self.modelDict['responses'][2]=(self.modelDisp)
self.modelDict['responses'][3]=(self.modelDetail)
self.modelDict['responses'][4]=(self.modelStatus)
self.modelDict['responses'][5]=(self.modelOwner)
self.modelDict['responses'][6]=(self.modelRevNum)
self.modelDict['responses'][7]=(self.modelCreated)
self.modelDict['responses'][8]=(self.modelLastUpdate)
self.modelDict['responses'][9]=(self.modelSourceType)
self.modelDict['responses'][10]=(self.modelSourceApp)
self.modelDict['responses'][11]=(self.modelSourceCompany)
self.modelDict['responses'][12]=(self.modelGlobalCoords)
self.modelDict['responses'][13]=(self.modelLCS)
self.modelDict['responses'][14]=(self.modelUnits)
self.modelDict['responses'][15]=(self.modelSAFVersion)
self.modelDict['responses'][16]=(self.modelModuleVersion)
self.modelDict['responses'][17]=(self.modelIgnoredObjects)
self.modelDict['responses'][18]=(self.modelIgnoredGroups)
self.modelDict['responses'][19]=(self.modelID)

def getProjectInfo(self):

return self.projectDict

def addProjectInfo(self,
projectName: str = '',
projectDesc: str = '',
projectNr: str = '',
projectCreated: str = '',
projectLastUpdate: str = '',
projectType: str = '',
projectKind: str = '',
projectBuildingType: str = '',
projectStatus: str = '',
projectLocation: str = ''):

self.projectName = projectName
self.projectDesc = projectDesc
self.projectNr = projectNr
self.projectCreated = projectCreated
self.projectLastUpdate = projectLastUpdate
self.projectType = projectType
self.projectKind = projectKind
self.projectBuildingType = projectBuildingType
self.projectStatus = projectStatus
self.projectLocation = projectLocation

self.projectDict['responses'][0]=(self.projectName)
self.projectDict['responses'][1]=(self.projectDesc)
self.projectDict['responses'][2]=(self.projectNr)
self.projectDict['responses'][3]=(self.projectCreated)
self.projectDict['responses'][4]=(self.projectLastUpdate)
self.projectDict['responses'][5]=(self.projectType)
self.projectDict['responses'][6]=(self.projectKind)
self.projectDict['responses'][7]=(self.projectBuildingType)
self.projectDict['responses'][8]=(self.projectStatus)
self.projectDict['responses'][9]=(self.projectLocation)

def getMaterialInfo(self):

return self.materialDict

def addMaterial(self,
materialName: str = "",
materialType: str = "",
materialSubtype: str = "",
materialQuality: str = "",
materialUnitMass: float = None,
materialEMod: float = None,
materialGMod: float = None,
materialPoisson: float = None,
materialThermal: float = None,
materialDesignProps: float = None,
materialId: int = None):

self.materialName = materialName
self.materialType = materialType
self.materialSubtype = materialSubtype
self.materialQuality= materialQuality
self.materialUnitMass = materialUnitMass
self.materialEMod = materialEMod
self.materialGMod = materialGMod
self.materialPoisson = materialPoisson
self.materialThermal = materialThermal
self.materialDesignProps = materialDesignProps
self.materialId = materialId

self.materialDict['Name'].append(self.materialName)
self.materialDict['Type'].append(self.materialType)
self.materialDict['Subtype'].append(self.materialSubtype)
self.materialDict['Quality'].append(self.materialQuality)
self.materialDict['Unit mass [kg/m3]'].append(self.materialUnitMass)
self.materialDict['E modulus [MPa]'].append(self.materialEMod)
self.materialDict['G modulus [MPa]'].append(self.materialGMod)
self.materialDict['Poisson Coefficient'].append(self.materialPoisson)
self.materialDict['Thermal expansion [1/K]'].append(self.materialThermal)
self.materialDict['Design properties'].append(self.materialDesignProps)
self.materialDict['Id'].append(self.materialId)

def getSectionInfo(self):

return self.sectionDict

def addSection(self,
sectionName: str = "",
sectionMaterial: str = "",
sectionType: str = "",
sectionShape: str = "",
sectionParameters: float = None,
sectionProfile: str = "",
sectionFormCode: str = "",
sectionDescription: int = None,
sectionArea: float = None,
sectionIy: float = None,
sectionIz: float = None,
sectionIt: float = None,
sectionIw: float = None,
sectionWply: float = None,
sectionWplz: float = None,
sectionId: int = None):

self.sectionName = sectionName
self.sectionMaterial = sectionMaterial
self.sectionType = sectionType
self.sectionShape = sectionShape
self.sectionParameters = sectionParameters
self.sectionProfile = sectionProfile
self.sectionFormCode = sectionFormCode
self.sectionDescription = sectionDescription
self.sectionArea = sectionArea
self.sectionIy = sectionIy
self.sectionIz = sectionIz
self.sectionIt = sectionIt
self.sectionIw = sectionIw
self.sectionWply = sectionWply
self.sectionWplz = sectionWplz
self.sectionId = sectionId

self.sectionDict['Name'].append(self.sectionName)
self.sectionDict['Material'].append(self.sectionMaterial)
self.sectionDict['Cross-section type'].append(self.sectionType)
self.sectionDict['Shape'].append(self.sectionShape)
self.sectionDict['Parameters [mm]'].append(self.sectionParameters)
self.sectionDict['Profile'].append(self.sectionProfile)
self.sectionDict['Form code'].append(self.sectionFormCode)
self.sectionDict['Description ID of the profile'].append(self.sectionDescription)
self.sectionDict['Iy [m4]'].append(self.sectionIy)
self.sectionDict['Iz [m4]'].append(self.sectionIz)
self.sectionDict['It [m4]'].append(self.sectionIt)
self.sectionDict['Iw [m6]'].append(self.sectionIw)
self.sectionDict['Wply [m3]'].append(self.sectionWply)
self.sectionDict['Wplz [m3]'].append(self.sectionWplz)
self.sectionDict['Id'].append(self.sectionId)

def getPointInfo(self):

return self.pointDict

def addPoint(self,
pointName: str = "",
pointX: float = None,
pointY: float = None,
pointZ: float = None,
pointId: int = None):

self.pointName = pointName
self.pointX = pointX
self.pointY = pointY
self.pointZ = pointZ
self.pointId = pointId

self.pointDict['Name'].append(self.pointName)
self.pointDict['Coordinate X [m]'].append(self.pointX)
self.pointDict['Coordinate Y [m]'].append(self.pointY)
self.pointDict['Coordinate Z [m]'].append(self.pointZ)
self.pointDict['Id'].append(self.pointId)

def exportExcel(self):

modelFrame = pd.DataFrame(self.modelDict)
projectFrame = pd.DataFrame(self.projectDict)
materialFrame = pd.DataFrame(self.materialDict)
sectionFrame = pd.DataFrame(self.sectionDict)
pointFrame = pd.DataFrame(self.pointDict)

safFile = pd.ExcelWriter(r'C:\Users\KaratasD\Desktop\Folders\safpy\mySAF.xlsx')

modelFrame.to_excel(safFile, sheet_name='Model', index=False, header=False)
projectFrame.to_excel(safFile, sheet_name='Project', index=False, header=False)
materialFrame.to_excel(safFile, sheet_name='StructuralMaterial', index=False)
sectionFrame.to_excel(safFile, sheet_name='StructuralCrossSection', index=False)
pointFrame.to_excel(safFile, sheet_name='StructuralPointConnection', index=False)

safFile.save()



7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from safpy import StructuralSchema

mySAF = StructuralSchema()
mySAF.addModelInfo("myFirstTry")
mySAF.addMaterial("myFirstMaterial")


0 comments on commit be6f901

Please sign in to comment.