Пример #1
0
Файл: io.py Проект: jeanim/gear
def exportSkin(path, objects, compression=False):

    xml_doc = etree.Element("skin")
    xml_doc.set("user", getpass.getuser())
    xml_doc.set("date", str(datetime.datetime.now()))
    xml_doc.set("version", str(xsixmldom.VERSION))

    # -----------------------------------------------------
    for obj in objects:

        envelope_op = ope.getOperatorFromStack(obj, "envelopop")
        if not envelope_op:
            gear.log("%s has no envelope skipped"%obj.Name, gear.sev_warning)
            continue

        xsixmldom.setOptions(X3DObject_children=False,
                                    X3DObject_primitive=False,
                                    X3DObject_kinematics=False,
                                    X3DObject_properties=[],
                                    Geometry_operators=["envelopop"],
                                    Compression=compression)
        xObject = xsixmldom.getObject(obj)
        xml_doc.append(xObject.xml)

    # -----------------------------------------------------
    # Save to file
    xmldom.indent(xml_doc)

    tree = etree.ElementTree(xml_doc)
    tree.write(path)

    return True
Пример #2
0
    def getAsXml(self):

        if self.obj is None:
            gear.log("Can't export primitive to xml", gear.sev_error)
            return

        xsixmldom.setOptions(X3DObject_children=False, X3DObject_properties=[], X3DObject_kinematics=False, Geometry_stack=False)
        return xsixmldom.getObject(self.obj).xml
Пример #3
0
    def getAsXml(self):

        if self.obj is None:
            gear.log("Can't export primitive to xml", gear.sev_error)
            return

        xsixmldom.setOptions(X3DObject_children=False, X3DObject_properties=[], X3DObject_kinematics=False, Geometry_stack=False)
        return xsixmldom.getObject(self.obj).xml
Пример #4
0
def gear_ExportObject_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    # -----------------------------------------------------
    # Getting the file path
    path = uit.fileBrowser("Export Object", xsi.ActiveProject2.OriginPath, xsi.Selection(0).Name+"_skin.xml", ["xml"], True)
    if not path:
        return

    xsixmldom.resetOptions()
    xObject = xsixmldom.getObject(xsi.Selection(0))
    xObject.save(path)
Пример #5
0
def gear_ExportObject_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    # -----------------------------------------------------
    # Getting the file path
    path = uit.fileBrowser("Export Object", xsi.ActiveProject2.OriginPath,
                           xsi.Selection(0).Name + "_skin.xml", ["xml"], True)
    if not path:
        return

    xsixmldom.resetOptions()
    xObject = xsixmldom.getObject(xsi.Selection(0))
    xObject.save(path)
Пример #6
0
    def getAsXml(self):

        xml_comp = etree.Element("component")
        xml_comp.set("name", self.fullName)
        xml_comp.set("type", self.type)
        if self.parentComponent is None:
            xml_comp.set("parent", "None")
        else:
            xml_comp.set(
                "parent",
                self.parentComponent.fullName + "." + self.parentLocalName)
        xml_comp.set("root_size", str(self.root.size.Value))

        # Settings and parameters
        xml_settings = self.getParametersAsXml("settings")
        xml_comp.append(xml_settings)

        # Objects
        xml_objects = etree.SubElement(xml_comp, "objects")
        for name in self.objectNames:
            if "#" in name:
                i = 0
                while not self.minmax[name].max > 0 or i < self.minmax[
                        name].max:
                    localName = string.replaceSharpWithPadding(name, i)

                    xsixmldom.setOptions(
                        X3DObject_children=False,
                        X3DObject_primitive=(name in self.save_primitive),
                        X3DObject_kinematics=(name in self.save_transform
                                              or name in self.save_blade),
                        X3DObject_properties=[],
                        Kinematics_local=False,
                        Kinematics_constraints=False,
                        Kinematics_removeScaling=True,
                        Geometry_addScaling=True,
                        Geometry_stack=False)

                    obj = self.model.FindChild(self.getName(localName))
                    if not obj:
                        break
                    xml_def = xsixmldom.getObject(obj).xml
                    xml_def.set("localName", localName)
                    xml_objects.append(xml_def)

                    i += 1

                if i < self.minmax[name].min:
                    gear.log(
                        "Minimum of object requiered for " + name +
                        " hasn't been reached", gear.sev_warning)
                    self.valid = False
                    continue

            else:
                xsixmldom.setOptions(
                    X3DObject_children=False,
                    X3DObject_primitive=(name in self.save_primitive),
                    X3DObject_kinematics=(name in self.save_transform
                                          or name in self.save_blade),
                    X3DObject_properties=[],
                    Kinematics_local=False,
                    Kinematics_constraints=False,
                    Kinematics_removeScaling=True,
                    Geometry_addScaling=True,
                    Geometry_stack=False)

                obj = self.model.FindChild(self.getName(name))
                if not obj:
                    gear.log("Object missing : %s" % name, gear.sev_warning)
                    continue
                xml_def = xsixmldom.getObject(obj).xml
                xml_def.set("localName", name)
                xml_objects.append(xml_def)

        return xml_comp
Пример #7
0
    def getAsXml(self):

        xml_comp = etree.Element("component")
        xml_comp.set("name", self.fullName)
        xml_comp.set("type", self.type)
        if self.parentComponent is None:
            xml_comp.set("parent", "None")
        else:
            xml_comp.set("parent", self.parentComponent.fullName+"."+self.parentLocalName)
        xml_comp.set("root_size", str(self.root.size.Value))

        # Settings and parameters
        xml_settings = self.getParametersAsXml("settings")
        xml_comp.append(xml_settings)

        # Objects
        xml_objects = etree.SubElement(xml_comp, "objects")
        for name in self.objectNames:
            if "#" in name:
                i = 0
                while not self.minmax[name].max > 0 or i < self.minmax[name].max:
                    localName = string.replaceSharpWithPadding(name, i)

                    xsixmldom.setOptions(X3DObject_children=False,
                                             X3DObject_primitive=(name in self.save_primitive),
                                             X3DObject_kinematics=(name in self.save_transform or name in self.save_blade),
                                             X3DObject_properties=[],
                                             Kinematics_local=False,
                                             Kinematics_constraints=False,
                                             Kinematics_removeScaling=True,
                                             Geometry_addScaling=True,
                                             Geometry_stack=False)

                    obj = self.model.FindChild(self.getName(localName))
                    if not obj:
                        break
                    xml_def = xsixmldom.getObject(obj).xml
                    xml_def.set("localName", localName)
                    xml_objects.append(xml_def)

                    i += 1

                if i < self.minmax[name].min:
                    gear.log("Minimum of object requiered for "+name+" hasn't been reached", gear.sev_warning)
                    self.valid = False
                    continue

            else:
                xsixmldom.setOptions(X3DObject_children=False,
                                         X3DObject_primitive=(name in self.save_primitive),
                                         X3DObject_kinematics=(name in self.save_transform or name in self.save_blade),
                                         X3DObject_properties=[],
                                         Kinematics_local=False,
                                         Kinematics_constraints=False,
                                         Kinematics_removeScaling=True,
                                         Geometry_addScaling=True,
                                         Geometry_stack=False)

                obj = self.model.FindChild(self.getName(name))
                if not obj:
                    gear.log("Object missing : %s"%name, gear.sev_warning)
                    continue
                xml_def = xsixmldom.getObject(obj).xml
                xml_def.set("localName", name)
                xml_objects.append(xml_def)

        return xml_comp