Last active
August 29, 2015 14:01
-
-
Save le717/e744e54b14a05bdf6cdb to your computer and use it in GitHub Desktop.
V1 Prototype code to skip LDraw file header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 ~Moved to LS01 | |
0 Name: LS00.dat | |
0 Author: [Willy Tschager] | |
0 !LDRAW_ORG Unofficial_Part | |
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt | |
0 BFC CERTIFY CCW | |
0 !HISTORY 2007-06-27 [Willy Tschager] Initial version | |
0 // LSynth Constraint Part - Type 1 - "Hose" | |
1 16 0 0 0 1 0 0 0 1 0 0 0 1 LS01.dat | |
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
myFile = "LS00.dat" | |
# Official META commands, http://www.ldraw.org/article/401.html | |
metaCommands = [b"Author", b"BFC", b"!CATEGORY", b"CLEAR", b"!CMDLINE", | |
b"!COLOUR", b"!HELP", b"!HISTORY", b"!KEYWORDS", | |
b"!LDRAW_ORG", b"LDRAW_ORG", b"!LICENSE", b"Name" | |
] | |
def removeHeader(fileContent=None): | |
"""Strip part header information""" | |
# Only read the file is the contents has not been read already | |
if fileContent is None: | |
with open(myFile, "rb") as f: | |
fileContent = f.readlines() | |
# Always remove the first line (part name and number) | |
del fileContent[0] | |
# Check if any META commands are present | |
for command in metaCommands: | |
for line in fileContent: | |
# Yes, some was found, so remove them | |
if line[2:].startswith(command): | |
del fileContent[fileContent.index(line)] | |
print("\nPart content:\n") | |
print(fileContent) | |
if __name__ == "__main__": | |
removeHeader() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment