Skip to content

Commit

Permalink
Arch: Allow to skip entities in IFC importer
Browse files Browse the repository at this point in the history
import importIFC
importIFC.open("/path/to/myfile.ifc",skip=[14,577,5447])
  • Loading branch information
yorikvanhavre committed Apr 21, 2014
1 parent cbb2add commit 321706c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -37,25 +37,25 @@
if open.__module__ == '__builtin__':
pyopen = open # because we'll redefine open below

def open(filename):
def open(filename,skip=None):
"called when freecad opens a file"
docname = os.path.splitext(os.path.basename(filename))[0]
doc = FreeCAD.newDocument(docname)
doc.Label = decode(docname)
FreeCAD.ActiveDocument = doc
getConfig()
read(filename)
read(filename,skip)
return doc

def insert(filename,docname):
def insert(filename,docname,skip=None):
"called when freecad wants to import a file"
try:
doc = FreeCAD.getDocument(docname)
except:
doc = FreeCAD.newDocument(docname)
FreeCAD.ActiveDocument = doc
getConfig()
read(filename)
read(filename,skip)
return doc

def getConfig():
Expand Down Expand Up @@ -97,13 +97,18 @@ def getIfcOpenShell():
else:
return True

def read(filename):
def read(filename,skip=None):
"Parses an IFC file"

# parsing the IFC file
t1 = time.time()

processedIds = []
skipIds = skip
if not skipIds:
skipIds = []
elif isinstance(skipIds,int):
skipIds = [skipIds]

if getIfcOpenShell() and not FORCE_PYTHON_PARSER:
# use the IfcOpenShell parser
Expand Down Expand Up @@ -189,9 +194,14 @@ def read(filename):

# retrieving name
n = getCleanName(objname,objid,objtype)


# skip IDs
if objid in skipIds:
if DEBUG: print "skipping because object ID is in skip list"
nobj = None

# skip types
if objtype in SKIP:
elif objtype in SKIP:
if DEBUG: print "skipping because type is in skip list"
nobj = None

Expand Down Expand Up @@ -717,7 +727,7 @@ def getPlacement(entity):
if entitytype == "IFCAXIS2PLACEMENT3D":
x = getVector(getAttr(entity,"RefDirection"))
z = getVector(getAttr(entity,"Axis"))
if not(x) or not(y):
if not(x) or not(z):
return None
y = z.cross(x)
loc = getVector(getAttr(entity,"Location"))
Expand Down

0 comments on commit 321706c

Please sign in to comment.