# Point group pattern in "nearpoints" VEX function ...

## Recommended Posts

Hello –

after quite a bit of searching and a pretty long struggle I've decided to post my simple question concerning the "nearpoints" function (http://www.sidefx.com/docs/houdini15.5/vex/functions/nearpoints) that I am using on a Point Wrangle SOP.

The manual states that, under "ptgroup", one can specify a "point group pattern to limit the search to":

int [] nearpoints(string geometry, string ptgroup, vector pt, float maxdist)

While inputting a simple pattern like "0 11 18" works (limiting the "nearpoints" function to these points like it's supposed to), I can't get it to work when I put in the sample expression "@Cd.x>0.5". Has anyone ever used the "ptgroup" argument with an expression, because all the examples I found always only used GEOHANDLE + POSITION + MAXDIST with an optional MAXPTS at the end?

Here's the code on the Point Wrangle SOP that works:

int nearest[] = nearpoints(0, "0 11 18", @P, 1);
i@found = len(nearest);
i@first = nearest[1];

This one doesn't, giving me a wrong result and a green "implicit cast from vector to float" error:

int nearest[] = nearpoints(0, @Cd<1.0, @P, 1);
i@found = len(nearest);
i@first = nearest[1];

I am afraid it is a very beginner's mistake, so I am grateful for any answers! Thanks,

Bastian.

It should be:

"Cd<1.0"

##### Share on other sites

One workaround I found is to create detail string attribute called for example "at" with value set to "@";

Then in wrangle node you can use detail(0,"at") to return @ as string without messing with the attributes.

```string grp = detail(0,"at")+"Cd<1.0";
int nearest[] = nearpoints(0, grp, @P, 1); ```

I usually use it to check for closest pieces different from current one:

```string grp = detail(0,"at")+"name!="+s@name;
int near = nearpoint(0,grp,v@P);```

If it works without @, like Yunus said, then silly me D:

Edited by rayman

##### Share on other sites

Thanks to both of you! Due to the time difference I could only now check your answers.

Yunus, as suggested, I simply omitted the "@" and put the expression in quotation marks:

```int nearest[] = nearpoints(0, "Cd.x<1.0", v@P, 1);
i@found = len(nearest);
i@first = nearest[1];```

While I don't get an error, this doesn't yield any result either. I attached a screenshot to illustrate the setup.

##### Share on other sites

Same result with your proposed solution, Pavel – no error, but not the intended result:

```string ptgroup = detail(0,"at")+"Cd.x<1.0";
int nearest[] = nearpoints(0, ptgroup, v@P, 1);
i@found = len(nearest);
i@first = nearest[1];```

Added the screenshot as well. Shouldn't there now also be a detail attribute on the geometry (lower pane), or am I missing something?

##### Share on other sites

I am also wondering if it's the smartest way of filtering the result? Of course, another option would be to get all the nearest points and filter afterwards.

But I thought since the manual explicitly states the option to do so, it would be a really smart and efficient way to do it:

int [] nearpoints(string geometry, string ptgroup, vector pt, float maxdist)

`ptgroup`: A point group pattern to limit the search to. Can be a SOP-style group pattern such as `0-10` or`@Cd.x>0.5`. An empty string will match all points.

##### Share on other sites

Try unicode representation of the @ character: "\x40Cd.x<1.0".

Snippet parser substitutes any "@" character with string "_bound_", it does not check if the symbol resides inside string. If you dive inside asset you may see this string by looking inside Attribute VOP's generated VEX code: "_bound_Cd.x<1.0". That's why Pavel's method works: expression passed to the compiler unchanged. You should have created detail attribute using Attribute Create node.

BTW, the very first element in an array is [0], not [1]. Of course, if you don't usually call it "zeroth element".

Edited by f1480187
• 2

##### Share on other sites

Sorry for not reporting back sooner ... I masked the "@" character, as F1 suggested, and it worked perfectly! Thanks to everyone for their help!

Added the screenshot for future reference ...

##### Share on other sites

interesting, since the help suggests using `@Cd.x>0.5`
is this just an error in the docs?

Edited by 3dome

##### Share on other sites

Exactly this was driving me crazy. The help fails to mention that the "@" character must be masked, as suggested by F1 ...

##### Share on other sites

Since it was originally my goal to limit the nearpoints() function to an exisiting point group, it might be worth to mention that Moritz pointed out to me how that is done successfully (see screenshot for this). Note that activeGroup is the name of the existing point group ...

Edited by bjs

##### Share on other sites

Is this fixed now?

##### Share on other sites
3 hours ago, Elon said:

Is this fixed now?

it should work fine

##### Share on other sites
On 8/1/2016 at 9:24 PM, bjs said:

Hello –

after quite a bit of searching and a pretty long struggle I've decided to post my simple question concerning the "nearpoints" function (http://www.sidefx.com/docs/houdini15.5/vex/functions/nearpoints) that I am using on a Point Wrangle SOP.

The manual states that, under "ptgroup", one can specify a "point group pattern to limit the search to":

int [] nearpoints(string geometry, string ptgroup, vector pt, float maxdist)

While inputting a simple pattern like "0 11 18" works (limiting the "nearpoints" function to these points like it's supposed to), I can't get it to work when I put in the sample expression "@Cd.x>0.5". Has anyone ever used the "ptgroup" argument with an expression, because all the examples I found always only used GEOHANDLE + POSITION + MAXDIST with an optional MAXPTS at the end?

Here's the code on the Point Wrangle SOP that works:

int nearest[] = nearpoints(0, "0 11 18", @P, 1);
i@found = len(nearest);
i@first = nearest[1];

This one doesn't, giving me a wrong result and a green "implicit cast from vector to float" error:

int nearest[] = nearpoints(0, @Cd<1.0, @P, 1);
i@found = len(nearest);
i@first = nearest[1];

I am afraid it is a very beginner's mistake, so I am grateful for any answers! Thanks,

Bastian.

I know its an old post but for those who still face the same problem here is what works for me. Simply write the expression without spaces as if it was written on a SOP node.

i[]@pts;

pts = nearpoints(0, "@Cd.x>0.8", @P,20);

Hope this helps others

Edited by haroon alhitary

## Create an account

Register a new account