If I run it from the script editor it works perfect. But, if I add it to the custom toolbar/hotkey I get an error message of
line 38
lastComponent = selectionLAST[0]
IndexError: list index out of range.
Code: Select all
###Match Points X/Y/Z
##### Y
#Only works on points
if Application.Selection(0).type == "edgeSubComponent":
Application.LogMessage("Align points works with points ONLY")
if Application.Selection(0).type == "polySubComponent":
Application.LogMessage("Align points works with points ONLY")
################
if Application.Selection(0).type == "pntSubComponent":
#
selectionALL = []
selectionFIRST = []
selectionLAST = []
allTemp = Application.Selection(0).SubComponent.ComponentCollection
for i in allTemp:
selectionALL.append(i.Index)
#
Application.Undo("")
#
firstTemp = Application.Selection(0).SubComponent.ComponentCollection
for i in firstTemp:
selectionFIRST.append(i.Index)
for i in selectionALL:
if i not in selectionFIRST:
selectionLAST.append(i)
lastComponent = selectionLAST[0] #######################################
##go to item mode and get the name
Application.ActivateObjectSelTool("")
rootObject = Application.Selection(0)
#switch back to vert mode
Application.ActivateVertexSelTool("")
positionOfLastSelectedComponentY = Application.ActiveProject.ActiveScene.Root.FindChild(rootObject).ActivePrimitive.Geometry.Points(lastComponent).Position.Y
####Works to get them to the same position
moveALL = []
for i in firstTemp:
moveALL.append(i.SubComponent)
for i in range(len(moveALL)):
number = i
PTtoMove = moveALL[number]
Application.Translate(PTtoMove, 0, positionOfLastSelectedComponentY, 0, "siAbsolute", "siPivot", "siObj", "siY", "", "", "", "", "", "", "", "", "", 0, "")
#reselect starting verts
Application.SelectGeometryComponents(firstTemp)