CADとPython学習 14 図形情報とGet / Set
図形情報を取得(Get)と設定(Set)
Get関数の戻り値として辞書形式で取得し、Set関数の引数として辞書で割り当てています。SetAttr関数は中でVectorworksのリファレンスのSet関数を入力しています。
def getAttr(hand): # 属性の辞書を返す
attrDict = {}
fillType = vs.GetObjectVariableInt(hand, 696)
boo, fillName = vs.GetVectorFill(hand)
fillpat = vs.GetFPat(hand)
attrDict["タイプ"] = fillType
attrDict["パターン"] = fillpat
attrDict["リソース"] = boo
if boo == False:
fillName = None
attrDict["名前"] = fillName
red, green, blue = vs.GetFillFore(hand)
color = vs.RGBToColorIndex(red, green, blue)
attrDict["面前RGB"] = [red, green, blue]
attrDict["面前色"] = color
red, green, blue = vs.GetFillBack(hand)
color = vs.RGBToColorIndex(red, green, blue)
attrDict["面後RGB"] = [red, green, blue]
attrDict["面後色"] = color
boo, penOpa, fillOpa = vs.GetOpacityN(hand)
attrDict["面透明"] = fillOpa
red, green, blue = vs.GetPenFore(hand)
color = vs.RGBToColorIndex(red, green, blue)
attrDict["線RGB"] = [red, green, blue]
attrDict["線色"] = color
attrDict["線透明"] = penOpa
lineWide = vs.GetLW(hand)
lineStyle = vs.GetLSN(hand)
attrDict["線幅"] = lineWide
attrDict["ラインタイプ"] = lineStyle
return attrDict
def setAttr(attrDict,hand):
vs.SetPenFore(hand, attrDict['線色'])
vs.SetLW(hand, attrDict['線幅'])
vs.SetLSN(hand, attrDict['ラインタイプ'])
vs.SetOpacityN(hand, attrDict['線透明'], attrDict['面透明'])
if attrDict['リソース'] == True:
result = vs.Name2Index(attrDict['名前'])
vs.SetObjectVariableLongInt (hand,695,result * -1)
else:
if attrDict['タイプ'] == 1:
vs.SetFPat(hand, 0)
elif attrDict['タイプ'] == 2:
vs.SetFPat(hand, 1)
vs.SetFillBack(hand, attrDict['面後色'])
elif attrDict['タイプ'] == 3:
vs.SetFPat(hand,attrDict['パターン'])
vs.SetFillFore(hand, attrDict['面前色'])
vs.SetFillBack(hand, attrDict['面後色'])
target = vs.GetObject('target')
attrDict = getAttr(target)
vs.AlrtDialog(str(attrDict))
hand = vs.FSActLayer()
setAttr(attrDict,hand)