Deciphering the Layer State File (.las) and its Mapping?

Deciphering the Layer State File (.las) and its Mapping?

Anonymous
Not applicable
4,146 Views
13 Replies
Message 1 of 14

Deciphering the Layer State File (.las) and its Mapping?

Anonymous
Not applicable

I have been attempting to decipher the Layer State File (.las) format and mapping. These files are created when you export a Layer State. I have been unable to find any documentation.

 

I have written a tool to convert .las files to .csv for comparison purposes but without knowing what each value represents I am unable to completely trust my tool. Can anyone help with the mapping of these values?

Attached is a basic example of a .las file containing 3 layers (you can open it in any basic text editor):

 

  0			# >>> Start of 'Header'
LAYERSTATEDICTIONARY
  0				# ???
LAYERSTATE
  1				# ???
ExampleLAS		# Name of Layer State                  
 91				# ???
2047				# ???
301				# ???
				# ???
290				# ???
0				# Current Layer when Layer State was saved
302				# ???
0			# <<< End of 'Header'	
  8			# >>> Start of Attributes for First Layer; What does '8' mean/represent?
C-ANNO			# Layer Name
 90				# ???
8				# Layer 'State' as some sort of bitwise value?; ie Frozen/Thawed/On/Off/Locked/Unlocked/Plot/NoPlot
 62				# ???
2				# Color 
370				# ???
-3				# Lineweight; -3 is 'Default'
  6				# ???
Continuous			# Linetype
  2				# ???
Color_2				# Plot Style
440				# ???
0			# <<< End of Attributes for First Layer; What does '0' mean/represent?
  8			# Then Repeats, 14 lines per layer... (unless the color is stored as RGB, then it's 16 lines, ugh)
Defpoints
 90
2
 62
9
370
-3
  6
Continuous
  2
Color_9
440
0
  8
0
 90
8
 62
7
370
-3
  6
Continuous
  2
Color_7
440
0

Thanks.

4,147 Views
13 Replies
Replies (13)
Message 2 of 14

rkmcswain
Mentor
Mentor
The numbers such as 8 (layer), 62 (color), etc. look like DXF codes.
R.K. McSwain     | CADpanacea | on twitter
Message 3 of 14

Anonymous
Not applicable

Thanks for the reply, this very helpful.

 

Looking at the DXF Codes here it seems that every line of actual data is preceded by a DXF code line for type of data. This clears up about half of all the lines, one mystery solved!

 

Regarding the layer 'State' value (4th line of each entry), expanding on user dnl999's work this is what I have so far:

 

Capture.PNG

 

Now if I could just figure out what all is in the header.

Message 4 of 14

OBERDACKER
Advocate
Advocate

@Anonymous were you ever successfull of figuring out what the header information meant?  I have a couple of guesses, but they don't necessarily make sense in context.  I am confident that the 301 is the code for a text string and in reference to my layer states the line following 301 is the "description"  that is displayed in the layer state manager dialog box for the layer state.

 

I thought that 91 may be a reference to the number of rows, but my .las has way more lines than that and way fewer rows, if I stretch out the entries for each layer into columns.

 

I'm still at a loss for 290 and 302 as I have only found references to boolean flag value and text string respectively. 

Message 5 of 14

Anonymous
Not applicable

Hi OBERDACKER,

 

No I was never able to decipher the rest but ultimately it didn't matter, the LISP routine I wrote to batch apply the .las file works flawlessly without editing the header. (It's now part of the standard workflow for the groups I work with). And the Excel tool I wrote to read, and write .las files without the need to ever touch CAD always works without touching the header.

 

I can say that one of the header values must represent the 'space' (model/layout etc) that the layerstate was saved in.

 

Sadly however, AutoDesk tweaked the .LAS formatting with AutoCAD 2018 and my tools no longer work, it now contains more entries per layer, and the number of properties per layer very wildly. All of which I believe is related to weather or not the property was applied as an XREF override but I haven't had a chance to update my code.

 

- N

Message 6 of 14

OBERDACKER
Advocate
Advocate

You wrote a tool to allow Excel read AND WRITE .las files?  If you would like to share any of your approach to do that I would love to hear about it.  I am finally making the time to look into a way to be able to import the information from a .las file into Excel so we can more easily document the layer states.  Our current process is to update an excel file, do some stuff to it,  export each layer state to a separate .csv file, and finally import it into AutoCAD.  That's a lot of work when you only have a couple relatively small changes, but it's either that or I have to make the changes to the AutoCAD template and the Excel file which is just begging to introduce more errors.  If we had a way to relatively easily just document changes made to the template it'd be much easier to make the small updates.

Message 7 of 14

OBERDACKER
Advocate
Advocate

So this really sucks.  I did some work and have determined that when Autodesk changed the file format in AutoCAD 2018 it caused the Lock and Unlock values to switch from your published chart.  Why would anyone do something like this?  It must make it extra complicated to open, or convert, files from, or to, previous versions.   I wonder how often they make this kind of background change?  This makes me question if it is really worth it for me to figure out a way to document our layer states, but reading exported .las files.  How long would it be before I would notice a change like this?

Message 8 of 14

rkmcswain
Mentor
Mentor
@OBERDACKER

Why would anyone do something like this?  It must make it extra complicated to open, or convert, files from, or to, previous versions. 

You have to think it was either a mistake, or a step to try and keep the competition on their toes. Am I missing anything else?

R.K. McSwain     | CADpanacea | on twitter
Message 9 of 14

Anonymous
Not applicable

I think the more likely scenario is that my chart was wrong and I failed to update my forum post when I found the issue. It was a long time ago but I believe I remember finding an error in my bitwise reverse-engineering.

0 Likes
Message 10 of 14

Anonymous
Not applicable

Below is a screenshot of what the excel tool looks like with an .LAS file imported. There are two buttons in the top left to import and export. If I had time I would have added more functionality like the ability to 'append' an additional .LAS to whatever was already loaded. However, since the export function just outputs all rows you can manually add or paste rows in before you export.

 

My Method (bear with me as I am not a programmer):

  • The file dialog box for the import/export popups were from this site, it opens a Windows file open dialog and has some basic validation. The export function acts similar.
  • For reading .LAS files I used 'FileSystemObject.OpenTextFile' (I believe you need to enable to include 'Microsoft Scripting Runtime' as a reference). I then read the .LAS file line by line as a stream (not a great idea, see lessons learned) so that I didn't have to store the entire file, sometimes they were 160,000 lines long. I then skip the header, then write each entry to an array, decode if necessary, and finally write the values to cells. Note, some values like the one bitwise 'state' entry actually ends up populating cells for ON, FROZEN, LOCKED, PLOT, NEWVPFREEZE. So it's not simple 1-to-1. The biggest challenge here was not getting off by a single line in the .LAS file since it's just a running list. Example, I discovered that if a layer's color was stored as an RGB color the number of entries for that layer would be 16, not the normal 14.
  • For writing .LAS files it's basically the same thing in reverse. I used 'FileSystemObject.CreateTextFile' and then just the WriteLine function to write one line at a time. I just write the original header back to a text file, then re-encode the entries and write them with their alternating DXF codes. 

Lessons Learned (what I would do differently):

  • Reading the .LAS file line by line as a stream was a nightmare since you can't 'look ahead' to the next line to see if the layer is done or it's one of those 16 line RGB layers. HINT: This method would make the 2018 changes a nightmare.
  • In retrospect I would have just loaded the entire .LAS file into a temp/hidden sheet and processed it from there. this would have allowed development and debugging to be much easier.

Regardless of all of that, for AutoCAD 2016 at least, this one excel tool was probably used 2000 times but several groups on two projects.

 

MLAS-Capture.PNG

Message 11 of 14

Anonymous
Not applicable

POSSIBLE ERROR: the lock/unlock column (bit value) may be inverted 

0 Likes
Message 12 of 14

OBERDACKER
Advocate
Advocate

@Anonymous am I correct in Assuming that you have 40 listed in your chart because it showed up in one of your exported, from AutoCAD, .las files?  I'm asking because as best I can tell there are only 32 unique combinations of the information stored in the layer state value.  Below is the chart I came up with which I believe matched those in your chart.

2019-10-29_09-52-28.png

I ran the configurations in the .las file from 0 to 63.  The only difference between the patterns is for every value above 31 the pattern repeated except for "Freeze in all View Ports" column which was always frozen.  I left the "View Port Freeze" column out as that only shows up in the layer manager and not the layer state manager and it did not seem to have any effect on the layer state value, at least not as far as I could tell.  I'll share my comparison if anyone want to see it.

 

Thank you for your explanation and lessons learned reply above.  I'll probably end up importing the .las information into it's own worksheet before processing the layer state values to human readable columns.  This looks like it is going to be a more involved than I originally thought.  Wish me luck.

Message 13 of 14

Anonymous
Not applicable

@OBERDACKER , yes I did see a 40 in a 2016 .LAS file at the time. Are you working with 2018 files? Sounds like the sixth bit is for 'Freeze in all viewports', who knows if it can be set by a layerstate.

 

Are you familiar with how those values are stored? It utilizes bitwise operations. Basically it's storing each togglable  value as a 1 or 0 then, when you look at as a binary number you might get 001100 which is the value 24 that you are seeing the .LAS file. So each 'bit' represents a power of 2 (binary) which allows for the numbers 0-63 to all represent a unique set of on/offs.

 

All programming languages (including Excel's VBA) has bitwise operations so you don't have to convert back and forth to binary to figure out a specific on/off. If you're going to tackle this in VBA (excel) let me know and I can share portions of my code that worked in 2016.

Message 14 of 14

TonyRB
Enthusiast
Enthusiast

Can I get that table?

0 Likes