Notice: Purchasing, Trials and Accounts Have Changed. What You Need To Know: Part II >>

Topic - select vert based on position? (python)

Page 1 of 2
   1  2  Next  Last 
if u know the (x,y,z), is it possible to select the vert at that location?
thnx!
i asked the exact same question a while ago...

unfortunately, i never looked any further

http://community.thefoundry.co.uk/discussion/topic.aspx?f=119&t=72679

Message edited by Keith. on 12/1/2013 - 3:48 PM

ya i knew it was a long shot....'d be nice to be able to do it at some point tho
may be 801 ; /
It's possible to do - although for dense meshes you'd be better off putting it into a command using the SDK.

You'd need to implement some kind of tolerance into the test, but the way to do it would be to have the script get the given position, run through all the verts in the mesh, grab their position and then, if the vert position is within a tiny amount of the given position, select it and return.



The SDK has a nicer way to do this, because it has built-in functions to grab the polygon nearest to a given 3D point then you can simply iterate over that polygon's verts to get the nearest one and select it.
Extract this to an lxserv folder in your Scripts directory;
http://www.farfarer.com/temp/selectAtPoint.zip

Then you can run the command
ffr.selectAt X Y Z TOLERANCE
and it will select the vertex at the position X Y Z on the current active layer.


TOLERANCE is an optional distance tolerance.

If you do not give a tolerance, it defaults to a tiiiny amount. Just small enough to account for floating point issues.

If you give it a value, it's a distance tolerance - so a value of W means "nearest vert to position X Y Z so long as it's within W metres of the position X Y Z".
So a value of 0.5 is 0.5m tolerance, 0.0001 is a tolerance of 0.0001m, etc...

If you give it a value and that value is less than zero, it will select the nearest vertex to the position X Y Z regardless of how far away the vertex is from that position.


If the command does not find a vertex within those specifications, it will not change the current vertex selection.

Message edited by Farfarer on 12/3/2013 - 4:09 AM

thanks farfarer for that .....

but foundry need to put in a simple command to select.vert X Y Z

iterating through all the verts can be a 'long' unnecessary process !

cheers !



Quote from Keith. : iterating through all the verts can be a 'long' unnecessary process !
Umm, no, iterating through all the verts is not only necessary, it's pretty much the only way to do it, regardless of whether you use a command or a script. The difference between a writing a command and a script is that a command has a tiny fraction of the overhead of a script while iterating the verts and will be considerably faster. You could gain some more performance by implementing Farfarer's python based command in C++ but the underlying process would be identical.

Message edited by GwynneR on 12/2/2013 - 9:07 AM

Quote from Keith. :
thanks farfarer for that .....

but foundry need to put in a simple command to select.vert X Y Z

iterating through all the verts can be a 'long' unnecessary process !

cheers !

If The Foundry wrote one, it would pretty much be what I just wrote there (except it'd be nicer, better code).

But position is an attribute (the defining attribute, even) of a vertex. So you have to iterate over all vertices and check their position attribute against the position you want to select.

There will be ways to make it faster (I wrote that script very quickly so it's probably not very efficient) but it won't change the fact you have to query all the vertices.
hi guys, i think we are not understanding each other.... it's the way it is now because we dont have the command to select a specific vert and a specific position... so you dont have a choice to iterate. today's reality !! so we have to go look for the vert before selecting it.

what I am stating is if we already know the position of vert XYZ , then we need a command to select vert XYZ without iterating.

it does not make sense to have to select a single vert (knowing it's position already) only by iterating because this becomes mesh size dependant and the larger the mesh ( or whatever - verts in world space), the longer it will take to find the vert....( if we had the proper command )

select.vert@position X Y Z - that's if you know the position. - this is what I mean.

cheers

Message edited by Keith. on 12/2/2013 - 10:43 AM

just to add to this... my current work around is I currently assign a selection set to that single vert. then select the select set.

so I would like to be able to get that vert without that workaround. and no iteration !!



Well, that can't be done.

Any command that was implemented to select a vertex by position would have to iterate over all of the vertices in the mesh. There are ways to help speed it up, but ultimately it has to be done via iteration.

It's just the way that 3D applications work. Vertices are not indexed via their position so there is no way to directly access them via position (and it's not practical or efficient to do so).
Quote from Farfarer :
Well, that can't be done.

Any command that was implemented to select a vertex by position would have to iterate over all of the vertices in the mesh. There are ways to help speed it up, but ultimately it has to be done via iteration.

It's just the way that 3D applications work. Vertices are not indexed via their position so there is no way to directly access them via position (and it's not practical or efficient to do so).


currently, that's how it is... unfortunately!!

and to state it's not practical or efficient... well that all depends on how each user wants to use that vert. it may be in the way you see it, but I see it otherwise.

Message edited by Keith. on 12/2/2013 - 11:01 AM

I don't mean for the user and their vertex, I mean for the entire 3D program.

To access by position, you'd have to use a 3 dimensional list with floats (or doubles) as keys to store your vertices. And if you moved any vertex, you wouldn't be able to access it again without knowing it's exact position (to several exact decimal places). And you wouldn't be able to have multiple vertices at the same position.

That's what I mean by it not being practical or efficient.



It is, essentially, not possible.

Message edited by Farfarer on 12/2/2013 - 11:08 AM

correct.. but it should be. -

if the vert moves, that's a completely different story, not what I am talking about.

I am talking about re-use of a vert that is created with code and doing whatever the code needs to do, then getting rid of that vert after the code is done.

in this case, you always know the position of that vert. thus able to select and deselect based on position...

and for example can create curves from that vert to another vert in world space because you created it and can select it now and then do whatever with it. Having such a command would eliminate many workarounds. ie avoid assigning selection sets, or having to create another mesh layer or avoid selecting other floating verts in the same mesh layer, etc etc... because position is known, and you just have to select it !!!

so, for now it's status quo !!!

Message edited by Keith. on 12/2/2013 - 11:21 AM

I think I'm completely lost as to what you want to achieve now :P
hehe.. oh well !!
nice ltl discussion goin on here ; /

Quote from Farfarer :
Extract this to an lxserv folder in your Scripts directory


thnx farfarer! where exactly is the lxserv folder on mac?

Message edited by ylaz on 12/2/2013 - 12:17 PM

If there isn't one, you can make one in your modo Scripts folder and put it in there.

Anything in an lxserv folder will tell modo to process it as a Python API plugin, rather than a regular script.
You can put an lxserv folder inside any valid (modo) imported folder and modo will find it and parse the contents, so either "user:Configs" or "user:Scripts" will do
i tried making a folder 'lxserv' inside scripts folder n ran the command, but
get an error 'unknown command'
edit: restarted modo, tried again, now it says 'failed'

Message edited by ylaz on 12/2/2013 - 12:28 PM

In case you didn't already, you'll need to restart modo - python files in lxserv folders are real plugins and have to be registered at startup.
tried that, now message 'failed'
Is it something like "not implemented" in the event log? You can ignore that, all Python API plugins do that.

If the script does nothing, it's because either;
There is no current active mesh layer.
The current active mesh layer has no vertices.
The script cannot find a vertex at the position given.
The script cannot find a vertex at the position given within the given tolerance.

I haven't set it to give specific errors, it'll just return early and do nothing.

Message edited by Farfarer on 12/2/2013 - 12:50 PM

Ahh, OK, the command is using the math module but it's not actually being imported. Edit the source python file and add "import math" at the top with the other imports eg:


#!/usr/bin/env python

import math
import lx
import lxifc
import lxu.command
import lxu.select


Then restart modo
trashed the old content in lxserv, added import math.
restarted modo.
if i run the command w arguments, modo crashes, if i run
the command itself, u get a popup. enter the xyz, then get 'failed'

Page 1 of 2
   1  2  Next  Last