Several enhancements
+ PLMXML Reader + Some meta information sorting + Making ProductRefs invisibly in Tree
This commit is contained in:
@@ -61,6 +61,7 @@ SET(SCL_Resources
|
||||
automotive_design.py # AP214e3
|
||||
ifc2x3.py # IFC
|
||||
ifc4.py # IFC 4
|
||||
PlmXmlParser.py
|
||||
)
|
||||
SOURCE_GROUP("SCL" FILES ${SCL_Resources})
|
||||
|
||||
|
||||
@@ -20,40 +20,133 @@
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#* Juergen Riegel 2002 *
|
||||
#* Juergen Riegel 2015 *
|
||||
#***************************************************************************/
|
||||
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
FreeCAD_On = False
|
||||
FreeCAD_Doc = None
|
||||
FreeCAD_ObjList = []
|
||||
|
||||
def ParseUserData(element):
|
||||
if element:
|
||||
res = {}
|
||||
for value in element.findall('{http://www.plmxml.org/Schemas/PLMXMLSchema}UserValue'):
|
||||
res = {}
|
||||
for i in element.findall('{http://www.plmxml.org/Schemas/PLMXMLSchema}UserData'):
|
||||
for value in i.findall('{http://www.plmxml.org/Schemas/PLMXMLSchema}UserValue'):
|
||||
res[value.attrib['title']] = value.attrib['value']
|
||||
return res
|
||||
return None
|
||||
return res
|
||||
|
||||
def addPart(partElement):
|
||||
#print partElement.attrib
|
||||
pass
|
||||
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
|
||||
print "=== Part ======================================================"
|
||||
name = partElement.attrib['name']
|
||||
id = partElement.attrib['id']
|
||||
userData = ParseUserData(partElement)
|
||||
|
||||
bound = partElement.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}Bound')
|
||||
print bound.attrib['values']
|
||||
|
||||
representation = partElement.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}Representation')
|
||||
format = representation.attrib['format']
|
||||
location = representation.attrib['location']
|
||||
|
||||
print id, name, userData, format, location
|
||||
if FreeCAD_On:
|
||||
import FreeCAD,Assembly
|
||||
print"Create Reference"
|
||||
partObject =FreeCAD_Doc.addObject("App::Part",id)
|
||||
FreeCAD_ObjList.append(partObject)
|
||||
partObject.Label = name
|
||||
partObject.Meta = userData
|
||||
|
||||
def addAssembly(asmElement):
|
||||
#print asmElement.attrib
|
||||
pass
|
||||
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
|
||||
print "=== Assembly ======================================================"
|
||||
userData = ParseUserData(asmElement)
|
||||
name = asmElement.attrib['name']
|
||||
id = asmElement.attrib['id']
|
||||
instanceRefs = asmElement.attrib['instanceRefs']
|
||||
userData['instanceRefs'] = instanceRefs
|
||||
|
||||
print id, name, instanceRefs, userData
|
||||
if FreeCAD_On:
|
||||
import FreeCAD,Assembly
|
||||
print"Create Reference"
|
||||
admObject =FreeCAD_Doc.addObject("Assembly::Product",id)
|
||||
FreeCAD_ObjList.append(admObject)
|
||||
admObject.Label = name
|
||||
admObject.Meta = userData
|
||||
|
||||
def addReference(refElement):
|
||||
#print refElement.attrib
|
||||
pass
|
||||
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
|
||||
print "=== Reference ======================================================"
|
||||
userData = ParseUserData(refElement)
|
||||
partRef = refElement.attrib['partRef'][1:]
|
||||
userData['partRef'] = partRef
|
||||
id = refElement.attrib['id']
|
||||
name = refElement.attrib['name']
|
||||
transform = refElement.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}Transform')
|
||||
mtrx = [float(i) for i in transform.text.split(' ')]
|
||||
print mtrx
|
||||
print id,name,partRef
|
||||
|
||||
if FreeCAD_On:
|
||||
import FreeCAD,Assembly
|
||||
print"Create Reference"
|
||||
refObject =FreeCAD_Doc.addObject("Assembly::ProductRef",id)
|
||||
FreeCAD_ObjList.append(refObject)
|
||||
refObject.Label = name
|
||||
refObject.Meta = userData
|
||||
|
||||
def resolveRefs():
|
||||
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
|
||||
print "=== Resolve References ======================================================"
|
||||
if FreeCAD_On:
|
||||
for i in FreeCAD_ObjList:
|
||||
if i.TypeId == 'Assembly::Product':
|
||||
objectList = []
|
||||
for l in i.Meta['instanceRefs'].split(' '):
|
||||
objectList.append(FreeCAD_Doc.getObject(l))
|
||||
i.Items = objectList
|
||||
if i.TypeId == 'Assembly::ProductRef':
|
||||
i.Item = FreeCAD_Doc.getObject(i.Meta['partRef'])
|
||||
|
||||
def open(fileName):
|
||||
"""called when freecad opens an PlmXml file"""
|
||||
global FreeCAD_On,FreeCAD_Doc
|
||||
import FreeCAD,os
|
||||
docname = os.path.splitext(os.path.basename(fileName))[0]
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
message='Started with opening of "'+fileName+'" file\n'
|
||||
FreeCAD.Console.PrintMessage(message)
|
||||
FreeCAD_Doc = doc
|
||||
FreeCAD_On = True
|
||||
parse(fileName)
|
||||
resolveRefs()
|
||||
|
||||
def insert(filename,docname):
|
||||
"""called when freecad imports an PlmXml file"""
|
||||
global FreeCAD_On,FreeCAD_Doc
|
||||
import FreeCAD
|
||||
FreeCAD.setActiveDocument(docname)
|
||||
doc=FreeCAD.getDocument(docname)
|
||||
FreeCAD.Console.PrintMessage('Started import of "'+filename+'" file')
|
||||
FreeCAD_Doc = doc
|
||||
FreeCAD_On = True
|
||||
parse(fileName)
|
||||
resolveRefs()
|
||||
|
||||
def main():
|
||||
parse('../../../../data/tests/Jt/Engine/2_Cylinder_Engine3.plmxml')
|
||||
|
||||
tree = ET.parse('../../../../data/tests/Jt/Engine/2_Cylinder_Engine3.plmxml')
|
||||
def parse(fileName):
|
||||
|
||||
tree = ET.parse(fileName)
|
||||
root = tree.getroot()
|
||||
ProductDef = root.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}ProductDef')
|
||||
|
||||
ParseUserData(ProductDef.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}UserData'))
|
||||
res = ParseUserData(ProductDef.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}UserData'))
|
||||
|
||||
InstanceGraph = ProductDef.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}InstanceGraph')
|
||||
|
||||
@@ -87,7 +180,7 @@ def main():
|
||||
addPart(child)
|
||||
continue
|
||||
if child.attrib['type'] == 'assembly' :
|
||||
addPart(child)
|
||||
addAssembly(child)
|
||||
continue
|
||||
print "Unknown Part type:",child
|
||||
else:
|
||||
|
||||
@@ -31,4 +31,4 @@
|
||||
#FreeCAD.addImportType("STEP 214 (*.step *.stp)","ImportGui")
|
||||
#FreeCAD.addExportType("STEP 214 (*.step *.stp)","ImportGui")
|
||||
#FreeCAD.addExportType("IGES files (*.iges *.igs)","ImportGui")
|
||||
FreeCAD.addExportType("PLMXML files (*.plmxml)","Import")
|
||||
FreeCAD.addImportType("PLMXML files (*.plmxml)","PlmXmlParser")
|
||||
|
||||
Reference in New Issue
Block a user