Skip to content

Instantly share code, notes, and snippets.

@le717
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le717/e744e54b14a05bdf6cdb to your computer and use it in GitHub Desktop.
Save le717/e744e54b14a05bdf6cdb to your computer and use it in GitHub Desktop.
V1 Prototype code to skip LDraw file header
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
#! /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