Skip to content

Commit

Permalink
Modified precision to x/32 and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardrake committed Aug 30, 2016
1 parent e84dfda commit eb1954f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 90 deletions.
140 changes: 73 additions & 67 deletions SE_BOM_Extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,69 @@
clr.AddReference("System.Runtime.InteropServices")
import System.Runtime.InteropServices as SRI

objOccurenceSets = None
objOccurrences = None
objSubOccurenceSets = None
objSubOccurrences = None

objApplication = SRI.Marshal.GetActiveObject("SolidEdge.Application")
objDocument = objApplication.ActiveDocument
objOccurenceSets = objDocument.Occurrences

def ExtractSubOccurrence(objOccurenceSets, level=1, nomenclature = []):
#Extract part object, in index 0, 2nd level of assembly Index 1, part name, Index 2,3 and 4 are Length, Witdh and heigth
part = ["groupname", "order", "assembly", "part", "longueur", "largeur", "Epaisseur","Materiel"]



def extractsuboccurrence(objOccurenceSets, level=1, nomenclature=[]):
#Extract part object, in index 0, 2nd level of assembly Index 1, part name,
# Index 2,3 and 4 are Length, Witdh and heigth
#part = ["groupname", "order", "assembly", "part", "longueur", "largeur", "Epaisseur","Materiel"]

for i in range(objOccurenceSets.Count):
objSubOccurrences = objOccurenceSets.Item(i + 1)
if objSubOccurrences.Subassembly == False:
objsuboccurrences = objOccurenceSets.Item(i + 1)
if not objsuboccurrences.Subassembly:
try:
VariableSet = objSubOccurrences.SubOccurrenceDocument.Variables
variableset = objsuboccurrences.SubOccurrenceDocument.Variables
except:
VariableSet = None
try:
ModelsSet = objSubOccurrences.SubOccurrenceDocument.Models
variableset = None
try:
modelsset = objsuboccurrences.SubOccurrenceDocument.Models
except:
ModelsSet = None
if CheckBody(ModelsSet):
modelsset = None
if CheckBody(modelsset):
SE_long = 0
SE_larg = 0
SE_larg = 0
SE_epai = 0
for i in range(VariableSet.Count):
Variables = VariableSet.Item(i + 1)
if Variables.ExposeName == "SE_LONGUEUR":
SE_long = convert(Variables.Value)
if Variables.ExposeName == "SE_LARGEUR":
SE_larg = convert(Variables.Value)
if Variables.ExposeName == "SE_EPAISSEUR":
SE_epai = convert(Variables.Value)
SE_Material = objSubOccurrences.SubOccurrenceDocument.Properties.Item(7).Item(1).Value
SE_DocName = objSubOccurrences.SubOccurrenceDocument.Properties.Item(5).Item(1).Value
SE_TopName = findNameByLevel(objSubOccurrences,level-1)
for i in range(variableset.Count):
variables = variableset.Item(i + 1)
if variables.ExposeName == "SE_LONGUEUR":
SE_long = convert(variables.Value)
if variables.ExposeName == "SE_LARGEUR":
SE_larg = convert(variables.Value)
if variables.ExposeName == "SE_EPAISSEUR":
SE_epai = convert(variables.Value)
SE_Material = objsuboccurrences.SubOccurrenceDocument.Properties.Item(7).Item(1).Value
SE_DocName = objsuboccurrences.SubOccurrenceDocument.Properties.Item(5).Item(1).Value
SE_TopName = findnamebylevel(objsuboccurrences,level-1)
if SE_DocName == '':
SE_DocName = objSubOccurrences.Name
part = [assignGroupName(SE_TopName)[0],assignGroupName(SE_TopName)[1], SE_TopName, objOccurenceSets.Parent.Name, SE_DocName, (SE_epai, SE_larg, SE_long),SE_Material]
SE_DocName = objsuboccurrences.Name
part = [assigngroupname(SE_TopName)[0], assigngroupname(SE_TopName)[1], SE_TopName,
objOccurenceSets.Parent.Name, SE_DocName, (SE_epai, SE_larg, SE_long), SE_Material]
nomenclature.append(part)
if objSubOccurrences.SubOccurrences != None:
ExtractSubOccurrence(objSubOccurrences.SubOccurrences, level+1)
if objsuboccurrences.SubOccurrences is not None:
extractsuboccurrence(objsuboccurrences.SubOccurrences, level+1)

return nomenclature

def convert(val,frac=0.125):

def convert(val, frac=0.03125):
#convert decimal to inches
return round((int((round(val,8) / 0.0254) / frac))*frac,4)
return round((int((round(val, 8) / 0.0254) / frac))*frac, 4)


def BuildQuery(BOM):
# Build SQL Query to insert list data in SQL Table
keys_to_sql = "SE_groupname, SE_order, SE_top, SE_pere, SE_piece,SE_epaisseur,SE_largeur,SE_longueur,SE_Materiel"
SQLQuery = "INSERT INTO SE_BOM("+keys_to_sql+")"
keys_to_sql = "SE_groupname, SE_order, SE_top, SE_pere, SE_piece, SE_epaisseur, SE_largeur, SE_longueur, SE_Materiel"
sqlquery = "INSERT INTO SE_BOM("+keys_to_sql+")"
tot_rec = 0
for item in BOM:
vars_to_sql = []
tot_rec+=1
tot_rec += 1
for i in item:
value_type = type(i)
if value_type == tuple:
Expand All @@ -75,51 +77,55 @@ def BuildQuery(BOM):
vars_to_sql.append("'"+i+"'")
final_to_sql = ','.join(vars_to_sql)
if tot_rec == len(BOM):
SQLQuery = SQLQuery + "SELECT " + final_to_sql +" GO"
sqlquery = sqlquery + "SELECT " + final_to_sql + " GO"
else:
SQLQuery = SQLQuery + "SELECT " + final_to_sql + " UNION ALL "
return SQLQuery

sqlquery = sqlquery + "SELECT " + final_to_sql + " UNION ALL "
return sqlquery


def CheckBody(ModelSet):
#Function to determine if Object has a body
try:
for Model in ModelSet:
if Model.Body is not None:
BodyValid = True
bodyvalid = True
except:
BodyValid = False
return BodyValid
bodyvalid = False
return bodyvalid

def findNameByLevel(root,level):
currentElement = root;

def findnamebylevel(root, level):
currentelement = root
for currentLevel in range(level):
currentElement = currentElement.Parent
currentelement = currentelement.Parent
# current element should now be the one we are searching for
SE_DocName = currentElement.OccurrenceDocument.Properties.Item("ProjectInformation").Item("Document Number").Value
if SE_DocName == "":
return currentElement.name
else :
return SE_DocName

def assignGroupName(mur):
SE_Commentaire = objDocument.Properties.Item("SummaryInformation").Item("Commentaires").Value
listgroup = SE_Commentaire.splitlines()
se_docname = currentelement.OccurrenceDocument.Properties.Item("ProjectInformation").Item("Document Number").Value
if se_docname == "":
return currentelement.name
else:
return se_docname


def assigngroupname(mur):
se_commentaire = objDocument.Properties.Item("SummaryInformation").Item("Commentaires").Value
listgroup = se_commentaire.splitlines()
result = ""
for idx, val in enumerate(listgroup):
if mur in val:
result = ("MUR "+ val, str(idx+1))
result = ("MUR " + val, str(idx+1))
if result == '':
result = ("MUR "+ mur, "9")
result = ("MUR " + mur, "9")
#print result
return result

MP = ExtractSubOccurrence(objOccurenceSets)
return result


MP = extractsuboccurrence(objOccurenceSets)

#BuildQuery(MP)
pySqlOperation.ZapSE_BOM()
pySqlOperation.executeSQLQuery(BuildQuery(MP))



pySqlOperation.executeSQLQuery(BuildQuery(MP))






24 changes: 1 addition & 23 deletions pySqlOperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"SERVER=CABANONS00006v;"
"PORT=3306;"
"DATABASE=Cf_Ext;"
"USER=xxxx;"
"USER=user;"
"PASSWORD=xxxx;"
"OPTION=3;"
)
Expand All @@ -32,30 +32,8 @@ def executeSQLQuery(query):
print "SQL query executed"
connection.Close()







# query = "SELECT * FROM SE_BOM"
#
#
# connection = OdbcConnection(connectString)
# adaptor = OdbcDataAdapter(query, connection)
# dataSet = DataSet()
# connection.Open()
# adaptor.Fill(dataSet)
# connection.Close()
# columnNames = [column.ColumnName for column in dataSet.Tables[0].Columns]
# print columnNames
#
# rows = []
# for row in dataSet.Tables[0].Rows:
# rows.append(list(row))
#
# for items in rows:
# print items



3 changes: 3 additions & 0 deletions update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"C:\Program Files (x86)\IronPython 2.7\ipy.exe" "C:\Program Files (x86)\IronPython 2.7\Tools\Scripts\pyc.py" /main:SE_BOM_Extractor.py /target:exe
copy C:\cooke\python\SE_BOM_Extractor\SE_BOM_Extractor.exe N:\nbacf\Util\SE_Bom\SE_BOM.exe
copy C:\cooke\python\SE_BOM_Extractor\SE_BOM_Extractor.dll N:\nbacf\Util\SE_Bom\SE_BOM_Extractor.dll

0 comments on commit eb1954f

Please sign in to comment.