{"id":936,"date":"2016-03-07T10:00:00","date_gmt":"2016-03-07T08:00:00","guid":{"rendered":"https:\/\/blogs.autodesk.com\/villagebim\/2016\/03\/exemple-dynamo-lire-un-fichier-xml.html"},"modified":"2021-02-09T22:03:24","modified_gmt":"2021-02-09T20:03:24","slug":"exemple-dynamo-lire-un-fichier-xml","status":"publish","type":"post","link":"https:\/\/blogs.autodesk.com\/villagebim\/2016\/03\/exemple-dynamo-lire-un-fichier-xml.html","title":{"rendered":"Exemple Dynamo : lire un fichier XML"},"content":{"rendered":"<p style=\"text-align: justify\">Le fichier XML (eXtensible Markup Language) est un fichier texte particulier qui permet de stocker des informations en respectant une structure donn\u00e9e. Ce type de fichier permet d\u2019\u00e9changer des informations entre diverses applications.<\/p>\n<p style=\"text-align: justify\">A ce titre, je vous propose de lire et d\u2019utiliser les informations contenues dans un fichier au format XML \u00e0 partir de Dynamo For Revit.<\/p>\n<p style=\"text-align: justify\">Voici le fichier au format XML que j\u2019ai cr\u00e9e :<\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01bb08b78bfb970d-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"822\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea8d1ea41.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\">Nota : fichier disponible en fin de document.<\/p>\n<p style=\"text-align: justify\">Comme vous pouvez le voir, ce format r\u00e9pond \u00e0 une syntaxe et un balisage pr\u00e9cis.<\/p>\n<p style=\"text-align: justify\">Pour plus de renseignements, le lecteur pourra se rendre \u00e0 <a href=\"https:\/\/fr.wikipedia.org\/wiki\/Extensible_Markup_Language\">cette adresse<\/a>.<\/p>\n<p style=\"text-align: justify\">Le but sera d\u2019\u00e9crire certaines donn\u00e9es dans les commentaires d\u2019un objet s\u00e9lectionn\u00e9 dans Revit.<\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\"><strong><u>1- Import du fichier au format XML dans Dynamo :<\/u><\/strong><\/p>\n<p style=\"text-align: justify\">&#160;&#160;&#160;&#160;C\u2019est tr\u00e8s simple, il suffit d\u2019utiliser deux n\u0153uds:<\/p>\n<blockquote>\n<p>&#8211; \u201c<em><strong>File Path<\/strong><\/em>\u201d : permet d\u2019indiquer le chemin o\u00f9 se trouve le fichier au format SAT,<\/p>\n<p>&#8211; \u201c<em><strong>File.ReadText<\/strong>\u201d<\/em> : lit le fichier et le transforme en ligne de caract\u00e8re.<\/p>\n<p>&#160;<\/p>\n<\/blockquote>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01b8d19ce59a970c-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"347\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea8eb5ca5.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\"><strong><u>2- Extraire des donn\u00e9es :<\/u><\/strong><\/p>\n<p style=\"text-align: justify\">&#160;&#160;&#160;&#160;Pour extraire les donn\u00e9es issues du fichier, je vais utiliser un package qui s\u2019intitule \u201c<em>LunchBox for Dynamo<\/em>\u201d que vous pouvez t\u00e9l\u00e9charger dans l\u2019interface de Dynamo dans le menu \u201c<strong><em>Packages\\ Rechercher un package\u2026\u201d<\/em><\/strong><\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01bb08b78c22970d-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"263\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea9167152.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p>Je vais utiliser le n\u0153ud \u201c<strong><em>DataSets.DeserializeXML<\/em><\/strong>\u201d qui extrait les donn\u00e9es du fichier XML et affiche le nom des variables ainsi que leurs valeurs.<\/p>\n<p>&#160;<\/p>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01b7c812c530970b-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"296\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea934c61f.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\">A la lecture de la structuration des donn\u00e9es, je vais extraire par exemple les informations concernant le premier mur.<\/p>\n<p style=\"text-align: justify\">Cr\u00e9er un \u201c<em><strong>Codeblock<\/strong><\/em>\u201d (double click sur l\u2019interface Dynamo)&#160;me permet d&#039;extraire des donn\u00e9es d\u2019une liste ou sous liste, voici la structure \u201cVariable[Indice1][Indice2]&#8230;\u201d. D\u2019o\u00f9 le r\u00e9sultat ci-dessous:<\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01b8d19ce7ab970c-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"343\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea9558a30.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\">Concernant la liste &quot;n\u0153ud&quot;, il y a une donn\u00e9e en trop&#160; : \u201c<em>Murs<\/em>\u201d. Nous allons la supprimer dans le liste en utilisant \u201c<strong><em>List.RestOfItem<\/em>s<\/strong>\u201d.<\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\"><strong><u>3- Mise en forme :<\/u><\/strong><\/p>\n<p style=\"text-align: justify\">Une fois extraites les donn\u00e9es voulues, nous allons les mettre en forme.<\/p>\n<p style=\"text-align: justify\">Nous allons :<\/p>\n<blockquote>\n<p>&#8211; fusionner les deux listes en une en utilisant le n\u0153ud &#039;\u201d<em><strong>List.create<\/strong><\/em>\u201d,<\/p>\n<p>&#8211; organiser la liste avec le n\u0153ud \u201c<strong><em>Transpose<\/em><\/strong>\u201d,<\/p>\n<p>&#8211; s\u00e9parer les valeurs et les donn\u00e9es par un s\u00e9parateur \u00e0 l\u2019aide du n\u0153ud \u201c<strong><em>String.Join<\/em><\/strong>\u201d,<\/p>\n<p>&#8211; transformer la liste en cha\u00eene de caract\u00e8res avec le n\u0153ud \u201c<strong><em>String from Arra<\/em><\/strong>y\u201d<\/p>\n<p>&#160;<\/p>\n<\/blockquote>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01b8d19ce7c9970c-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"225\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea973f675.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p style=\"text-align: justify\">&#160;<\/p>\n<p style=\"text-align: justify\"><strong><u>4- Stocker les donn\u00e9es dans les commentaires d\u2019un objet:<\/u><\/strong><\/p>\n<p style=\"text-align: justify\">Pour faire simple, nous allons stocker les donn\u00e9es r\u00e9colt\u00e9es dans les commentaires d\u2019un objet s\u00e9lectionn\u00e9 de Revit.<\/p>\n<blockquote>\n<p>&#8211; utiliser le n\u0153ud \u201c <strong><em>Select Model Element<\/em><\/strong>\u201d et cliquer sur l\u2019\u00e9l\u00e9ment dans l\u2019interface Revit (par exemple un mur),<\/p>\n<p>&#8211; cr\u00e9er un n\u0153ud \u201c<strong><em>String<\/em><\/strong>\u201d, en introduisant le texte \u201c<em>Commentaires<\/em>\u201d,<\/p>\n<p>&#8211; envoyer les donn\u00e9es vers l\u2019objet s\u00e9lectionn\u00e9 : \u201c<strong><em>Element.SetParameterByName<\/em><\/strong>\u201d,<\/p>\n<p>&#160;<\/p>\n<\/blockquote>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01b7c812c6c5970b-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"175\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea98ef836.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p><strong><u>Voici le r\u00e9sultat dans Revit :<\/u><\/strong><\/p>\n<p>&#160;<\/p>\n<p><a href=\"http:\/\/villagebim.typepad.com\/.a\/6a015391e15a28970b01b7c812c6d6970b-pi\"><img loading=\"lazy\" decoding=\"async\" alt=\"image\" border=\"0\" height=\"383\" src=\"https:\/\/blogs.autodesk.com\/villagebim\/wp-content\/uploads\/sites\/154\/2021\/02\/img_6022ea9a6af70.png\" style=\"padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px;margin-left: auto;margin-right: auto;background-image: none\" title=\"image\" width=\"454\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p>T\u00e9l\u00e9chargement :<\/p>\n<p>&#160; &#160; &#8211; <span class=\"asset  asset-generic at-xid-6a015391e15a28970b01bb08b79e32970d img-responsive\"><a href=\"http:\/\/villagebim.typepad.com\/files\/donn%C3%A9es.xml\">Fichier XML&#160;<\/a><\/span><\/p>\n<p>&#160; &#160; &#8211; <span class=\"asset  asset-generic at-xid-6a015391e15a28970b01b8d19cf606970c img-responsive\"><a href=\"http:\/\/villagebim.typepad.com\/files\/lire-xmlblogf.dyn\">Fichier Dynamo<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Le fichier XML (eXtensible Markup Language) est un fichier texte particulier qui permet de stocker des informations en respectant une structure donn\u00e9e. Ce type de fichier permet d\u2019\u00e9changer des informations entre diverses applications. A ce titre, je vous propose de lire et d\u2019utiliser les informations contenues dans un fichier au format XML \u00e0 partir de [&hellip;]<\/p>\n","protected":false},"author":4760,"featured_media":2472,"menu_order":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[15,28,17,6],"tags":[13,20,865,1373,21],"class_list":["post-936","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-autodesk-revit","category-gestion-de-donnees","category-nouveautes","category-trucs-et-astuces","tag-autocad","tag-autodesk","tag-exemple-dynamo","tag-fichier-xml","tag-revit","dhig-theme--light"],"acf":[],"_links":{"self":[{"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/users\/4760"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":0,"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/media\/2472"}],"wp:attachment":[{"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.autodesk.com\/villagebim\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}