development of the recording of the macro fc info in xml format

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Gandouzi Ghayth
Posts: 41
Joined: Wed May 13, 2020 2:45 am

development of the recording of the macro fc info in xml format

Post by Gandouzi Ghayth »

Hello ,

my research project is to add to the Fc info macro the recording in xml format
and from my research on the forum I understood that it is not enough to add ".xml" at the end of the file for it to write XML. You have to modify all the lines that I gave previously to correctly format the text.
it is necessary to apply the modifications of the macro line fc info from 3689 to 3775

Code: Select all

try:
                f = open(SaveName, 'w') # write
                f.write(iso8859("Info on the element\n"))
                f.write(iso8859("___________________\n"))
                f.write(iso8859(dateUs() + " "+ heure() + "\n\n"))
                f.write(iso8859("Name of the document      :" + ESCAPE + document_ + "\n"))
                f.write(iso8859("Label Name                :" + ESCAPE + object_Label + "\n"))
                f.write(iso8859("Internal Name             :" + ESCAPE + object_Name + "\n"))
                f.write(iso8859("Name of the element       :" + ESCAPE + str(element_) + "\n"))
                f.write(iso8859("Object type               :" + ESCAPE + typeObject + "\n"))

                f.write(iso8859("Mouse coordinates         :" + ESCAPE + "  X:" + ESCAPE + str(position0 * uniteM) + ESCAPE + uniteMs + ESCAPE + "  Y:" + ESCAPE + str(position1 * uniteM) + ESCAPE + uniteMs + ESCAPE + "  Z:" + ESCAPE + str(position2 * uniteM) + ESCAPE + uniteMs + "\n"))
                f.write(iso8859(typeLongueur + "      :" + ESCAPE + str(longueurObjet * uniteM) + ESCAPE + uniteMs + "\n"))

                if rayonObjet != 0.0:
                    f.write(iso8859("Radius                    :" + ESCAPE + str(rayonObjet * uniteM) + ESCAPE + uniteMs + "\n") )

                f.write(iso8859("Perimeter of the shape    :" + ESCAPE + str(perimetre * uniteM) + ESCAPE + uniteMs + "\n\n"))

                if self.GBox_004_SpreadSheet.isChecked():
                    f.write(iso8859("Vertexes and details      :" + ESCAPE + " Number Edges :" + ESCAPE + str(compt_E) + ESCAPE + " Number Faces :" + ESCAPE + str(compt_F) + ESCAPE + " Number Vertexes faces :" + ESCAPE + str(compt_VF) + ESCAPE + " Detail Total :" + ESCAPE + str(RowCountTest) + "\n\n"))
                    co = 0
                    aa = 0
                    for j in enumerate(Edges):
                        f.write(str(j[1]) + ESCAPE +iso8859(str(float(EdgesLong[co]) * float(uniteM)) + ESCAPE + uniteMs + ESCAPE))#"\n"
                        co+=1
                        for a in range(aa,aa+6):
                            try:
                                chaine = str(Vertx[a]).split(":")
                                f.write(chaine[0] + ESCAPE + iso8859(str(float(chaine[1]) * float(uniteM))) + ESCAPE + uniteMs + ESCAPE)
                            except Exception:
                                None
                        aa += 6
                        f.write("\n")
                    f.write("\n")
                    co  = 0
                    cco = 0
                    co2 = 0
                    for j in enumerate(Faces):
                        f.write(str(j[1]) + ESCAPE + iso8859(str(float(FacesSurf[co]) * float(uniteS)) + ESCAPE + uniteSs + "\n"))
                        co += 1

                        for jj in range(cco,len(FacesCoor)):# Faces coordinates
                            cco+=1
                            if FacesCoor[jj] == "T":
                                f.write("\n")
                                break
                            else:
                                chaine = str(FacesCoor[jj]).split(":")
                                f.write(iso8859(chaine[0] + ESCAPE + str(float(chaine[1]) * float(uniteM)) + ESCAPE + uniteMs + ESCAPE))
                                co2 += 1
                                if co2 == 3:
                                    f.write("\n")
                                    co2 = 0

                f.write("\n")
                f.write(iso8859("Plan                     :" + ESCAPE + " XY:" + ESCAPE + self.lineEdit_8xy.text() + ESCAPE + " coordinates:" + ESCAPE + str(Plan_xy_V) + "\n"))
                f.write(iso8859("Plan                     :" + ESCAPE + " YZ:" + ESCAPE + self.lineEdit_8yz.text() + ESCAPE + " coordinates:" + ESCAPE + str(Plan_yz_V) + "\n"))
                f.write(iso8859("Plan                     :" + ESCAPE + " ZX:" + ESCAPE + self.lineEdit_8zx.text() + ESCAPE + " coordinates:" + ESCAPE + str(Plan_zx_V) + "\n\n"))
                f.write(iso8859("The form surface         :" + ESCAPE + str(surface * uniteS) + ESCAPE + uniteSs + "\n"))
                f.write(iso8859("Surface of the face      :" + ESCAPE + str(surfaceFace * uniteS) + ESCAPE + uniteSs + "\n\n"))

                f.write(iso8859("Volume of the form       :" + ESCAPE + str(volume_ * uniteV) + ESCAPE + uniteVs + "\n"))
                f.write(iso8859("Weight                   :" + ESCAPE + str(poids) + ESCAPE + unitePs + ESCAPE + " Density:" + ESCAPE + str(densite) + "\n\n"))

                f.write(iso8859("Center of the shape      :" + ESCAPE + " X:" + ESCAPE + str(boundBoxCenterX * uniteM) + ESCAPE + uniteMs + ESCAPE + " Y:" + ESCAPE + str(boundBoxCenterY * uniteM) + ESCAPE + uniteMs + ESCAPE + " Z:" + ESCAPE + str(boundBoxCenterZ * uniteM) + ESCAPE + uniteMs + "\n"))
                f.write(iso8859("Center of mass           :" + ESCAPE + " X:" + ESCAPE + str(CenterOfMassX   * uniteM) + ESCAPE + uniteMs + ESCAPE + " Y:" + ESCAPE + str(CenterOfMassY   * uniteM) + ESCAPE + uniteMs + ESCAPE + " Z:" + ESCAPE + str(CenterOfMassZ   * uniteM) + ESCAPE + uniteMs + "\n"))
                f.write(iso8859("BoundBox                 :" + ESCAPE + " X:" + ESCAPE + str(boundBoxLX      * uniteM) + ESCAPE + uniteMs + ESCAPE + " Y:" + ESCAPE + str(boundBoxLY      * uniteM) + ESCAPE + uniteMs + ESCAPE + " Z:" + ESCAPE + str(boundBoxLZ      * uniteM) + ESCAPE + uniteMs + "\n"))
                f.write(iso8859("BoundBox Diagonal        :" + ESCAPE + str(boundBoxDiag * uniteM) + ESCAPE + uniteMs + "\n\n"))

                f.write(iso8859("Direction                :" + ESCAPE + str(directionObj) + "\n"))
                f.write(iso8859("ValueAt                  :" + ESCAPE + str(direcValueAt) + "\n\n"))

                f.write(iso8859("Matrix of inertia        :" + ESCAPE +  uniteMs+"^5") + "\n")
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(MatrixX1_16) + ESCAPE + " Y:" + ESCAPE + str(MatrixY1_16) + ESCAPE + " Z:" + ESCAPE + str(MatrixZ1_16) + ESCAPE + " :" + ESCAPE + str(Matrix_1) + "\n"))
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(MatrixX2_16) + ESCAPE + " Y:" + ESCAPE + str(MatrixY2_16) + ESCAPE + " Z:" + ESCAPE + str(MatrixZ2_16) + ESCAPE + " :" + ESCAPE + str(Matrix_2) + "\n"))
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(MatrixX3_16) + ESCAPE + " Y:" + ESCAPE + str(MatrixY3_16) + ESCAPE + " Z:" + ESCAPE + str(MatrixZ3_16) + ESCAPE + " :" + ESCAPE + str(Matrix_3) + "\n"))
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(Matrix12)    + ESCAPE + " Y:" + ESCAPE + str(Matrix13)    + ESCAPE + " Z:" + ESCAPE + str(Matrix14)    + ESCAPE + " :" + ESCAPE + str(Matrix15) + "\n\n"))

                f.write(iso8859("Matrix inertia with mass :" + ESCAPE + unitePs + uniteSs) + "\n")
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(MatrixX1_17) + ESCAPE + " Y:" + ESCAPE + str(MatrixY1_17) + ESCAPE + " Z:" + ESCAPE + str(MatrixZ1_17) + "\n"))
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(MatrixX2_17) + ESCAPE + " Y:" + ESCAPE + str(MatrixY2_17) + ESCAPE + " Z:" + ESCAPE + str(MatrixZ2_17) + "\n"))
                f.write(iso8859("                         :" + ESCAPE + " X:" + ESCAPE + str(MatrixX3_17) + ESCAPE + " Y:" + ESCAPE + str(MatrixY3_17) + ESCAPE + " Z:" + ESCAPE + str(MatrixZ3_17) + "\n\n"))

                f.write(iso8859("Matrix Determinant       :" + ESCAPE + str(DeterminantM) + "\n"))
                f.write(iso8859("Determinant decimal      :" + ESCAPE + str(decimal.Decimal(DeterminantM))+"\n\n"))
                f.close()
I posed my problem and am ready to clarify the incomprehensible points
I am waiting for your advice, it is useful for me
My respect
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: development of the recording of the macro fc info in xml format

Post by Kunda1 »

The code snippet is quite hard to read in the forum. Can you please add it to a github/gitlab repo as well and post a link to it?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Gandouzi Ghayth
Posts: 41
Joined: Wed May 13, 2020 2:45 am

Re: development of the recording of the macro fc info in xml format

Post by Gandouzi Ghayth »

Last edited by Kunda1 on Tue Jul 21, 2020 1:54 pm, edited 1 time in total.
Reason: removed wiki bbcode (that's just relevant to wiki.freecadweb.org wiki pages)
User avatar
hardeeprai
Posts: 177
Joined: Sun May 23, 2010 2:41 pm
Location: Ludhiana, Punjab, India
Contact:

Re: development of the recording of the macro fc info in xml format

Post by hardeeprai »

Gandouzi Ghayth wrote: Tue Jul 21, 2020 9:44 am my research project is to add to the Fc info macro the recording in xml format
and from my research on the forum I understood that it is not enough to add ".xml" at the end of the file for it to write XML.
You are right.

Gandouzi Ghayth wrote: Tue Jul 21, 2020 9:44 am
You have to modify all the lines that I gave previously to correctly format the text.
it is necessary to apply the modifications of the macro line fc info from 3689 to 3775

Code: Select all

try:
                f = open(SaveName, 'w') # write
  
  <snip>
  
                f.close()
I posed my problem and am ready to clarify the incomprehensible points
I am waiting for your advice, it is useful for me
Are you trying to record FreeCAD macro in xml format?
--
H.S.Rai
Gandouzi Ghayth
Posts: 41
Joined: Wed May 13, 2020 2:45 am

Re: development of the recording of the macro fc info in xml format

Post by Gandouzi Ghayth »

yes but i search about the form of the xml that can give the different data like volume,area,mass,inertia
the extraction with the xml form is very important on the system engineering.
User avatar
Sudhanshu
Posts: 357
Joined: Mon Oct 15, 2018 5:22 am

Re: development of the recording of the macro fc info in xml format

Post by Sudhanshu »

Gandouzi Ghayth wrote: Sat Jul 25, 2020 4:37 pm yes but i search about the form of the xml that can give the different data like volume,area,mass,inertia
the extraction with the xml form is very important on the system engineering.
From my experience, macros in FreeCAD are mostly used to generate a FreeCAD script which can replicate the model automatically.
Do you wish to do the same from an xml file? That is, a functionality where we can write the model in an xml file and later import it to get the model back?

Not sure if it will help you, but have you had a look at this: https://forum.freecadweb.org/viewtopic.php?t=40029
Gandouzi Ghayth
Posts: 41
Joined: Wed May 13, 2020 2:45 am

Re: development of the recording of the macro fc info in xml format

Post by Gandouzi Ghayth »

j'ai trouvez ici la structure mais qu'est ce que je peut mettre ici:"ici votre code pour le xml "?

Code: Select all

        SaveName = ""
#        SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file FCInfo", path, "*.FCInfo")   # PySide
        SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, u"Sauve le fichier FCInfo", path, "*.FCInfo *.csv *.asc *.txt;;FCInfo (*.FCInfo);;Csv (*.csv);;Ascii (*.asc);;TXT (*.txt);;XML (*.xml)")   # PySide
        print(SaveName,"  ", Filter)
        if SaveName == "":
            App.Console.PrintMessage(u"Processus abandonné"+"\n")
            errorDialog(u"Processus abandonné")
        else:
            if Filter == "XML (*.xml)":
		ici votre code pour le xml
            else:
            #décaler toute la section qui sauve à mon format 
            	try:
            	
            	except.....
Post Reply