def feedset_contents_migrate(): matchingFeedersFrom = get_feeders_by_name( 'Substring of feed names to move from') if matchingFeedersFrom is None or not len(matchingFeedersFrom): return matchingFeedersTo = get_feeders_by_name( 'Substring of feed names to move to') if matchingFeedersTo is None or not len(matchingFeedersTo): return if len(matchingFeedersTo) < len(matchingFeedersFrom): psypnp.ui.showError("Destination has less slots than source--aborting") return numModded = 0 fswap = FeedSwapper() for i in range(0, len(matchingFeedersFrom)): srcFeed = matchingFeedersFrom[i] destFeed = matchingFeedersTo[i] fswap.movePart(srcFeed, destFeed, EnableSwap) numModded += 1 if EnableSwap: psypnp.showMessage("Swapped %i feeders" % numModded) else: psypnp.showMessage("Migrated %i feeders" % numModded)
def main(): lastProjName = psypnp.nv.get_subvalue(StorageParentName, 'projname') lastFileName = psypnp.nv.get_subvalue(StorageParentName, 'filename') if lastProjName is None: lastProjName = 'My Project' if lastFileName is None: lastFileName = 'feed_map.csv' fmap = FeedMapper.FeedMapper() feed_info = fmap.map() if feed_info is None or not len(feed_info): psypnp.showMessage("No enabled feeds to export") return projname = psypnp.getUserInput("Project Name", lastProjName) if projname is None: return fname = psypnp.getUserInput("Save as CSV file", lastFileName) if fname is None: return psypnp.nv.set_subvalue(StorageParentName, 'projname', projname, False) psypnp.nv.set_subvalue(StorageParentName, 'filename', fname) numFeeds = generate_csv(feed_info, projname, fname) psypnp.showMessage("Saved %i feeds to %s" % (numFeeds, fname))
def set_part_heights(setAll): psypnp.debug.out.buffer('Setting parts heights to defaults...') allParts = config.getParts() noHeightParts = [] for aPart in allParts: hValue = aPart.getHeight().getValue() if setAll or hValue < 0.001: psypnp.debug.out.buffer('No height set for %s' % str(aPart)) noHeightParts.append(aPart) numChanged = 0 for confedHeight in DefaultHeightsMap.items(): pheightLen = None # reset this for noHPart in noHeightParts: pid = noHPart.getId() if pid is not None and pid.find(confedHeight[0]) >= 0: if pheightLen is None: pheightLen = Length(confedHeight[1], HeightUnits) psypnp.debug.out.buffer('Setting height to %s for %s' % (str(confedHeight[1]), str(aPart))) noHPart.setHeight(pheightLen) numChanged += 1 statusMsg = "Number parts affected: %i" % numChanged psypnp.debug.out.flush(statusMsg) gui.getPartsTab().repaint() psypnp.showMessage(statusMsg)
def main(): lastProjName = psypnp.nv.get_subvalue(StorageParentName, 'projname') lastFileName = psypnp.nv.get_subvalue(StorageParentName, 'filename') if lastProjName is None: lastProjName = 'My Project' if lastFileName is None: lastFileName = '/tmp/feeds_config.csv' feed_info = freeze_feeders() if feed_info is None or not len(feed_info): psypnp.showMessage("No enabled feeds to map") return projname = psypnp.getUserInput("Name of project", lastProjName) if projname is None: return fname = psypnp.getUserInput("Save as CSV file", lastFileName) if fname is None: return psypnp.nv.set_subvalue(StorageParentName, 'projname', projname, False) psypnp.nv.set_subvalue(StorageParentName, 'filename', fname) numFeeds = generate_backup(feed_info, projname, fname) psypnp.showMessage("Saved %i feeds to %s" % (numFeeds, fname))
def set_feeder_heights(): nvStore = psypnp.nv.NVStorage(psypnp.config.storagekeys.FeedSearchStorage) selFeeders = psypnp.ui.getSelectedFeeders() defName = nvStore.feedname if len(selFeeders) == 1: defName = selFeeders[0] if defName is None or not len(defName): defName = '8mmStrip' # some default value feedSearch = psypnp.search.prompt_for_feeders_by_name("Name of feeder, or substring thereof to match many", defName) if feedSearch is None or feedSearch.searched is None or not len(feedSearch.searched): return nvStore.feedname = feedSearch.searched if not len(feedSearch.results): psypnp.ui.showError("No feeders match name '%s'" % pname, 'None found') return height = get_height_len() if height is None: return numChanged = 0 for afeeder in feedSearch.results: apart = afeeder.getPart() if apart is not None: pHeight = apart.getHeight() if DoSubtractPartHeightFromLevel: feederHeight = height.subtract(pHeight) else: feederHeight = height refHole = afeeder.getReferenceHoleLocation() if refHole is not None: numChanged += 1 newHole = Location(refHole.getUnits(), refHole.getX(), refHole.getY(), 0, 0) newZ = Location(feederHeight.getUnits(), 0, 0, feederHeight.getValue(), 0) newHole = newHole.add(newZ) psypnp.debug.out.buffer("Setting ref hole for %s to %s" % (afeeder.getName(), str(newHole))) afeeder.setReferenceHoleLocation(newHole) print("Number feeders affected: %i" % numChanged) gui.getFeedersTab().repaint() psypnp.showMessage("Set level Z for %i feeders" % numChanged)
def get_coords(): headcams = machine.defaultHead.getCameras() maccams = machine.getCameras() targetCam = None for acam in maccams: targetCam = acam for hcam in headcams: if targetCam is not None and hcam.getId() == targetCam.getId(): # bottom cam is not on the head, kill this targetCam = None if targetCam is None: psypnp.showMessage("Could not find a camera not on defaultHead") return None return targetCam.getLocation()
def main(): partsAl = machine.getPartAlignments() if partsAl and len(partsAl) and partsAl[0]: botvis = partsAl[0] val = psypnp.getUserInput("Max Angular Offset", botvis.getMaxAngularOffset()) if (val is not None): try: val = float(val) except: val = botvis.getMaxAngularOffset() if val >=0 and val <=45: botvis.setMaxAngularOffset(val) psypnp.showMessage("Max angle now %s" % str(botvis.getMaxAngularOffset())) else: psypnp.showError("Need a val between 0-45") else: psypnp.showError("Don't have bottom vision?")
def feeders_translate(): matchingFeeders = get_feeders_by_name() if matchingFeeders is None or not len(matchingFeeders): return xMoveDistance = psypnp.ui.getUserInputFloat("X displacement", 0.0) yMoveDistance = psypnp.ui.getUserInputFloat("Y displacement", 0.0) if xMoveDistance == 0 and yMoveDistance == 0: return fd1 = matchingFeeders[0] refHole = fd1.getReferenceHoleLocation() lastHole = fd1.getLastHoleLocation() orientationDist = lastHole.subtract(refHole) deltaX = 0.0 deltaY = 0.0 if abs(orientationDist.getX()) > abs(orientationDist.getY()): deltaX = orientationDist.getX() else: deltaY = orientationDist.getY() displacementLocation = Location(refHole.getUnits(), xMoveDistance, yMoveDistance, 0, 0) cleanOrientationDisp = Location(refHole.getUnits(), deltaX, deltaY, 0, 0) numChanged = 0 for afeed in matchingFeeders: refHole = afeed.getReferenceHoleLocation() newLocRefHole = refHole.add(displacementLocation) newLastHole = newLocRefHole.add(cleanOrientationDisp) afeed.setReferenceHoleLocation(newLocRefHole) afeed.setLastHoleLocation(newLastHole) numChanged += 1 psypnp.showMessage("Moved %i feeders" % numChanged)
def set_part_heights(): keepGoing = True while keepGoing: pname = psypnp.getUserInput("Name of part, or substring thereof", "C_0603") if pname is None or not len(pname): return height = get_height_len() if height is None: return numChanged = 0 for apart in config.getParts(): if pname == '*' or apart.id.find(pname) >= 0: numChanged += 1 apart.setHeight(height) statusMsg = "Number parts affected: %i" % numChanged print(statusMsg) gui.getPartsTab().repaint() psypnp.showMessage(statusMsg)
def feedset_contents_migrate(): matchingFeedersFrom = get_feeders_by_name( 'Substring of feed names to flip') if matchingFeedersFrom is None or not len(matchingFeedersFrom): return numModded = 0 fswap = FeedSwapper() numFeeds = len(matchingFeedersFrom) halfNumFeeds = numFeeds // 2 maxIdx = numFeeds - 1 if halfNumFeeds < 1: psypnp.ui.showError("nuttin' to do.") return for i in range(0, halfNumFeeds): srcFeed = matchingFeedersFrom[i] destFeed = matchingFeedersFrom[maxIdx - i] fswap.movePart(srcFeed, destFeed, True) numModded += 1 psypnp.showMessage("Flipped %i feeders" % numModded)
def feeders_align(): matchingFeeders = get_feeders_by_name() if matchingFeeders is None or not len(matchingFeeders): return feedLocations = [] runningStatsX = (0, 0, 0) runningStatsY = (0, 0, 0) for afeeder in matchingFeeders: if afeeder.isEnabled(): refHole = afeeder.getReferenceHoleLocation() if refHole is None or not refHole: print("A feed has no reference hole... hum") else: runningStatsX = updatePosStats(runningStatsX, refHole.getX()) runningStatsY = updatePosStats(runningStatsY, refHole.getY()) if runningStatsX[0] < 2: # enabled count is too low psypnp.ui.showError("Not enough enabled feeds to reliably find pos") return statsX = finalizePosStats(runningStatsX) statsY = finalizePosStats(runningStatsY) print("Final stats: \nX: %s\n\nY: %s" % (statsX, statsY)) targetX = None targetY = None if statsX[1] < statsY[1]: # is a vertical set targetX = statsX[0] # set to average X if not psypnp.ui.getConfirmation( "Effect change?", "Will move vertical set to align with x=%s. Proceed?" % str(targetX)): return else: targetY = statsY[0] # set to average Y if not psypnp.ui.getConfirmation( "Effect change?", "Will move horizontal set to align with y=%s. Proceed?" % str(targetY)): return numChanged = 0 for afeeder in matchingFeeders: refHole = afeeder.getReferenceHoleLocation() if targetX is not None: newX = targetX newY = refHole.getY() elif targetY is not None: newX = refHole.getX() newY = targetY newLoc = Location(refHole.getUnits(), newX, newY, refHole.getZ(), refHole.getRotation()) print("Setting feeder loc to: %s" % str(newLoc)) numChanged += 1 afeeder.setReferenceHoleLocation(newLoc) gui.getFeedersTab().repaint() psypnp.showMessage("Aligned %i feeders" % numChanged)