Vectorworks 部屋の備品を数えるスクリプト
部屋ごとの備品のワークシートのチェックするスクリプトサンプルです。
import vs
def callbackUuidName(hand):
uuid = vs.GetObjectUuid(hand)
vs.SetName(hand, uuid)
def callbackRecRoom(hand):
vs.SetRecord(hand, '部屋')
def callbackRecSet(hand):
vs.SetRecord(hand, '備品')
def symRecSheet():
wsHand = vs.CreateWS('情報入力', 4, 4)
dbrow = r"= (T=SYMBOL)"
vs.SetWSCellFormulaN(wsHand,2,0,2,0,dbrow)
vs.SetWSCellFormulaN(wsHand,2,1,2,1,'=SYMBOLNAME')
vs.SetWSCellFormulaN(wsHand,2,2,2,2,"='備品'.'単価'")
vs.SetWSCellFormulaN(wsHand,2,3,2,3,"='備品'.'備考'")
vs.SetWSCellFormulaN(wsHand,2,4,2,4,"='備品'.'除外'")
vs.AddWSColumnOperator(wsHand,2,1,1)
dbrow = r"=(R IN ['部屋'])"
vs.SetWSCellFormulaN(wsHand,4,0,4,0,dbrow)
vs.SetWSCellFormulaN(wsHand,4,1,4,1,"='部屋'.'名前'")
vs.SetWSAutoRecalcState(wsHand, True)
vs.SetWSImgShowDBHeader(wsHand,False,True)
vs.ShowWS(wsHand, True)
def symCountInRoom():
def callbackUuid(hand):
uuidList.append(vs.GetObjectUuid(hand))
uuidList = []
vs.ForEachObject(callbackUuid, "(R IN ['部屋']) ")
wsHand = vs.CreateWS('備品数量表', 2 * (len(uuidList)), 6)
for i , uuid in enumerate(uuidList):
hand = vs.GetObjectByUuid(uuid)
#vs.AlrtDialog(str(uuid))
vs.SetName(hand,uuid)
db = 2*(i+1)
range = 2*(i+1) - 1
vs.SetWSCellFormulaN(wsHand,range,1,range,1,vs.GetRField(hand,'部屋', '名前'))
vs.SetWSCellFormulaN(wsHand,range,2,range,2,'数量')
vs.SetWSCellFormulaN(wsHand,range,3,range,3,'単価')
vs.SetWSCellFormulaN(wsHand,range,4,range,4,'小計')
vs.SetWSCellFormulaN(wsHand,range,5,range,5,'備考')
vs.SetWSCellFormulaN(wsHand,range,6,range,6,'除外')
vs.SetWSCellFill(wsHand,range, 1, range, 6, 2, 9, 9, 2)
#vs.AlrtDialog(str(db))
dbrow = r"=DATABASE(((LOC='" + uuid + "') & (T=SYMBOL) & ('備品'.'除外'=FALSE)))"
vs.SetWSCellFormulaN(wsHand,db,0,db,0,dbrow)
vs.AddWSColumnOperator(wsHand,db,1,1)
vs.SetWSCellFormulaN(wsHand,db,1,db,1,'=s')
vs.SetWSCellFormulaN(wsHand,db,2,db,2,'=count')
vs.SetWSCellFormulaN(wsHand,db,3,db,3,"='備品'.'単価'")
total = '=' + 'B' + str(db) + '*' + 'C' + str(db)
vs.SetWSCellFormulaN(wsHand,db,4,db,4,total)
vs.AddWSColumnOperator(wsHand,db,4,2)
vs.SetWSCellFormulaN(wsHand,db,5,db,5,"='備品'.'備考'")
vs.SetWSCellFormulaN(wsHand,db,6,db,6,"='備品'.'除外'")
vs.SetWSImgShowDBHeader(wsHand,False,True)
vs.ShowWS(wsHand, True)
vs.NewField('部屋', '名前', '', 4, 0)
vs.NewField('備品', '単価', 0, 1, 0)
vs.NewField('備品', '備考', '', 4, 0)
vs.NewField('備品', '除外', False, 2, 0)
#vs.ForEachObject(callbackRecRoom , "(VSEL=TRUE)")
#vs.ForEachObject(callbackUuidName , "(R IN ['部屋'])")
vs.ForEachObject(callbackRecSet, "INSYMBOL & (T=SYMBOL)")
h = vs.GetObject('備品数量表')
if h == None:
symRecSheet()
symCountInRoom()
else:
if vs.GetTypeN(h) == 18:
vs.DelObject(h)
symCountInRoom()
else:
vs.AlrtDialog('備品数量表がワークシート以外で存在します。名前を変更してください')