vertexes coordinates

Need help, or want to share a macro? Post here!
Post Reply
lagunax
Posts: 39
Joined: Wed May 25, 2022 5:12 pm

vertexes coordinates

Post by lagunax »

hi
working with script and many times got some bad things:
in some types of objects there are vertexes/vectors of one type, that have members X Y and Z (capital).
But some other types have vertexes of another type and have members x y and z (not capital),

when difference will be fixed for one standard? it is to mach work added to work in one script with different types of objects.
edwilliams16
Veteran
Posts: 1370
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: vertexes coordinates

Post by edwilliams16 »

lagunax wrote: Sat Jun 25, 2022 2:02 pm hi
working with script and many times got some bad things:
in some types of objects there are vertexes/vectors of one type, that have members X Y and Z (capital).
But some other types have vertexes of another type and have members x y and z (not capital),

when difference will be fixed for one standard? it is to mach work added to work in one script with different types of objects.
Can you give examples of vertices of different types?

I have found that vertex.X gives the x-coordinate of the vertex's location and that vector.x is the x-component of a vector. They are quite different entities. Perhaps the notation is a reminder that vertex.X is only a getter, while vector.x is a getter and a setter.
lagunax
Posts: 39
Joined: Wed May 25, 2022 5:12 pm

Re: vertexes coordinates

Post by lagunax »

it is too long script allready, will try to show in shortest

Code: Select all

#in a loop i get face in this way
    for face1 in object1.Shape.Faces
      for face21 in object1.Shape.Faces

# next in another function i get intersection line with
    dts = face1.distToShape(face2)
    if dts[0] > 1e-7:
        return None
    else:
        return Part.makeLine(dts[1][0][0],dts[1][1][0])

# next in another function i get this for calculations
	result=face1.distToShape(edge)
	#where edge is returned line frome above Part.makeLine
	...
	cur_vertex=result[1][1][1]
	num_edge=result[2][1][1]
	cur_edge=face.Edges[num_edge]
	last_vertex=cur_edge.Vertexes[0]
	vertex1=Vector(cur_vertex.x,cur_vertex.y,cur_vertex.z)
	vertex2=Vector(last_vertex.X,last_vertex.Y,last_vertex.Z)
here in 'vertex1' and 'vertex2' used different case of letters. changing will make error.

this is not only one situation. and this is realy strange. i think tha no metter can you change it or not - it may be used in different ways and searching where to use on or another is a little hard way in big code. also if i have function that can get both types - how can i determine what one to use? determining will add unnessesary code to know what kind of coordinate to use.

in this case i see another one way of overloaded logic of FC. we have vector, we have vertex and etc, all of them have coordinates. if we can change one, why we can't change another? as result we got not unified representation of same parameters and overloaded code. imo
User avatar
Chris_G
Veteran
Posts: 2133
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: vertexes coordinates

Post by Chris_G »

You are facing the same comprehension problem again.
A Vertex is a topology entity upon a geometry Vector.
You can create a vector, wherever you want, and build a vertex on this support geometry :

Code: Select all

vec = FreeCAD.Vector(10, 20, 30)
vert = Part.Vertex(vec)
But you can't modify a vertex directly :

Code: Select all

vert.X = 15
# Traceback (most recent call last):
#  File "<input>", line 1, in <module>
# AttributeError: Attribute 'X' of object 'TopoShape' is read-only
This would move the vertex away from its geometry support entity. This is a nonsense.
lagunax
Posts: 39
Joined: Wed May 25, 2022 5:12 pm

Re: vertexes coordinates

Post by lagunax »

i do not need to modify them, because i make new object later in code.
but problem stands where i need to use different objects with same function. totaly i need to make different functions only for x|X-compatability. if all coordinates was x or all X then i need only one function.
in this case if i will make one function so i need to determine what kind of object i got in args - this is also hard way, becous objects like Vertex have no any ParametersList or Type methods to determine what kind of object i got.
in my script above there is an example of hardness of logic: i just need to get coordinates of vertexes of objects, but when i started work with code ii found that i need to know what kind of object and where i got - in this way i need to look all logic and find from where it can be gotten, also i need to know what object have x and what have X. etc...
finaly i spend mach more time on debugging and making copies of functions for another types of objects only because some have x and other have X.
also i do not need to create vector myself, in my script it will be looking like:
1) determine if gotten point is vector or not - to mach overload, because i need to know what kind of object i got (see above)
2) if it is not vector then get coordinate and make vector from them

it is sometimes hard to make scripts because of situations like this one. it adds realy unneeded work
User avatar
onekk
Veteran
Posts: 2788
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: vertexes coordinates

Post by onekk »

lagunax wrote: Sun Jun 26, 2022 11:59 am ....
it is sometimes hard to make scripts because of situations like this one. it adds realy unneeded work

To tell what @Chris_G has told you in a different way:

1) Vertex is a Topology concepts and is a TopoShape

if you type:

Code: Select all

vtx = Part.Vertex(FreeCAD.Vector(10,20,5))
print(vtx.TypeId)

you will see it will print

Code: Select all

Part::TopoShape
but if you do:

Code: Select all

vtx = Part.Vertex(FreeCAD.Vector(10,20,5))
pt = vtx.Point
print(pt)

you will see that it print:

Code: Select all

Vector (10.0, 20.0, 5.0)

and if you do:

Code: Select all

dir(FreeCAD.Vector)
you will se that at the end you will have x,y,z written with lowercase


They are different things.

It depends on what the method you are calling will return:

1) a Part.Vertex you have the properties of a Vertex Object so X,Y.Z so uppercase
2) a FreeCAD.Vector same as Base.Vector it has x,y,x properties (lowercase)

Probably some checks in the code will make the job, or just remember to test if the object is returned as an instance of Part.Vertex to simply take his .Point property that will return the Vector so you have always a x,y,z property to work on.


You could not change a Vertex assigning X,Y.,Z properties directly as they are not properties of the "Vertex" that is a TopoShape but are simply exposed taking them to the underlying geometry that is the Vector contained in the Point property of a Vertex
Topology entitiy

Hope I've been clear, if not I apologize


Regards

Carlo D.

EDIT: Sorry for multiple edits, but sometimes I see errors, only in the forum post as characters of the edit windows in my Browser are less readable.
My English and Italian Scripting Guide https://github.com/onekk/freecad-doc.
My Blog: https://onekk-maker.blogspot.com/

To help development see on GitHub Page

For enquiry about customized FC Scripting job PM me.
Post Reply