FreeCad cartesian coordinates

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
geraldhemel
Posts: 8
Joined: Wed Jul 03, 2013 8:35 am

FreeCad cartesian coordinates

Post by geraldhemel »

Hi all,

I'm a new member of this forum, and I was wondering if you guys can help me with the following problem.
I have a drwaning of a lens in a step file, and i would like to have the cartesian coordinates of the crosssection cut.
Preferably something like :
x=34. z=1.56443
x=33.99 z=1.5633
x=33.98 z=1.5600
x=33.97 z=1.5587

And so on untill the end/side of the lens is reached.
Is it possible to get these coordinates? Is this a common problem?
Can anybody give me an example how to write tis in Delpi?
I'm also new to this :roll:

Thank you :D
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: FreeCad cartesian coordinates

Post by yorik »

I'm not sure I understood clearly, what you want is to take a 2D curve, and get a series of points on that curve? You need to do that in python scripting, but it is totally possible. I give here an example, you'll need to adapt to your own situation. Let's say you have your object, and you already made a cutplane and placed it correctly (your cur plane must be larger than the object to cut) and already made a section of them, and that section object is called "MySection", and you want a point every 10 units:

Code: Select all

obj = FreeCAD.ActiveDocument.MySection
for edge in obj.Shape.Edges:
    numberOfPoints = int(edge.Length/10)
    intervals = range(0,numberOfPoints)
    intervals.append(edge.Length)
    for i in intervals:
        point = edge.valueAt(i*10)
        print "point at length "+ str(i) + " : x=" + str(point.x) + " y=" + str(point.y) + " z=" + str(point.z)
geraldhemel
Posts: 8
Joined: Wed Jul 03, 2013 8:35 am

Re: FreeCad cartesian coordinates

Post by geraldhemel »

Thank you for your help :D


Im realy a newbe, how do I make a cut ?
Maybe i'm making the right cut, but I get a error on line 1, But I cant read the error. Are you sure the code you give me is correct?
I have called the section "mysection" like you suggested. I have atached a screen of the problem.
Please Help :oops:
geraldhemel
Posts: 8
Joined: Wed Jul 03, 2013 8:35 am

Re: FreeCad cartesian coordinates

Post by geraldhemel »

Try agian to attache the pic of my screen.
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: FreeCad cartesian coordinates

Post by yorik »

if the line 1 gives an error it means there is no object called "MySection" in your document. Probably it has another name, you'd better not modify its default name and use that name in the script. Be careful that it is case-sensitive.
To make a cut you basically make one object to cut, then a plane that will act as a section plane, it must be bigger than the object to cut, then you select both and use the "Section" tool in the Part module...

Attaching images to the forum doesn't work at the moment (sourceforge did something wrong and never fixed), you need to host your images somewhere else and use a link, if you want to post images.
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: FreeCad cartesian coordinates

Post by NormandC »

Gerald,

Please explain why you posted here in "Open discussion (Open discussion about the future of FreeCAD)" instead of in "Help on using FreeCAD (This is the board to ask for help USING FreeCAD)".

This is a help request is it not?
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: FreeCad cartesian coordinates

Post by wmayer »

Here is a simple example:

Code: Select all

import Part
from FreeCAD import Base

c=Part.makeCylinder(2,10)
# slice accepts two arguments:
#+ the normal of the cross section plane
#+ the distance from the origin to the cross section plane. Here you have to find a value so that the plane intersects your object
s=c.slice(Base.Vector(0,1,0),0)
# here the result is a single wire
# depending on the source object this can be several wires
s=s[0]
# if you only need the vertexes of the shape you can use
v=[]
for i in s.Vertexes:
    v.append(i.Point)

# but you can also sub-sample the section to have a certain number of points (int) ...
p1=s.discretize(20)

# ... or define a sampling distance (float)
p2=s.discretize(0.5)
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: FreeCad cartesian coordinates

Post by yorik »

Yes, much better example, sorry, my explanations were a bit sparse...
geraldhemel
Posts: 8
Joined: Wed Jul 03, 2013 8:35 am

Re: FreeCad cartesian coordinates

Post by geraldhemel »

This is a help request, shall i move this thread to the help section?
Still after many weeks of practise I still can not export the cardesian coordinates ! :|
Now I know how to cut the part in half, I can select the curve I want exported, but I have no idea how to export this... please help me with this (for me) difficult problem ;-)
Here is a screenshot of the stepfile I would like to export the cardesian coordinates, the selected curve I would like to export.
http://www.freebits.nl/images/332cad.jpg

The only thing I need is the coordinates something like this

X24.896813 Z0.149248
X24.896438 Z0.149152
X24.895688 Z0.148959
X24.892688 Z0.148188
enz enz
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: FreeCad cartesian coordinates

Post by yorik »

Ok I'll adapt Werner's example to this case. The following code will give you 10 points from a selected edge. You can paste this code in a macro, so it's easy to reuse, or paste the code directly in the python window. Change the value of numberOfPoints if you want a different number or points:

Code: Select all

numberOfPoints = 10
selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0].copy()
points  = selectedEdge.discretize(numberOfPoints)
for p in points:
    print "X", p.x, " Y", p.y, " Z", p.z
Post Reply