Skip to content

Instantly share code, notes, and snippets.

@mario52a
Last active August 12, 2021 23:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mario52a/3ad4147f0ce25fa85b45 to your computer and use it in GitHub Desktop.
Save mario52a/3ad4147f0ce25fa85b45 to your computer and use it in GitHub Desktop.
This macro creates a wire (or points) with the coordinates extracted from a file. The coordinates X Y Z are separated by a space.
# -*- 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()
@mario52a
Copy link
Author

mario52a commented Jan 2, 2016

This macro utility is intended for the use of the program FreeCAD http://www.freecadweb.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment