def _change_kfile(self): kfile = forms.pick_file('txt') if kfile: logger.debug('Setting keynote file: %s' % kfile) try: with revit.Transaction("Set Keynote File"): revit.update.set_keynote_file(kfile, doc=revit.doc) self._kfile = revit.query.get_keynote_file(doc=revit.doc) # attempt at opening the selected file. try: self._conn = kdb.connect(self._kfile) except Exception as ckf_ex: forms.alert( "Error opening seleced keynote file.", sub_msg=str(ckf_ex), expanded="{}::_change_kfile() [kdb.connect]".format( self.__class__.__name__) ) return self._kfile except Exception as skex: forms.alert(str(skex), expanded="{}::_change_kfile() [transaction]".format( self.__class__.__name__))
def _convert_existing(self): # make a copy of exsing temp_kfile = op.join(op.dirname(self._kfile), op.basename(self._kfile) + '.bak') shutil.copy(self._kfile, temp_kfile) os.remove(self._kfile) try: self._conn = kdb.connect(self._kfile) kdb.import_legacy_keynotes(self._conn, temp_kfile, skip_dup=True) except System.TimeoutException as toutex: forms.alert(toutex.Message, exitscript=True)
def __init__(self, xaml_file_name): forms.WPFWindow.__init__(self, xaml_file_name) # verify keynote file existence self._kfile = revit.query.get_keynote_file(doc=revit.doc) if not self._kfile or not op.exists(self._kfile): self._kfile = None forms.alert("Keynote file is not accessible. " "Please select a keynote file.") self._change_kfile() # if a keynote file is still not set, return if not self._kfile: raise Exception('Keynote file is not setup.') self._conn = None try: self._conn = kdb.connect(self._kfile) except System.TimeoutException as toutex: forms.alert(toutex.Message, exitscript=True) except Exception as ex: logger.debug('Connection failed | %s' % ex) res = forms.alert( "Existing keynote file needs to be converted to " "a format usable by this tool. The resulting keynote " "file is still readble by Revit and could be shared " "with other projects. Users should NOT be making changes to " "the existing keynote file during the conversion process.\n" "Are you sure you want to convert?", options=["Convert", "Give me more info"]) if res: if res == "Convert": try: self._convert_existing() forms.alert("Conversion completed!") if not self._conn: forms.alert( "Launch the tool again to manage keynotes.", exitscript=True) except Exception as convex: logger.debug('Legacy conversion failed | %s' % convex) forms.alert("Conversion failed! %s" % convex, exitscript=True) elif res == "Give me more info": script.open_url('https://eirannejad.github.io/pyRevit') script.exit() else: forms.alert("Keynote file is not yet converted.", exitscript=True) self._cache = [] self._allcat = kdb.RKeynote(key='', text='-- ALL CATEGORIES --', parent_key='', locked=False, owner='', children=None) self._config = script.get_config() self._used_keysdict = self.get_used_keynote_elements() self.load_config() self.search_tb.Focus()
def __init__(self, xaml_file_name, reset_config=False): forms.WPFWindow.__init__(self, xaml_file_name) # verify keynote file existence self._kfile = revit.query.get_local_keynote_file(doc=revit.doc) self._kfile_handler = None if not self._kfile: self._kfile_ext = \ revit.query.get_external_keynote_file(doc=revit.doc) self._kfile_handler = 'unknown' # mak sure ADC is available if self._kfile_handler == 'unknown': if adc.is_available(): self._kfile_handler = 'adc' # check if keynote file is being synced by ADC # use the drive:// path for adc communications # adc module takes both remote or local paths, # but remote is faster lookup local_kfile = adc.get_local_path(self._kfile_ext) if local_kfile: # check is someone else has locked the file locked, owner = adc.is_locked(self._kfile_ext) if locked: forms.alert( "Keynote file is being modified and locked by " "{}. Please try again later".format(owner), exitscript=True) # force sync to get the latest contents adc.sync_file(self._kfile_ext) adc.lock_file(self._kfile_ext) # now that adc communication is done, # replace with local path self._kfile = local_kfile self.Title += ' (BIM360)' else: forms.alert("Can not get keynote file from {}".format( adc.ADC_NAME), exitscript=True) else: forms.alert( "This model is using a keynote file that seems to be " "managed by {long} ({short}). But {short} is not " "running, or is not installed. Please install/run the " "{short} and open the keynote manager again".format( long=adc.ADC_NAME, short=adc.ADC_SHORTNAME), exitscript=True) # byt this point we must have a local path to the keynote file if not self._kfile or not op.exists(self._kfile): self._kfile = None forms.alert("Keynote file is not accessible. " "Please select a keynote file.") self._change_kfile() # if a keynote file is still not set, return if not self._kfile: raise Exception('Keynote file is not setup.') # if a keynote file is still not set, return if not os.access(self._kfile, os.W_OK): raise Exception('Keynote file is read-only.') self._conn = None try: self._conn = kdb.connect(self._kfile) except System.TimeoutException as toutex: forms.alert(toutex.Message, expanded="{}::__init__()".format( self.__class__.__name__), exitscript=True) except Exception as ex: logger.debug('Connection failed | %s' % ex) res = forms.alert( "Existing keynote file needs to be converted to " "a format usable by this tool. The resulting keynote " "file is still readble by Revit and could be shared " "with other projects. Users should NOT be making changes to " "the existing keynote file during the conversion process.\n" "Are you sure you want to convert?", options=[ "Convert", "Select a different keynote file", "Give me more info" ]) if res: if res == "Convert": try: self._convert_existing() forms.alert("Conversion completed!") if not self._conn: forms.alert( "Launch the tool again to manage keynotes.", exitscript=True) except Exception as convex: logger.debug('Legacy conversion failed | %s' % convex) forms.alert("Conversion failed! %s" % convex, exitscript=True) elif res == "Select a different keynote file": self._change_kfile() elif res == "Give me more info": script.open_url(__helpurl__) #pylint: disable=undefined-variable script.exit() else: forms.alert("Keynote file is not yet converted.", exitscript=True) self._cache = [] self._allcat = kdb.RKeynote(key='', text='-- ALL CATEGORIES --', parent_key='', locked=False, owner='', children=None) self._needs_update = False self._config = script.get_config() self._used_keysdict = self.get_used_keynote_elements() self.load_config(reset_config) self.search_tb.Focus()