Macro WireXYZ: Difference between revisions

From FreeCAD Documentation
m (minor)
(Marked this version for translation)
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|Name=WireXYZ|Description=Creates a wire with coordinate x y z.|Author=Mario52|Version=0.1|Date=2016-09-06}}
|Name=WireXYZ
|Icon=Macro_WireXYZ.png
|Description=This macro creates a wire (or points) with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.<br/>{{ColoredText|(Command line, paste this complete macro in the Python console)}}.
|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=== <!--T:2-->
==Description== <!--T:2-->


<!--T:3-->
<!--T:3-->
This macro creates a wire (or points) with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.
This macro creates a wire (or points) with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.


===Use=== <!--T:4-->
==Usage== <!--T:4-->


<!--T:5-->
<!--T:5-->
The file must have three coordinates X Y Z in ascii format without header
The file must have three coordinates X Y Z in ascii format without header


===Script=== <!--T:11-->
==Script== <!--T:11-->
</translate>
</translate>


Macro_WireXYZ.FCMacro
ToolBar Icon [[Image:Macro_WireXYZ.png]]

<syntaxhighlight>
'''Macro_WireXYZ.FCMacro'''

{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# created a wire with coordinate x y z separated (in the file)
# 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:
#EX:
#0 0 0
#0 0 0
Line 26: Line 46:
#. . . .
#. . . .


from __future__ import unicode_literals
from FreeCAD import Base
from FreeCAD import Base
import Draft, Part
import Draft, Part


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

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


file = open(fichier, "r") # open the file read
file = open(fichier, "r") # open the file read
Line 38: Line 61:
for ligne in file:
for ligne in file:
coordinates = ligne.split()
coordinates = ligne.split()
X,Y,Z = coordinates # separate the coordinates
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)
# Draft.makePoint(float(X),float(Y),float(Z)) # create points (uncomment for use)
print X," ",Y," ",Z
print(X," ",Y," ",Z)
wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates
wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates

except Exception:
None
file.close()
file.close()
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
#Draft.makeWire(wire,closed=True,face=False,support=None) # create the wire closed (uncomment for use)
#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)
</syntaxhighlight>
#Draft.makeBSpline(wire,closed=True,face=False,support=None)# create the BSpline open (uncomment for use)

App.ActiveDocument.recompute()

}}

<translate>
<translate>

===Example===
==Example== <!--T:13-->
</translate>
</translate>

<code>
{{Code|code=
0 240.42686 0
0 240.42686 0


Line 65: Line 98:


...
...
}}
</code>
<translate>
<translate>
<!--T:14-->
Modify your path and name of file, save and load the macro and run.
Modify your path and name of file, save and load the macro and run.
</translate>
</translate>


{{Code|code=
<syntaxhighlight>
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

}}


<translate>
<translate>
<!--T:15-->
If you want a close wire modify this line (closed=False):
If you want a close wire modify this line (closed=False):
</translate>
</translate>


{{Code|code=
<syntaxhighlight>
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>


<translate>
<translate>


<!--T:16-->
and replace with (closed=True):
and replace with (closed=True):
</translate>
</translate>


{{Code|code=
<syntaxhighlight>
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>


<translate>
<translate>
<!--T:17-->
same for the face, False or True (face=True).
same for the face, False or True (face=True).




===Links===
==Links== <!--T:18-->
The discussion [http://forum.freecadweb.org/viewtopic.php?f=3&t=7828 How do I transform a point cloud to a line?]
The discussion [http://forum.freecadweb.org/viewtopic.php?f=3&t=7828 How do I transform a point cloud to a line?]

==Version== <!--T:19-->

<!--T:22-->
00.03 16/10/2020 : convert for Python 3, adding info for the path file "Windows" replace slatch "\" by "\\" or "/" see [https://forum.freecadweb.org/viewtopic.php?f=3&t=7828 How do I transform a point cloud to a line?]

<!--T:20-->
00.02 02/07/2019 :

<!--T:21-->
00.01 21/02/2015


</translate>
</translate>
<languages/>

Latest revision as of 09:53, 16 October 2020

Other languages:

WireXYZ

Description
This macro creates a wire (or points) with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.
(Command line, paste this complete macro in the Python console).

Macro version: 0.3
Last modified: 2020-10-16
FreeCAD version: All
Download: ToolBar Icon
Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
0.3
Date last modified
2020-10-16
FreeCAD Version(s)
All
Default shortcut
None
See also
Macro_Dxf_To_Shape

Description

This macro creates a wire (or points) with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.

Usage

The file must have three coordinates X Y Z in ascii format without header

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()


Example

0 240.42686 0

20 243.83054 0

40 247.33677 0

60 250.94702 0

80 254.66283 0

100 258.48575 0

...

Modify your path and name of file, save and load the macro and run.

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

If you want a close wire modify this line (closed=False):

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


and replace with (closed=True):

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

same for the face, False or True (face=True).


Links

The discussion How do I transform a point cloud to a line?

Version

00.03 16/10/2020 : convert for Python 3, adding info for the path file "Windows" replace slatch "\" by "\\" or "/" see How do I transform a point cloud to a line?

00.02 02/07/2019 :

00.01 21/02/2015