Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

LayerNames function returns empty list after Opening project?

$
0
0

@bmartin wrote:

Hello,

I have a GUI that calls mesh intersection code that sometimes crashes. To prevent losing too much work, I implemented a "backup" function that saves the complete Rhino project (.3dm) and the current GUI-related values (.txt) before the dangerous operations. After a crash, if both these files are available, I load them so that my project is restored and my GUI is reseted to the right values.

My problem is that sometimes, right after the command

rs.Command("_-Open " + backupFile + " _Enter" )

Everything seems fine:

  • I see all the surfaces, curves and points (and I can pick them, etc)
  • The Layers tab shows all the layers (and I can turn them on/off)

BUT the command

rhinoscriptsyntax.LayerNames()

returns an EMPTY layer list... Then, all my other scripts fail because they cannot find their inputs in the expected layer (as rs.IsLayer(layer) returns False ). Here is a print out of the traces I have showing the problem:

First restoration (everything works as expected with lots of layers, in particular the STL one)

Entering RestoreProject...
   allLayers: ['Default', 'Layer 01', 'Layer 02', 'Layer 03', 'Layer 04', 'Layer 05']
RestorationIsPossible: True
Restoring design file: P:\PREP_DECOUPE\BackupDesign.3dm
Python Script ( ResetEngine ): _-Open
Name of the file to open ( UpdatePromptUpdateBlocks=Yes  Browse ): P:\PREP_DECOUPE\BackupDesign.3dm
File "P:\PREP_DECOUPE\BackupDesign.3dm" successfully read
Command: _Enter
   allLayers AFTER -Open command: ['Default', 'STL', '104564D Podoscan', '0', '104564D_Contour_Data4941985', 'Metatarsal_1', 'Metatarsal_2', 'Metatarsal_3', 'Metatarsal_4', 'Metatarsal_5', 'AlignmentPoint_1', 'AlignmentPoint_2', 'AlignmentPoint_3', 'AlignmentPoint_4', 'AlignmentPoint_5', 'AxisLines', 'Forefoot_Contour', 'Medial_Edge', 'Lateral_Edge', '104564D_Contour_Data4941985::Heel_Contour']
Restoring parameters file: P:\PREP_DECOUPE\BackupParameters.txt
   allLayers AFTER reading parameters: ['Default', 'STL', '104564D Podoscan', '0', '104564D_Contour_Data4941985', 'Metatarsal_1', 'Metatarsal_2', 'Metatarsal_3', 'Metatarsal_4', 'Metatarsal_5', 'AlignmentPoint_1', 'AlignmentPoint_2', 'AlignmentPoint_3', 'AlignmentPoint_4', 'AlignmentPoint_5', 'AxisLines', 'Forefoot_Contour', 'Medial_Edge', 'Lateral_Edge', '104564D_Contour_Data4941985::Heel_Contour']
Restoring UI
UI update finish
   allLayers AFTER UI update: ['Default', 'STL', '104564D Podoscan', '0', '104564D_Contour_Data4941985', 'Metatarsal_1', 'Metatarsal_2', 'Metatarsal_3', 'Metatarsal_4', 'Metatarsal_5', 'AlignmentPoint_1', 'AlignmentPoint_2', 'AlignmentPoint_3', 'AlignmentPoint_4', 'AlignmentPoint_5', 'AxisLines', 'Forefoot_Contour', 'Medial_Edge', 'Lateral_Edge', '104564D_Contour_Data4941985::Heel_Contour']

Second restoration (after Open command on same project file, no more layer!!!)

Entering RestoreProject...
   allLayers: ['Default', 'STL', '104564D Podoscan', '0', '104564D_Contour_Data4941985', 'Metatarsal_1', 'Metatarsal_2', 'Metatarsal_3', 'Metatarsal_4', 'Metatarsal_5', 'AlignmentPoint_1', 'AlignmentPoint_2', 'AlignmentPoint_3', 'AlignmentPoint_4', 'AlignmentPoint_5', 'AxisLines', 'Forefoot_Contour', 'Medial_Edge', 'Lateral_Edge', '104564D_Contour_Data4941985::Heel_Contour']
RestorationIsPossible: True
Restoring design file: P:\PREP_DECOUPE\BackupDesign.3dm
Command: _-Open
Name of the file to open ( UpdatePromptUpdateBlocks=Yes  Browse ): P:\PREP_DECOUPE\BackupDesign.3dm
File "P:\PREP_DECOUPE\BackupDesign.3dm" successfully read
Command: _Enter
   allLayers AFTER -Open command: []
Restoring parameters file: P:\PREP_DECOUPE\BackupParameters.txt
   allLayers AFTER reading parameters: []
Restoring UI
UI update finish
   allLayers AFTER UI update: []

And here is the RestoreProject function that produced these traces:

 def RestoreProject(self):
        """ Restores the Rhino project from its last state along with the Heel modeling parameters.
        """
        print "\nEntering RestoreProject..."
        allLayers = rs.LayerNames()
        print "   allLayers: " + str(allLayers)
        
        if not self.RestorationIsPossible():
            return
        
        GeoUtil.ShowMessageAndContinue("Restoring design file: " + self.BkpDesignCompleteFilename(), sleeptime=2)
        rs.Command("_-Open " + self.BkpDesignCompleteFilename() + " _Enter" )
        
        allLayers = rs.LayerNames()
        print "   allLayers AFTER -Open command: " + str(allLayers)
        
        GeoUtil.ShowMessageAndContinue("Restoring parameters file: " + self.BkpParametersCompleteFilename(), sleeptime=2)
        paramFile = open(self.BkpParametersCompleteFilename(), 'rt')
        readParameters = pickle.load( paramFile )
        self.data = readParameters
        paramFile.close()
        
        allLayers = rs.LayerNames()
        print "   allLayers AFTER reading parameters: " + str(allLayers)
        GeoUtil.ShowMessageAndContinue("Restoring UI", sleeptime=2)
        self.UpdateUI()
        
        allLayers = rs.LayerNames()
        print "   allLayers AFTER UI update: " + str(allLayers)

Does anyone have an Idea of what could be going on? Is there some Rhino call that I could make that would re-parse the project structure and rediscover the layers?

Thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles