Macro WireXYZ/fr: Difference between revisions

From FreeCAD Documentation
mNo edit summary
(Created page with "00.03 16/10/2020 : conversion pour Python 3, ajout d'info pour le chemin du fichier dans "Windows" remplacer le slatch "\" par "\\" ou "/" voir [https://forum.freecadweb.org...")
 
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
{{Macro/fr|Icon=Text-x-python|Name=WireXYZ|Name/fr=WireXYZ|Description=Crée un wire avec les coordonnées x y z. d'un fichier|Author=Mario52|Version=0.1}}
{{Macro/fr
|Name=WireXYZ
|Icon=Macro_WireXYZ.png
|Description=Crée un wire avec les coordonnées x y z séparées par un espace. Les données sont extraites d'un fichier.<br/>{{ColoredText|(Ligne de commande, collez cette macro complète dans la console Python)}}.
|Author=Mario52
|Version=0.3
|Date=2020-10-16
|FCVersion=All
|SeeAlso=[[Macro_Dxf_To_Shape|Macro_Dxf_To_Shape]] [[Image:Macro_Dxf_To_Shape.png|24px]]
|Download=[https://www.freecadweb.org/wiki/images/0/0a/Macro_WireXYZ.png ToolBar Icon]
}}


===Description===
==Description==


Cette macro crée un wire (ou points) avec les coordonnées XYZ extraites d'un fichier.
Cette macro crée un wire (ou points) avec les coordonnées XYZ extraites d'un fichier.
Les coordonnées X Y Z sont séparées par un espace.
Les coordonnées X Y Z sont séparées par un espace.


===Utilisation===
==Utilisation==


Le fichier doit avoir les coordonnées X Y Z au ASCII sans entête.
Le fichier doit avoir les coordonnées X Y Z au ASCII sans entête.


==Script==
'''EX:'''


ToolBar Icon [[Image:Macro_WireXYZ.png]]
<code>

'''Macro_WireXYZ.FCMacro'''

{{MacroCode|code=
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# created a wire with coordinate x y z separated (in the file without coma)
__title__= "Macro_WireXYZ"
__author__= "Mario52"
__date__= "2020/10/16"
__version__= "00.03"
##
#EX:
#0 0 0
#10 10 10
#15 20 25
#. . . .

from FreeCAD import Base
import Draft, Part

## path for Windows : C:\yourPath\cloud.asc (create one error in Python (cause, the "\" is a command syntax in Python)
## replace "\" by "/" result : C:/yourPath/cloud.asc
## or replace the "\" by "\\" result : C:\\yourPath\\cloud.asc

fichier = "C:\\yourPath\\cloud.asc" # path and name of file.txt

file = open(fichier, "r") # open the file read
wire = []
X=Y=Z = 0.0

for ligne in file:
coordinates = ligne.split()
try: # for format PCD ignore the header
X,Y,Z = coordinates # separate the coordinates
# Draft.makePoint(float(X),float(Y),float(Z)) # create points (uncomment for use)
print(X," ",Y," ",Z)
wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates
except Exception:
None
file.close()
Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open
#Draft.makeWire(wire,closed=True,face=False,support=None) # create the wire closed (uncomment for use)

#Draft.makeBSpline(wire,closed=False,face=False,support=None)# create the BSpline open (uncomment for use)
#Draft.makeBSpline(wire,closed=True,face=False,support=None)# create the BSpline open (uncomment for use)

App.ActiveDocument.recompute()

}}


== Exemples ==

{{Code|code=
0 240.42686 0
0 240.42686 0


Line 26: Line 92:


...
...
}}
</code>

Modifiez le chemin et nom du fichier, sauvez la macro, rechargez la macro et lancez la.
Modifiez le chemin et nom du fichier, sauvez la macro, rechargez la macro et lancez la.

<syntaxhighlight>
{{Code|code=
fichier = "C:\yourPath\cloud.asc" # path and name of file.txt
fichier = "C:\yourPath\cloud.asc" # path and name of file.txt

</syntaxhighlight>
## path for Windows : C:\yourPath\cloud.asc (create one error in Python (cause, the "\" is a command syntax in Python)
## replace "\" by "/" result : C:/yourPath/cloud.asc
## or replace the "\" by "\\" result : C:\\yourPath\\cloud.asc

}}

Si vous voulez un wire fermé, modifiez le code (closed=False):
Si vous voulez un wire fermé, modifiez le code (closed=False):

<syntaxhighlight>
{{Code|code=
Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open
Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open
}}
</syntaxhighlight>


et remplacez le par (closed=True)
et remplacez le par (closed=True)

<syntaxhighlight>
{{Code|code=
Draft.makeWire(wire,closed=True,face=False,support=None) # create the wire closed
Draft.makeWire(wire,closed=True,face=False,support=None) # create the wire closed
}}
</syntaxhighlight>

même procédure pour la face, False ou True (face=True).
même procédure pour la face, False ou True (face=True).


===Script===
Macro_WireXYZ.FCMacro
<syntaxhighlight>
# -*- coding: utf-8 -*-
# created a wire with coordinate x y z unseparated (in the file)
#EX:
#0 0 0
#10 10 10
#15 20 25
#. . . .


==Liens==
from __future__ import unicode_literals
La discussion sur le forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=7828 How do I transform a point cloud to a line?]
from FreeCAD import Base
import Draft, Part


==Version==
fichier = "C:\yourPath\cloud.asc" # path and name of file.txt


00.03 16/10/2020 : conversion pour Python 3, ajout d'info pour le chemin du fichier dans "Windows" remplacer le slatch "\" par "\\" ou "/" voir [https://forum.freecadweb.org/viewtopic.php?f=3&t=7828 How do I transform a point cloud to a line?]
file = open(fichier, "r") # open the file read
wire = []
X=Y=Z = 0.0


00.02 02/07/2019 :
for ligne in file:
coordinates = ligne.split()
X,Y,Z = coordinates # separate the coordinates
# Draft.makePoint(float(X),float(Y),float(Z)) # create points (uncomment for use)
print X," ",Y," ",Z
wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates


00.01 21/02/2015
file.close()
Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open
#Draft.makeWire(wire,closed=True,face=False,support=None) # create the wire closed (uncomment for use)

</syntaxhighlight>

===Liens===
La discussion sur le forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=7828 How do I transform a point cloud to a line?]
{{clear}}
<languages/>

Latest revision as of 10:28, 16 October 2020

Other languages:

WireXYZ

Description
Crée un wire avec les coordonnées x y z séparées par un espace. Les données sont extraites d'un fichier.
(Ligne de commande, collez cette macro complète dans la console Python).

Version macro : 0.3
Date dernière modification : 2020-10-16
Version FreeCAD : All
Téléchargement : ToolBar Icon
Auteur: Mario52
Auteur
Mario52
Téléchargement
ToolBar Icon
Liens
Version Macro
0.3
Dernière modification
2020-10-16
Version(s) FreeCAD
All
Raccourci clavier
None
Voir aussi
Macro_Dxf_To_Shape

Description

Cette macro crée un wire (ou points) avec les coordonnées XYZ extraites d'un fichier. Les coordonnées X Y Z sont séparées par un espace.

Utilisation

Le fichier doit avoir les coordonnées X Y Z au ASCII sans entête.

Script

ToolBar Icon

Macro_WireXYZ.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# created a wire with coordinate x y z separated (in the file without coma)
__title__= "Macro_WireXYZ"
__author__= "Mario52"
__date__= "2020/10/16"
__version__= "00.03"
##
#EX:
#0 0 0
#10 10 10
#15 20 25
#. . . .

from FreeCAD import Base
import Draft, Part

## path for Windows    : C:\yourPath\cloud.asc (create one error in Python (cause, the "\" is a command syntax in Python)
## replace "\" by "/"  result : C:/yourPath/cloud.asc 
## or replace the "\" by "\\" result : C:\\yourPath\\cloud.asc 

fichier = "C:\\yourPath\\cloud.asc"                          # path and name of file.txt

file = open(fichier, "r")                                  # open the file read
wire = []
X=Y=Z = 0.0

for ligne in file:
    coordinates = ligne.split()
    try:                                                        # for format PCD ignore the header
        X,Y,Z = coordinates                                     # separate the coordinates
#        Draft.makePoint(float(X),float(Y),float(Z))            # create points (uncomment for use)
        print(X," ",Y," ",Z)
        wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates
    except Exception:
        None
file.close()
Draft.makeWire(wire,closed=False,face=False,support=None)   # create the wire open
#Draft.makeWire(wire,closed=True,face=False,support=None)   # create the wire closed (uncomment for use)

#Draft.makeBSpline(wire,closed=False,face=False,support=None)# create the BSpline open (uncomment for use)
#Draft.makeBSpline(wire,closed=True,face=False,support=None)# create the BSpline open (uncomment for use)

App.ActiveDocument.recompute()


Exemples

0 240.42686 0

20 243.83054 0

40 247.33677 0

60 250.94702 0

80 254.66283 0

100 258.48575 0

...

Modifiez le chemin et nom du fichier, sauvez la macro, rechargez la macro et lancez la.

fichier = "C:\yourPath\cloud.asc"                          # path and name of file.txt

## path for Windows    : C:\yourPath\cloud.asc (create one error in Python (cause, the "\" is a command syntax in Python)
## replace "\" by "/"  result : C:/yourPath/cloud.asc 
## or replace the "\" by "\\" result : C:\\yourPath\\cloud.asc

Si vous voulez un wire fermé, modifiez le code (closed=False):

Draft.makeWire(wire,closed=False,face=False,support=None)   # create the wire open


et remplacez le par (closed=True)

Draft.makeWire(wire,closed=True,face=False,support=None)   # create the wire closed

même procédure pour la face, False ou True (face=True).


Liens

La discussion sur le forum How do I transform a point cloud to a line?

Version

00.03 16/10/2020 : conversion pour Python 3, ajout d'info pour le chemin du fichier dans "Windows" remplacer le slatch "\" par "\\" ou "/" voir How do I transform a point cloud to a line?

00.02 02/07/2019 :

00.01 21/02/2015