# pcloud en external data

## Recommended Posts

I'm learning procedural modeling, I'm trying to find nearest points from a sphere with this

```@Cd=0;

// point d'origine
int origin=chi("Origin");

// Distance séparant les points
float distance=ch("Distance");

// nombre de points à retourner
int amount=chi("Amount");

int target;

// retourne la position du point d'origine
vector pos=point(1,"P",origin);
printf("pos: %d\n",pos);

// stocke les positions des "amount "points à une distance de "distance"
int pcloud=pcopen(0,"P",pos,distance,amount);

if(pcnumfound(pcloud)>0){
while(pciterate(pcloud)){
// stocke le numéro du point dans target par référence
pcimport(pcloud,"point.number",target);
setpointattrib(0,"Cd",target,{1,0,0},"set");
}
}```

and the vector pos is always 0,0,0 even if a sphere is plugged in 1 ?

I' ve found this example on youtube and it works ?

Edited by davidyannick
error

##### Share on other sites

It took me quite a while to understand what is happening there  looks like very overcomplicated code for a simple task.

vector pos is returning 0 as in code:

vector pos=point(1,"P",origin);

You are asking for P (position) from input 1 (your sphere) of the point number "origin" which in your case is "115" in hip you sent.

Your sphere has only 1 point (number 0). There is no point number "115" therefore it fails and returns {0,0,0}.

ps. You don't need to export output to terminal to debug this (using printf), you can just export global variable and have live output of your work in "geometry spreadsheet" @test = pos;

SideFX help file is very extensive and worth reading! Better than getting wrong ideas from youtube and potentially inexperienced people

Edited by tmdag
• 1

##### Share on other sites
1 minute ago, tmdag said:

It took me quite a while to understand what is happening there  looks like very overcomplicated code for a simple task.

vector pos is returning 0 as in code:

vector pos=point(1,"P",origin);

You are asking for P (position) from input 1 (your sphere) of the point number "origin" which in your case is "115" in hip you sent.

Your sphere has only 1 point (number 0). There is no point number "115" therefore it fails and returns {0,0,0}.

ps. You don't need to export output to terminal to debug this (using printf), you can just export global variable and have live output of your work in "geometry spreadsheet"

Shame on me I didn't see it ..

Thank you for your help next time I'll pay more attention

##### Share on other sites
1 hour ago, fsimerey said:

There is a VEX function to find the closest point > https://www.sidefx.com/docs/houdini/vex/functions/nearpoint.html

And for a list of the all the closest points in a geometry https://www.sidefx.com/docs/houdini/vex/functions/nearpoints.html

Thanks

## Create an account

Register a new account