Last active
August 29, 2015 14:01
-
-
Save le717/f8714a139ed50e31935b to your computer and use it in GitHub Desktop.
V2 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 LSynth Constraint Part - Type 3 - "Hose" | |
0 Name: LS03.dat | |
0 Author: John VanZwieten, Steve Bliss, Kevin Clague, Paul Easter, Don Heyse | |
0 !LDRAW_ORG Unofficial_Part | |
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt | |
0 BFC CERTIFY CW | |
0 !KEYWORDS LSynth, RCX, ELECTRIC, CABLE, NXT, FIBER, OPTIC, FLEX, SYSTEM, FLEXIBLE, AXLE, MINIFIG, | |
0 !KEYWORDS PNEUMATIC, RIBBED, RUBBER, STRING, CHAIN, BAND, BELT, PLASTIC, TREAD, INSIDE, OUTSIDE, | |
0 !KEYWORDS CROSS, SHOW, HIDE, Synthesis | |
0 !HISTORY 1999-05-02 [kclague] Added nipple (taken from 751.dat) | |
0 !HISTORY 1999-08-19 [SEB] Changed 4-4con12.dat >> 4-4con1.dat | |
0 !HISTORY 2002-10-24 [kclague] Added fin for easy visualization of Y rotation | |
0 !HISTORY 2007-04-03 [Holly-Wood] Changed color 47 to 16, BFCed, converted to new header. | |
1 16 0 5 0 3 0 0 0 -1 0 0 0 3 4-4disc.dat | |
1 16 0 5 0 3 0 0 0 1 0 0 0 3 4-4edge.dat | |
1 16 0 0 0 7 0 0 0 1 0 0 0 7 4-4edge.dat | |
1 16 0 5 0 3 0 0 0 -5 0 0 0 3 4-4cyli.dat | |
1 16 0 -0.5 -4.9 1 0 0 0 5.5 0 0 0 2 box.dat | |
1 16 0 0 0 5 0 0 0 1 0 0 0 5 4-4edge.dat | |
1 16 0 0 0 5 0 0 0 1 0 0 0 5 4-4disc.dat | |
1 16 0 0 0 3 0 0 0 1 0 0 0 3 4-4edge.dat | |
1 16 0 0 0 3 0 0 0 -6 0 0 0 3 4-4cyli.dat | |
1 16 0 -6 0 3 0 0 0 1 0 0 0 3 4-4edge.dat | |
1 16 0 -6 0 1 0 0 0 -1 0 0 0 1 ring3.dat | |
1 16 0 -6 0 4 0 0 0 1 0 0 0 4 4-4edge.dat | |
1 16 0 -6 0 4 0 0 0 -2 0 0 0 4 4-4cyli.dat | |
1 16 0 -8 0 4 0 0 0 -4 0 0 0 4 4-4con0.dat | |
0 | |
0 // Inlined: 1 16 0 0 0 10 0 0 0 15 0 0 0 10 zerobase.dat | |
0 | |
2 4 -10 0 0 10 0 0 | |
2 5 0 -15 0 0 15 0 | |
2 9 0 0 -10 0 0 10 | |
0 +x | |
2 4 11.6 0 0.2 11.6 0 -0.2 | |
2 4 11.8 0 0 11.4 0 0 | |
2 4 10.4 0 0.4 10.8 0 -0.4 | |
2 4 10.8 0 0.4 10.4 0 -0.4 | |
0 -x | |
2 4 -11.8 0 0 -11.4 0 0 | |
2 4 -10.4 0 0.4 -10.8 0 -0.4 | |
2 4 -10.8 0 0.4 -10.4 0 -0.4 | |
0 +y | |
2 5 0.2 17.4 0 -0.2 17.4 0 | |
2 5 0 17.7 0 0 17.1 0 | |
2 5 0 15.9 0 0.4 15.6 0 | |
2 5 0 15.9 0 -0.4 15.9 0 | |
2 5 0 15.9 0 0.4 16.2 0 | |
0 -y | |
2 5 0 -17.7 0 0 -17.1 0 | |
2 5 0 -15.9 0 0.4 -15.6 0 | |
2 5 0 -15.9 0 -0.4 -15.9 0 | |
2 5 0 -15.9 0 0.4 -16.2 0 | |
0 +z | |
2 9 0.2 0 11.6 -0.2 0 11.6 | |
2 9 0 0 11.8 0 0 11.4 | |
2 9 0.4 0 10.4 0.4 0 10.8 | |
2 9 0.4 0 10.4 -0.4 0 10.8 | |
2 9 -0.4 0 10.4 -0.4 0 10.8 | |
0 -z | |
2 9 0 0 -11.8 0 0 -11.4 | |
2 9 0.4 0 -10.4 0.4 0 -10.8 | |
2 9 0.4 0 -10.4 -0.4 0 -10.8 | |
2 9 -0.4 0 -10.4 -0.4 0 -10.8 | |
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 = "LDR-Importer_UnicodeDecodeError/LSynth/LS03.dat" | |
# Only a few of the official META commands, | |
# http://www.ldraw.org/article/401.html | |
metaCommands = [b"0 ", b"!LDRAW_ORG", b"LDRAW_ORG", b"Name"] | |
def removeHeader(): | |
"""Strip part header information""" | |
# Read part contents | |
with open(myFile, "rb") as f: | |
fileContent = f.readlines() | |
# Preform a four-fold check: | |
# * Blank lines | |
# * Lines that start with 0 | |
# * Lines that do NOT start with a 0 and + | |
# * Lines that do NOT start with a 0 and - | |
for command in metaCommands: | |
for line in fileContent: | |
# A line that meet tha criteria was found, remove it from the data | |
if ( | |
line == b"\r\n" or line.startswith(b"0") and | |
not (line.startswith(b"0 +") or line.startswith(b"0 -")) | |
): | |
del fileContent[fileContent.index(line)] | |
print("\nPart content:\n") | |
for finalData in fileContent: | |
print(finalData) | |
if __name__ == "__main__": | |
removeHeader() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment