import clr clr.AddReference("RevitNodes") import Revit clr.ImportExtensions(Revit.Elements) clr.AddReference("DSCoreNodes") import DSCore from DSCore import * clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") import sys import System from System.Windows.Forms import * from System.Drawing import * from System import Array from System.Collections.Generic import * clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c') from Microsoft.Office.Interop import Excel System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo("en-US") from System.Runtime.InteropServices import Marshal # Create a Class Form class CreateWindow(Form): def __init__(self): # Create the Form self.Name = "Create Window" self.Text = "现浇混凝土构件类别命名确认" self.Size = Size(700, 550) self.CenterToScreen() self.values_XJ = [] # Create Label for Beam Name labelBeamName_expath = Label(Text = "* excel工程清单路径") labelBeamName_expath.Parent = self labelBeamName_expath.Location = Point(30, 20) labelBeamName_expath.AutoSize=False labelBeamName_expath.Width=300 # Create TextBox for Beam Name self.textboxBeamName_expath = TextBox() self.textboxBeamName_expath.Parent = self self.textboxBeamName_expath.Text = r'C:\Users\admin\Desktop\万科超级清单模板(总包)08.31.xls' self.textboxBeamName_expath.Location = Point(350, 20) self.textboxBeamName_expath.Width = 300 labelsheetname = Label(Text = "工作表名称(工程清单)") labelsheetname.Parent = self labelsheetname.Location = Point(30, 50) labelsheetname.AutoSize=False labelsheetname.Width=300 # Create TextBox for Beam Name self.textboxsheetname = TextBox() self.textboxsheetname.Parent = self self.textboxsheetname.Text = '01型+A类明细表(土建地上)' self.textboxsheetname.Location = Point(350, 50) self.textboxsheetname.Width = 300 # Create Label for Beam Name labelBeamName_梁 = Label(Text = "* 梁类别") labelBeamName_梁.Parent = self labelBeamName_梁.Location = Point(30, 80) labelBeamName_梁.AutoSize=False labelBeamName_梁.Width=300 # Create Label for Beam Name labelBeamName_有梁板 = Label(Text = "有梁板(如:框架梁,暗梁,悬挑梁)") labelBeamName_有梁板.Parent = self labelBeamName_有梁板.Location = Point(30, 110) labelBeamName_有梁板.AutoSize=False labelBeamName_有梁板.Width=300 # Create TextBox for Beam Name self.textboxBeamName_有梁板 = TextBox() self.textboxBeamName_有梁板.Parent = self self.textboxBeamName_有梁板.Text = "KL,AL,XL,PTL" self.textboxBeamName_有梁板.Location = Point(350, 110) self.textboxBeamName_有梁板.Width = 300 # Create Label for Beam Number labelBeamName_直形墙 = Label(Text = "直形墙(连梁等)") labelBeamName_直形墙.Parent = self labelBeamName_直形墙.Location = Point(30, 140) labelBeamName_直形墙.AutoSize=False labelBeamName_直形墙.Width=300 # Create TextBox for Beam Number self.textboxBeamName_直形墙 = TextBox() self.textboxBeamName_直形墙.Parent = self self.textboxBeamName_直形墙.Text = "LL" self.textboxBeamName_直形墙.Location = Point(350, 140) self.textboxBeamName_直形墙.Width = 300 # Create Label for Beam Name labelBeamName_圈梁过梁 = Label(Text = "圈梁过梁") labelBeamName_圈梁过梁.Parent = self labelBeamName_圈梁过梁.Location = Point(30, 170) labelBeamName_圈梁过梁.AutoSize=False labelBeamName_圈梁过梁.Width=300 # Create TextBox for Beam Name self.textboxBeamName_圈梁过梁 = TextBox() self.textboxBeamName_圈梁过梁.Parent = self self.textboxBeamName_圈梁过梁.Text = "QL,GL" self.textboxBeamName_圈梁过梁.Location = Point(350, 170) self.textboxBeamName_圈梁过梁.Width = 300 # Create Label for Beam Number labelBeamName_零星构件 = Label(Text = "混凝土现浇零星构件(如翻边,反坎)") labelBeamName_零星构件.Parent = self labelBeamName_零星构件.Location = Point(30, 200) labelBeamName_零星构件.AutoSize=False labelBeamName_零星构件.Width=300 # Create TextBox for Beam Number self.textboxBeamName_零星构件 = TextBox() self.textboxBeamName_零星构件.Parent = self self.textboxBeamName_零星构件.Text = "翻边,反坎" self.textboxBeamName_零星构件.Location = Point(350, 200) self.textboxBeamName_零星构件.Width = 300 # Create Label for Beam Number labelColumnName_柱 = Label(Text = "* 结构柱类别") labelColumnName_柱.Parent = self labelColumnName_柱.Location = Point(30, 230) labelColumnName_柱.AutoSize=False labelColumnName_柱.Width=300 # Create Label for Beam Number labelColumnName_矩形柱 = Label(Text = "矩形柱(如框架柱,梯柱等),其余归入直形墙") labelColumnName_矩形柱.Parent = self labelColumnName_矩形柱.Location = Point(30, 260) labelColumnName_矩形柱.AutoSize=False labelColumnName_矩形柱.Width=300 # Create TextBox for Beam Number self.textboxColumnName_矩形柱 = TextBox() self.textboxColumnName_矩形柱.Parent = self self.textboxColumnName_矩形柱.Text = "KZ,TZ" self.textboxColumnName_矩形柱.Location = Point(350, 260) self.textboxColumnName_矩形柱.Width = 300 # Create Label for Beam Number labelColumnName_矩形柱 = Label(Text = "* 结构墙") labelColumnName_矩形柱.Parent = self labelColumnName_矩形柱.Location = Point(30, 290) labelColumnName_矩形柱.AutoSize=False labelColumnName_矩形柱.Width=300 # Create Label for Beam Number labelWallName_结构墙 = Label(Text = "结构墙(如剪力墙等)") labelWallName_结构墙.Parent = self labelWallName_结构墙.Location = Point(30, 320) labelWallName_结构墙.AutoSize=False labelWallName_结构墙.Width=300 # Create TextBox for Beam Number self.textboxWallName_结构墙 = TextBox() self.textboxWallName_结构墙.Parent = self self.textboxWallName_结构墙.Text = "Q" self.textboxWallName_结构墙.Location = Point(350, 320) self.textboxWallName_结构墙.Width = 300 # Create Label for Beam Number labelFloorName_楼板 = Label(Text = "* 结构板") labelFloorName_楼板.Parent = self labelFloorName_楼板.Location = Point(30, 350) labelFloorName_楼板.AutoSize=False labelFloorName_楼板.Width=300 # Create Label for Beam Number labelFloorName_楼板 = Label(Text = "结构板(如楼板)") labelFloorName_楼板.Parent = self labelFloorName_楼板.Location = Point(30, 380) labelFloorName_楼板.AutoSize=False labelFloorName_楼板.Width=300 # Create TextBox for Beam Number self.textboxFloorName_楼板 = TextBox() self.textboxFloorName_楼板.Parent = self self.textboxFloorName_楼板.Text = "楼板,LB" self.textboxFloorName_楼板.Location = Point(350, 380) self.textboxFloorName_楼板.Width = 200 # Create Button = button button = Button() button.Parent = self button.Text = "确定" button.Location = Point(500, 450) # Register event button.Click += self.ButtonClicked # Create button event def ButtonClicked(self, sender, args): if sender.Click: self.values_XJ.append(self.textboxBeamName_expath.Text) self.values_XJ.append(self.textboxBeamName_有梁板.Text) self.values_XJ.append(self.textboxBeamName_直形墙.Text) self.values_XJ.append(self.textboxBeamName_圈梁过梁.Text) self.values_XJ.append(self.textboxBeamName_零星构件.Text) self.values_XJ.append(self.textboxColumnName_矩形柱.Text) self.values_XJ.append(self.textboxWallName_结构墙.Text) self.values_XJ.append(self.textboxFloorName_楼板.Text) self.values_XJ.append(self.textboxsheetname.Text) self.Close() form = CreateWindow() Application.Run(form) P_excel=form.values_XJ[0] B_有梁板=form.values_XJ[1].split(',') B_直形墙=form.values_XJ[2].split(',') B_圈梁过梁=form.values_XJ[3].split(',') B_零星构件=form.values_XJ[4].split(',') Z_矩形柱=form.values_XJ[5].split(',') Q_结构墙=form.values_XJ[6].split(',') L_楼板=form.values_XJ[7].split(',') S_工作表=form.values_XJ[8] # Create a Class Form class CreateWindow_YZ(Form): def __init__(self): # Create the Form self.Name = "Create Window" self.Text = "预制构件命名确认" self.Size = Size(700, 290) self.CenterToScreen() self.values_YZ = [] # Create Label for Beam Name labelPrefaName_预制板 = Label(Text = "预制板(如:叠合板)") labelPrefaName_预制板.Parent = self labelPrefaName_预制板.Location = Point(30, 30) labelPrefaName_预制板.AutoSize=False labelPrefaName_预制板.Width=300 # Create TextBox for Beam Name self.textboxPrefaName_预制板 = TextBox() self.textboxPrefaName_预制板.Parent = self self.textboxPrefaName_预制板.Text = "DBS,叠合板" self.textboxPrefaName_预制板.Location = Point(350, 30) self.textboxPrefaName_预制板.Width = 300 # Create Label for Beam Number labelPrefaName_预制梁 = Label(Text = "预制梁(如:叠合梁)") labelPrefaName_预制梁.Parent = self labelPrefaName_预制梁.Location = Point(30, 60) labelPrefaName_预制梁.AutoSize=False labelPrefaName_预制梁.Width=300 # Create TextBox for Beam Number self.textboxPrefaName_预制梁 = TextBox() self.textboxPrefaName_预制梁.Parent = self self.textboxPrefaName_预制梁.Text = "YL,预制梁" self.textboxPrefaName_预制梁.Location = Point(350, 60) self.textboxPrefaName_预制梁.Width = 300 # Create Label for Beam Name labelPrefaName_预制阳台 = Label(Text = "预制阳台(如预制叠合阳台)") labelPrefaName_预制阳台.Parent = self labelPrefaName_预制阳台.Location = Point(30, 90) labelPrefaName_预制阳台.AutoSize=False labelPrefaName_预制阳台.Width=300 # Create TextBox for Beam Name self.textboxPrefaName_预制阳台 = TextBox() self.textboxPrefaName_预制阳台.Parent = self self.textboxPrefaName_预制阳台.Text = "YYT,预制叠合阳台" self.textboxPrefaName_预制阳台.Location = Point(350, 90) self.textboxPrefaName_预制阳台.Width = 300 # Create Label for Beam Number labelPrefaName_预制楼梯 = Label(Text = "预制楼梯(如预制楼梯)") labelPrefaName_预制楼梯.Parent = self labelPrefaName_预制楼梯.Location = Point(30, 120) labelPrefaName_预制楼梯.AutoSize=False labelPrefaName_预制楼梯.Width=300 # Create TextBox for Beam Number self.textboxPrefaName_预制楼梯 = TextBox() self.textboxPrefaName_预制楼梯.Parent = self self.textboxPrefaName_预制楼梯.Text = "YZLT,预制楼梯" self.textboxPrefaName_预制楼梯.Location = Point(350, 120) self.textboxPrefaName_预制楼梯.Width = 300 # Create Label for Beam Number labelPrefaName_预制空调板 = Label(Text = "预制空调板(如:预制空调板)") labelPrefaName_预制空调板.Parent = self labelPrefaName_预制空调板.Location = Point(30, 150) labelPrefaName_预制空调板.AutoSize=False labelPrefaName_预制空调板.Width=300 # Create TextBox for Beam Number self.textboxPrefaName_预制空调板 = TextBox() self.textboxPrefaName_预制空调板.Parent = self self.textboxPrefaName_预制空调板.Text = "YKT,预制空调板" self.textboxPrefaName_预制空调板.Location = Point(350, 150) self.textboxPrefaName_预制空调板.Width = 300 # Create Button = button button = Button() button.Parent = self button.Text = "确定" button.Location = Point(500, 200) # Register event button.Click += self.ButtonClicked # Create button event def ButtonClicked(self, sender, args): if sender.Click: self.values_YZ.append(self.textboxPrefaName_预制板.Text) self.values_YZ.append(self.textboxPrefaName_预制梁.Text) self.values_YZ.append(self.textboxPrefaName_预制阳台.Text) self.values_YZ.append(self.textboxPrefaName_预制楼梯.Text) self.values_YZ.append(self.textboxPrefaName_预制空调板.Text) self.Close() form_YZ = CreateWindow_YZ() Application.Run(form_YZ) DBS_叠合板=form_YZ.values_YZ[0].split(',') YL_预制梁=form_YZ.values_YZ[1].split(',') YYT_预制叠合阳台=form_YZ.values_YZ[2].split(',') YZLT_预制楼梯=form_YZ.values_YZ[3].split(',') YKT_预制空调板=form_YZ.values_YZ[4].split(',') class CreateWindow_HY(Form): def __init__(self): # Create the Form self.Name = "Create Window" self.Text = "合同编码命名确认" self.Size = Size(700, 350) self.CenterToScreen() self.values_HY = [] # Create Label for Beam Name labelBM_现浇 = Label(Text = "*现浇混凝土构件") labelBM_现浇.Parent = self labelBM_现浇.Location = Point(30, 30) labelBM_现浇.AutoSize=False labelBM_现浇.Width=300 labelBM_合一 = Label(Text = "合约类型编码1") labelBM_合一.Parent = self labelBM_合一.Location = Point(30, 60) labelBM_合一.AutoSize=False labelBM_合一.Width=300 # Create TextBox for Beam Name self.textboxBM_合一 = TextBox() self.textboxBM_合一.Parent = self self.textboxBM_合一.Text = "CG.CD.0002" self.textboxBM_合一.Location = Point(350, 60) self.textboxBM_合一.Width = 300 # Create Label for Beam Number labelBM_合二 = Label(Text = "合约类型编码2") labelBM_合二.Parent = self labelBM_合二.Location = Point(30, 90) labelBM_合二.AutoSize=False labelBM_合二.Width=300 # Create TextBox for Beam Number self.textboxBM_合二 = TextBox() self.textboxBM_合二.Parent = self self.textboxBM_合二.Text = "SG.JT.0001" self.textboxBM_合二.Location = Point(350, 90) self.textboxBM_合二.Width = 300 # Create Label for Beam Name label_预制 = Label(Text = "*预制构件") label_预制.Parent = self label_预制.Location = Point(30, 120) label_预制.AutoSize=False label_预制.Width=300 # Create Label for Beam Name labelYBM_合一 = Label(Text = "合约类型编码1") labelYBM_合一.Parent = self labelYBM_合一.Location = Point(30, 150) labelYBM_合一.AutoSize=False labelYBM_合一.Width=300 # Create TextBox for Beam Name self.textboxYBM_合一 = TextBox() self.textboxYBM_合一.Parent = self self.textboxYBM_合一.Text = " " self.textboxYBM_合一.Location = Point(350, 150) self.textboxYBM_合一.Width = 300 # Create Label for Beam Number labelYBM_合二 = Label(Text = "合约类型编码2") labelYBM_合二.Parent = self labelYBM_合二.Location = Point(30, 180) labelYBM_合二.AutoSize=False labelYBM_合二.Width=300 self.textboxYBM_合二 = TextBox() self.textboxYBM_合二.Parent = self self.textboxYBM_合二.Text = "SG.JT.0001" self.textboxYBM_合二.Location = Point(350, 180) self.textboxYBM_合二.Width = 300 # Create Button = button button = Button() button.Parent = self button.Text = "确定" button.Location = Point(500, 250) # Register event button.Click += self.ButtonClicked # Create button event def ButtonClicked(self, sender, args): if sender.Click: self.values_HY.append(self.textboxBM_合一.Text) self.values_HY.append(self.textboxBM_合二.Text) self.values_HY.append(self.textboxYBM_合一.Text) self.values_HY.append(self.textboxYBM_合二.Text) self.Close() form_HY = CreateWindow_HY() Application.Run(form_HY) HNT_编码1=form_HY.values_HY[0] HNT_编码2=form_HY.values_HY[1] YZ_编码1=form_HY.values_HY[2] YZ_编码2=form_HY.values_HY[3] doc = DocumentManager.Instance.CurrentDBDocument TransactionManager.Instance.EnsureInTransaction(doc) ###结构梁### ####### builtInCategory_L = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType().ToElements() class Eleli: def __init__(self,builtInCategory,name): #传入参数名称,如‘KL’ self.name=name self.builtInCategory=builtInCategory self.list=[] for each in self.name: self.list.append(list(filter(lambda l : each in l.Name, self.builtInCategory))) self.list=DSCore.List.Flatten(self.list,3) def elementlist(self): return self.list def elementcon(self): return list(each.Name[each.Name.index('C'):each.Name.index('C')+3] for each in self.list) def elementvolumn(self): return list(map(lambda l :UnitUtils.Convert(l.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED).AsDouble(), DisplayUnitType.DUT_CUBIC_FEET, DisplayUnitType.DUT_CUBIC_METERS),self.list)) beam_有梁板 = Eleli(builtInCategory_L,B_有梁板).elementlist() ###"KL","AL","XL","PTL" beamcon_有梁板=Eleli(builtInCategory_L,B_有梁板).elementcon() beamVolumn_有梁板 =Eleli(builtInCategory_L,B_有梁板).elementvolumn() beam_直形墙 = Eleli(builtInCategory_L,B_直形墙).elementlist() ###"LL" beamcon_直形墙=Eleli(builtInCategory_L,B_直形墙).elementcon() beamVolumn_直形墙 =Eleli(builtInCategory_L,B_直形墙).elementvolumn() beam_圈梁过梁 = Eleli(builtInCategory_L,B_圈梁过梁).elementlist() #GL过梁:对应清单圈梁过梁 beamcon_圈梁过梁= Eleli(builtInCategory_L,B_圈梁过梁).elementcon() beamVolumn_圈梁过梁 = Eleli(builtInCategory_L,B_圈梁过梁).elementvolumn() beam_L = list(set(list(filter(lambda l : l.Name[0]=='L', builtInCategory_L)) ).difference(set(beam_直形墙))) #L梁:对应清单有梁板 beamcon_L=list(each.Name[each.Name.index('C'):each.Name.index('C')+3] for each in beam_L) beamVolumn_L=list(map(lambda l :UnitUtils.Convert(l.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED).AsDouble(), DisplayUnitType.DUT_CUBIC_FEET, DisplayUnitType.DUT_CUBIC_METERS),beam_L)) beam_零星构件 = Eleli(builtInCategory_L,B_零星构件).elementlist() #GL过梁:对应清单圈梁过梁 beamcon_零星构件= Eleli(builtInCategory_L,B_零星构件).elementcon() beamVolumn_零星构件 = Eleli(builtInCategory_L,B_零星构件).elementvolumn() #有梁板清单 beamlist_有梁板=DSCore.List.Flatten([beam_有梁板,beam_L], 3) beamconlist_有梁板=DSCore.List.Flatten([beamcon_有梁板,beamcon_L], 3) beamVolumnlist_有梁板=DSCore.List.Flatten([beamVolumn_有梁板,beamVolumn_L], 3) #直形墙清单 beamlist_直形墙=DSCore.List.Flatten([beam_直形墙], 3) beamconlist_直形墙=DSCore.List.Flatten([beamcon_直形墙], 3) beamVolumnlist_直形墙=DSCore.List.Flatten([beamVolumn_直形墙], 3) #圈梁过梁清单 beamlist_圈梁过梁=DSCore.List.Flatten([beam_圈梁过梁], 3) beamconlist_圈梁过梁=DSCore.List.Flatten([beamcon_圈梁过梁], 3) beamVolumnlist_圈梁过梁=DSCore.List.Flatten([beamVolumn_圈梁过梁], 3) #零星构件清单 beamlist_零星构件=DSCore.List.Flatten([beam_零星构件], 3) beamconlist_零星构件=DSCore.List.Flatten([beamcon_零星构件], 3) beamVolumnlist_零星构件=DSCore.List.Flatten([beamVolumn_零星构件], 3) #四个清单归类(result) Blist_有梁板=[beamlist_有梁板,beamconlist_有梁板,beamVolumnlist_有梁板] Blist_直形墙=[beamlist_直形墙,beamconlist_直形墙,beamVolumnlist_直形墙] Blist_圈梁过梁=[beamlist_圈梁过梁,beamconlist_圈梁过梁,beamVolumnlist_圈梁过梁] Blist_零星构件=[beamlist_零星构件,beamconlist_零星构件,beamVolumnlist_零星构件] ###结构柱### ####### builtInCategory_Z = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).WhereElementIsNotElementType().ToElements() column_矩形柱 = Eleli(builtInCategory_Z,Z_矩形柱).elementlist() #KZ框架柱:对应清单矩形柱 columncon_矩形柱=Eleli(builtInCategory_Z,Z_矩形柱).elementcon() columnVolumn_矩形柱 =Eleli(builtInCategory_Z,Z_矩形柱).elementvolumn() column_QZ = list(set(list(filter(lambda l : 'Z' in l.Name, builtInCategory_Z)) ).difference(set(column_矩形柱))) #其他翼缘柱:对应清单直形墙 columncon_QZ=list(each.Name[each.Name.index('C'):each.Name.index('C')+3] for each in column_QZ) columnVolumn_QZ=list(map(lambda l :UnitUtils.Convert(l.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED).AsDouble(), DisplayUnitType.DUT_CUBIC_FEET, DisplayUnitType.DUT_CUBIC_METERS),column_QZ)) columnlist_矩形柱=DSCore.List.Flatten([column_矩形柱], 3) columnconlist_矩形柱=DSCore.List.Flatten([columncon_矩形柱], 3) columnVolumnlist_矩形柱=DSCore.List.Flatten([columnVolumn_矩形柱], 3) columnlist_直形墙=DSCore.List.Flatten([column_QZ], 3) columnconlist_直形墙=DSCore.List.Flatten([columncon_QZ], 3) columnVolumnlist_直形墙=DSCore.List.Flatten([columnVolumn_QZ], 3) Clist_矩形柱=[columnlist_矩形柱,columnconlist_矩形柱,columnVolumnlist_矩形柱] Clist_直形墙=[columnlist_直形墙,columnconlist_直形墙,columnVolumnlist_直形墙] ###结构墙### ####### builtInCategory_W = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements() wall_直形墙 = Eleli(builtInCategory_W,Q_结构墙).elementlist() #KZ框架柱:对应清单矩形柱 wallcon_直形墙=Eleli(builtInCategory_W,Q_结构墙).elementcon() wallVolumn_直形墙 =Eleli(builtInCategory_W,Q_结构墙).elementvolumn() walllist_直形墙=DSCore.List.Flatten([wall_直形墙], 3) wallconlist_直形墙=DSCore.List.Flatten([wallcon_直形墙], 3) wallVolumnlist_直形墙=DSCore.List.Flatten([wallVolumn_直形墙], 3) #result Q墙 Wlist_直形墙=[walllist_直形墙,wallconlist_直形墙,wallVolumnlist_直形墙] ###结构板### ####### builtInCategory_F = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().ToElements() floor_楼板 = Eleli(builtInCategory_F,L_楼板).elementlist() floorcon_楼板= Eleli(builtInCategory_F,L_楼板).elementcon() floorVolumn_楼板=Eleli(builtInCategory_F,L_楼板).elementvolumn() floorlist_楼板=DSCore.List.Flatten([floor_楼板], 3) floorconlist_楼板=DSCore.List.Flatten([floorcon_楼板], 3) floorVolumnlist_楼板=DSCore.List.Flatten([floorVolumn_楼板], 3) Flist_有梁板=[floorlist_楼板,floorconlist_楼板,floorVolumnlist_楼板] #OUT=(Blist_有梁板,Blist_直形墙,Blist_圈梁过梁,Blist_零星构件,Clist_矩形柱,Clist_直形墙,Wlist_直形墙,Flist_有梁板) ###常规模型### ####### builtInCategory_G = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().ToElements() class Genericli: def __init__(self,name,nname=0): #传入参数名称,如‘叠合板’ self.name=name self.nname=nname self.list=[] for each in self.name: self.list.append((filter(lambda l : each in l.Name and self.nname not in l.Name, builtInCategory_G))) self.list=DSCore.List.Flatten(self.list,3) def genericlist(self): return self.list def genericcon(self): return list() def genericvolumn(self): return list(map(lambda l :UnitUtils.Convert(l.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED).AsDouble(), DisplayUnitType.DUT_CUBIC_FEET, DisplayUnitType.DUT_CUBIC_METERS),self.list)) genericDBS_叠合板 = Genericli(DBS_叠合板).genericlist()#DBS(叠合板):对应清单预制板 genericCon_DBS_叠合板 = Genericli(DBS_叠合板).genericcon() genericVolumn_DBS_叠合板 = Genericli(DBS_叠合板).genericvolumn() #清单 DBS(叠合板) genericlist_DBS叠合板=DSCore.List.Flatten([genericDBS_叠合板], 3) genericConlist_DBS叠合板=DSCore.List.Flatten([genericCon_DBS_叠合板], 3) genericVolumnlist_DBS叠合板=DSCore.List.Flatten([genericVolumn_DBS_叠合板 ], 3) #result DBS(叠合板) Glist_DBS叠合板=[genericlist_DBS叠合板,genericConlist_DBS叠合板,genericVolumnlist_DBS叠合板] genericYL_预制梁 = Genericli(YL_预制梁).genericlist() #YL(预制梁):对应清单预制梁 genericConYL_预制梁 = Genericli(YL_预制梁).genericcon() genericVolumnYL_预制梁 = Genericli(YL_预制梁).genericvolumn() #清单 YL(预制梁) genericlist_YL预制梁=DSCore.List.Flatten([genericYL_预制梁], 3) genericConlist_YL预制梁=DSCore.List.Flatten([genericConYL_预制梁], 3) genericVolumnlist_YL预制梁=DSCore.List.Flatten([genericVolumnYL_预制梁], 3) #result YL(预制梁) Glist_YL预制梁=[genericlist_YL预制梁,genericConlist_YL预制梁,genericVolumnlist_YL预制梁] genericYYT_预制叠合阳台 = Genericli(YYT_预制叠合阳台).genericlist() #YYT(预制叠合阳台):对应清单预制叠合阳台 genericConYYT_预制叠合阳台 = Genericli(YYT_预制叠合阳台).genericcon() genericVolumnYYT_预制叠合阳台 = Genericli(YYT_预制叠合阳台).genericvolumn() #清单 YYT(预制叠合阳台) genericlist_YYT预制叠合阳台=DSCore.List.Flatten([genericYYT_预制叠合阳台], 3) genericConlist_YYT预制叠合阳台=DSCore.List.Flatten([genericConYYT_预制叠合阳台], 3) genericVolumnlist_YYT预制叠合阳台=DSCore.List.Flatten([genericVolumnYYT_预制叠合阳台], 3) #result YYT(预制叠合阳台) Glist_YYT预制叠合阳台=[genericlist_YYT预制叠合阳台,genericConlist_YYT预制叠合阳台,genericVolumnlist_YYT预制叠合阳台] genericYZLT_预制楼梯 = Genericli(YZLT_预制楼梯).genericlist() #YZLT(预制楼梯):对应清单预制楼梯 genericConYZLT_预制楼梯 = Genericli(YZLT_预制楼梯).genericcon() genericVolumnYZLT_预制楼梯= Genericli(YZLT_预制楼梯).genericvolumn() #清单 YYT(预制楼梯) genericlist_YZLT预制楼梯=DSCore.List.Flatten([genericYZLT_预制楼梯], 3) genericConlist_YZLT预制楼梯=DSCore.List.Flatten([genericConYZLT_预制楼梯], 3) genericVolumnlist_YZLT预制楼梯=DSCore.List.Flatten([genericVolumnYZLT_预制楼梯], 3) #result YZLT(预制楼梯) Glist_YZLT预制楼梯=[genericlist_YZLT预制楼梯,genericConlist_YZLT预制楼梯,genericVolumnlist_YZLT预制楼梯] genericYKT_预制空调板 = Genericli(YKT_预制空调板).genericlist() #YKT(预制空调板):对应清单预制空调板 genericConYKT_预制空调板 = Genericli(YKT_预制空调板).genericcon() genericVolumnYKT_预制空调板= Genericli(YKT_预制空调板).genericvolumn() #清单 YYT(预制空调板) genericlist_YKT预制空调板=DSCore.List.Flatten([genericYKT_预制空调板], 3) genericConlist_YKT预制空调板=DSCore.List.Flatten([genericConYKT_预制空调板], 3) genericVolumnlist_YKT预制空调板=DSCore.List.Flatten([genericVolumnYKT_预制空调板], 3) #result YZLT(预制空调板) Glist_YKT预制空调板=[genericlist_YKT预制空调板,genericConlist_YKT预制空调板,genericVolumnlist_YKT预制空调板] generic_现浇梯梁 = Genericli('现浇梯梁').genericlist() #TL(现浇楼梯):对应清单矩形梁 genericCon_现浇梯梁 = Genericli('现浇梯梁').genericcon() genericVolumn_现浇梯梁= Genericli('现浇梯梁').genericvolumn() generic_TL = Genericli('TL').genericlist() genericVolumn_TL = Genericli('TL').genericvolumn()#清单 TL(现浇梯梁) genericCon_TL = Genericli('TL').genericcon() genericlist_TL现浇梯梁=DSCore.List.Flatten([generic_现浇梯梁,generic_TL], 3) genericConlist_TL现浇梯梁=DSCore.List.Flatten([genericCon_现浇梯梁,genericCon_TL], 3) genericVolumnlist_TL现浇梯梁=DSCore.List.Flatten([genericVolumn_现浇梯梁,genericVolumn_TL], 3)#result TL(现浇梯梁) Glist_TL现浇梯梁=[genericlist_TL现浇梯梁,genericConlist_TL现浇梯梁,genericVolumnlist_TL现浇梯梁] ###excel### ####### ###excel### '''excel_data=IN[0] excel_code=['0' if x==None else x for x in excel_data[0]] excel_name=['0' if x==None else x for x in excel_data[1]]''' path=P_excel sys.path.append(path) ex=Excel.ApplicationClass() ex.Visible=True ex.DisplayAlerts=False workbook=ex.Workbooks.Open(path) ws=workbook.Worksheets[S_工作表] ws2=workbook.Worksheets.Add() ws2.name="01型+A类明细表(土建地上)工程量2" x1range=ws.Range["A1","A200"] x2range=ws.Range["B1","B200"] r1=x1range.Value2 r2=x2range.Value2 x21range=ws2.Range["A1","A200"] x22range=ws2.Range["B1","B200"] x21range.Value2=r1 x22range.Value2=r2 #ws3=workbook.creat_sheet() excel_code=['0' if x==None else x for x in r1] excel_name=['0' if x==None else x for x in r2] class Code: def __init__(self,keyword,*lists): self.lists=lists self.keyword=keyword self.result=[] self.listelement=[] length1=len(self.lists[0]) length2=len(self.lists) for i in range(length1): temp=[] for j in range(length2): temp.append(lists[j][i]) self.result.append(temp) for each in self.result: self.listelement.append(DSCore.List.Flatten(each, 3)) def getele(self): return self.listelement def getCode(self): code_new=[] nu_row=[] i=0 for each1 in self.listelement[0]: for each2 in excel_name: if self.keyword in each2 and self.listelement[1][i] in each2: n_row=excel_name.index(each2) nu_row.append(n_row) code_new.append(excel_code[n_row]) i+=1 self.listelement.append(code_new) self.listelement.append(nu_row) return self.listelement def getCode_YZ(self): code_new=[] nu_row=[] i=0 for each1 in self.listelement[0]: for each2 in excel_name: if self.keyword in each2: n_row=excel_name.index(each2) nu_row.append(n_row) code_new.append(excel_code[n_row]) i+=1 self.listelement.append(code_new) self.listelement.append(nu_row) return self.listelement listelement_有梁板=Code('有梁板',Blist_有梁板,Flist_有梁板).getCode() listelement_直形墙=Code('直形墙',Blist_直形墙,Clist_直形墙,Wlist_直形墙).getCode() listelement_圈梁过梁=Code('圈梁',Blist_圈梁过梁).getCode() listelement_零星构件=Code('现浇混凝土其他构件:零星',Blist_零星构件).getCode() listelement_矩形柱=Code('矩形柱',Clist_矩形柱).getCode() listelement_DBS叠合板=Code('叠合板',Glist_DBS叠合板).getCode_YZ() listelement_YL预制梁=Code('预制叠合阳台梁',Glist_YL预制梁).getCode_YZ() listelement_YYT预制叠合阳台=Code('预制阳台',Glist_DBS叠合板).getCode_YZ() listelement_YZLT预制楼梯=Code('预制楼梯',Glist_YZLT预制楼梯).getCode_YZ() listelement_YKT预制空调板=Code('预制空调板',Glist_YKT预制空调板).getCode_YZ() ###编码### ####### class Code_element: def __init__(self,listelement): ###code3需要从excel获取 self.listelement=listelement def codeSetting_HNT(self): i=0 for each in self.listelement[0]: typeId = each.GetTypeId() typeElement = doc.GetElement(typeId) parms = typeElement.Parameters for par in parms: if par.Definition.Name == '合约类型编码1': par.Set(HNT_编码1) elif par.Definition.Name == '合约类型编码2': par.Set(HNT_编码2) elif par.Definition.Name == '清单编码': par.Set(self.listelement[3][i]) i+=1 def codeSetting_YZ(self): i=0 for each in self.listelement[0]: typeId = each.GetTypeId() typeElement = doc.GetElement(typeId) parms = typeElement.Parameters for par in parms: if par.Definition.Name == '合约类型编码1': par.Set(YZ_编码1) elif par.Definition.Name == '合约类型编码2': par.Set(YZ_编码2) elif par.Definition.Name == '清单编码': par.Set(self.listelement[3][i]) i+=1 Code_element(listelement_有梁板).codeSetting_HNT() Code_element(listelement_矩形柱).codeSetting_HNT() Code_element(listelement_直形墙).codeSetting_HNT() Code_element(listelement_圈梁过梁).codeSetting_HNT() Code_element(listelement_零星构件).codeSetting_HNT() Code_element(listelement_DBS叠合板).codeSetting_YZ() Code_element(listelement_YL预制梁).codeSetting_YZ() Code_element(listelement_YYT预制叠合阳台).codeSetting_YZ() Code_element(listelement_YZLT预制楼梯).codeSetting_YZ() Code_element(listelement_YKT预制空调板).codeSetting_YZ() ###get the floor num filename=Document.PathName.GetValue(doc) filename_doc=filename.split('\\')[-1] n=filename_doc.index('F') floor_num=str(filename_doc[n-2:n]) colnum=int(floor_num)+2 class Volumn_row: def __init__(self,listelement): self.listelement_row=listelement[4] self.listelement_volumn=listelement[2] self.dic={} for i in range(len(self.listelement_row)): if self.listelement_row[i] not in self.listelement_row[0:i]: self.dic[self.listelement_row[i]]=self.listelement_volumn[i] else: self.dic[self.listelement_row[i]]=self.dic[self.listelement_row[i]]+self.listelement_volumn[i] self.keys=list(map(lambda l:l+1,list(self.dic.keys()))) self.values=list(self.dic.values()) def getdic(self): return self.dic def getrow(self): return self.keys def getvolumn(self): return list(self.dic.values()) def writting(self): for i in range(len(self.keys)): ws2.Cells[self.keys[i],colnum]=self.values[i] Volumn_row(listelement_有梁板).writting() Volumn_row(listelement_矩形柱).writting() Volumn_row(listelement_直形墙).writting() Volumn_row(listelement_圈梁过梁).writting() Volumn_row(listelement_零星构件).writting() Volumn_row(listelement_DBS叠合板).writting() Volumn_row(listelement_YL预制梁).writting() Volumn_row(listelement_YYT预制叠合阳台).writting() Volumn_row(listelement_YZLT预制楼梯).writting() Volumn_row(listelement_YKT预制空调板).writting() OUT=(listelement_有梁板,listelement_直形墙,listelement_零星构件,listelement_DBS叠合板,listelement_DBS叠合板)