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 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_idx_by_feedname(): # be nice and keep track of last search lastFeedNameSearchVal = psypnp.nv.get_subvalue(StorageParentName, 'feedsrch') if lastFeedNameSearchVal is None: lastFeedNameSearchVal = '8mmTop' # ask for part name/id feedname = psypnp.getUserInput("Name of feed, or substring thereof", lastFeedNameSearchVal) if feedname is None or not len(feedname): return False # store it for next time psypnp.nv.set_subvalue(StorageParentName, 'feedsrch', feedname) print("Searching for feed '%s'" % feedname) foundFeed = psypnp.search.feed_by_name(feedname) if foundFeed is not None: #print("Setting feed idx to %i" % feedDeets.index) if not _set_idx_to_feedid(foundFeed.getId()): psypnp.ui.showError("Couldn't set feed idx??") # set_current_idx(feedDeets.index) else: psypnp.ui.showError("Couldn't locate a feed \nmatching '%s'" % feedname) return True
def clone_part_bottom_pipeline(): pname = psypnp.getUserInput("Name of part to clone from, or substring thereof", "C_0603") if pname is None or not len(pname): return numChanged = 0 matchingParts = psypnp.parts_by_name(pname) if not len(matchingParts): psypnp.showError("No parts matching name found") return if len(matchingParts) > 1: psypnp.showError("Too many matches--don't know which to choose") return sourcePart = matchingParts[0] sourcePackage = sourcePart.getPackage() val = psypnp.getOption("Really proceed?", "Copy bottom view pipeline from %s to all parts with package %s?" % (sourcePart.getId(), sourcePackage.getId()), ['Abort', 'Yes, proceed']) if val != 1: return print("Using part %s as source for bottom vision pipeline" % sourcePart.getId()) partsWithThisPackage = psypnp.parts_by_package(sourcePackage) if partsWithThisPackage is None or len(partsWithThisPackage) < 2: psypnp.showError("Don't seem to be many targets with this package around") return psypnp.util.clone_alignment_pipeline(machine, sourcePart, partsWithThisPackage) print("ALL DONE") gui.getPartsTab().repaint()
def get_feeders_by_name(): nvStore = psypnp.nv.NVStorage('fdrs_align') # get last name used, if possible defName = nvStore.feedname if defName is None or not len(defName): defName = '8mmLeft' # some default value pname = psypnp.getUserInput("Common string in name of feeders in set", defName) if pname is None or not len(pname): return # stash it for next time nvStore.feedname = pname matchingFeeders = [] for afeeder in machine.getFeeders(): if pname == '*' or afeeder.getName().find(pname) >= 0: matchingFeeders.append(afeeder) if not len(matchingFeeders): psypnp.ui.showError("No feeders match name '%s'" % pname) return None return matchingFeeders
def get_feeders_by_name(promptstr): nvStore = psypnp.nv.NVStorage('fdrs_migrate') # get last name used, if possible defName = nvStore.feedname if defName is None or not len(defName): defName = '8mmLeft' # some default value pname = psypnp.getUserInput(promptstr, defName) if pname is None or not len(pname): return # stash it for next time nvStore.feedname = pname matchingFeeders = [] for afeeder in machine.getFeeders(): if afeeder.getName().find(pname) >= 0: matchingFeeders.append(afeeder) if not len(matchingFeeders): psypnp.ui.showError("No feeders match name '%s'" % pname) return None sortedMatchingFeeders = sorted(matchingFeeders, key=lambda x: x.getName()) return sortedMatchingFeeders
def get_height_len(): lenstr = psypnp.getUserInput("Enter desired height (mm) for these feeders", -9.876) try: heightval = float(lenstr) height = Length(heightval, LengthUnit.Millimeters) except: height = Length.parse(lenstr) return height
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 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 set_idx_by_part(): # be nice and keep track of last search lastPartNameSearchVal = psypnp.nv.get_subvalue(StorageParentName, 'partsrch') if lastPartNameSearchVal is None: lastPartNameSearchVal = '100k' # ask for part name/id pname = psypnp.getUserInput("Name of part, or substring thereof", lastPartNameSearchVal) if pname is None or not len(pname): return False # store it for next time psypnp.nv.set_subvalue(StorageParentName, 'partsrch', pname) partsOfInterest = psypnp.search.parts_by_name(pname) if partsOfInterest is None or not len(partsOfInterest): psypnp.ui.showError("No parts found for '%s'" % pname) return True allFeeds = get_sorted_feeders_list() if allFeeds is None or not len(allFeeds): psypnp.ui.showError("No feeders found at all?") return False matchingFeeds = psypnp.search.feeds_by_partslist(partsOfInterest, onlyEnabled=True, feederList=allFeeds) if matchingFeeds is None or not len(matchingFeeds): psypnp.ui.showError("No feeders found for this part") return True if not _set_idx_to_feedid(matchingFeeds[0].getId(), allFeeds): psypnp.ui.showError("Weirdness -- could not extract feed idx??") return True