ja ich bin noch ziemlich neu hier, zu meiner Person: viewtopic.php?f=4&t=7912
Zum Start 2 Bilder:
- für die, die wissen wie es geht: unten der Code zum kopieren
- für alle anderen, folgt ein Beitrag zur Einrichtung von Python und fischertechnik Designer
Code: Alles auswählen
#SerienGenerator
#Autor: Dieter Striebel
#Stand: 13.03.2023
import ftd
import math
lngPartCount = ftd.GetPartCount()
#get the two last added parts. >>> based on this parts, the serie will be generated
prt1 = ftd.GetPartAtIndex(lngPartCount-2)
prt2 = ftd.GetPartAtIndex(lngPartCount-1)
#select ONLY the two last added partsftd.DeSelectAll()
ftd.SelectPart(prt1.Name)
ftd.CoSelectPart(prt2.Name)
#move selected parts zu new phase
lngPhase = prt1.Phase + 1
prt1.Phase = lngPhase
prt2.Phase = lngPhase
ftd.RepaintPhaseView()
#get Object3D
o3d1 = prt1.Object3D
o3d2 = prt2.Object3D
pos1 = o3d1.Position
pos2 = o3d2.Position
dir1 = o3d1.Direction
dir2 = o3d2.Direction
lngDir1x = math.degrees(math.asin(dir1.x))
lngDir2x = math.degrees(math.asin(dir2.x))
lngDir1y = math.degrees(math.asin(dir1.y))
lngDir2y = math.degrees(math.asin(dir2.y))
lngDir1z = math.degrees(math.asin(dir1.z))
lngDir2z = math.degrees(math.asin(dir2.z))
#calculate difference
lngPosDx = pos2.x - pos1.x
lngPosDy = pos2.y - pos1.y
lngPosDz = pos2.z - pos1.z
lngDirDx = lngDir2x - lngDir1x
lngDirDy = lngDir2y - lngDir1y
lngDirDz = lngDir2z - lngDir1z
#store new starting point
lngPosSx = pos2.x
lngPosSy = pos2.y
lngPosSz = pos2.z
lngDirSx = dir2.x
lngDirSy = dir2.y
lngDirSz = dir2.z
#orgNumber = prt2.OrgNumber
orgNumber = prt2.Name[1:6]
lngNumber = int(ftd.InputDlg("Serie erstellen", "Anzahl Bauteile", "0"))
for i in range(lngNumber):
#create new part
strN = ftd.AddPart(orgNumber)
ftd.CoSelectPart(strN)
prtN = ftd.GetPartAtIndex(lngPartCount + i)
prtN.Phase = lngPhase
ftd.RepaintPhaseView()
o3dN = prtN.Object3D
posN = o3dN.Position
dirN = o3dN.Direction
# set new coordinates based on the starting-point and the different of the origianly two last added parts
posN.x = lngPosSx + lngPosDx
posN.y = lngPosSy + lngPosDy
posN.z = lngPosSz + lngPosDz
dirN.x = math.sin(math.radians(lngDirSx + lngDirDx))
dirN.y = math.sin(math.radians(lngDirSy + lngDirDy))
dirN.z = math.sin(math.radians(lngDirSz + lngDirDz))
prtN.CommitChanges(0)
# and store it as new starting point
lngPosSx = posN.x
lngPosSy = posN.y
lngPosSz = posN.z
lngDirSx = dirN.x
lngDirSy = dirN.y
lngDirSz = dirN.z