How to use DistanceTo or GetDistance in C#?

How to use DistanceTo or GetDistance in C#?

sonny3g
Collaborator Collaborator
2,986 Views
8 Replies
Message 1 of 9

How to use DistanceTo or GetDistance in C#?

sonny3g
Collaborator
Collaborator
What I have to do is first determine a point at floor level.  Then a point at the top level followed by up to 7 more points located somewhere between the floor level and the top level.  I am able to create the collection of points okay, but I need to get two height variables for each point except the floor level point.

 So, I need to know the distance from the floor level point and the top level point, then from the floor level to the next selected point (the selected points may be  in random order - floor level, top level, level 3, level 4, level 2, level 1).  This makes up the first set of distances I need.

The second set of distances I need is the spread between each point.  So, in a 6 level drawing I need to know how far is the 1st level point from the floor point, then how far is the 2nd level point from the 1st level point and so on up the to top level. 

I can have anywhere from 2 levels to 8 levels to work with.  Also, all points are in a vertical line so their X value should all be the same. 

The final problem and why I have to figure out how to get DistanceTo to work is that orientation of the view will be below the X plane of the drawing so Y will be going from the largest negative number at floor level up the lowest negative number for the top level.  Or it could be a rotated view and UCS.

So far, I cannot get DistanceTo to work in C# nor can I get GetDistance to work.

Any suggestion will be greatly appreciated!

Modify message

 
Scott G. Sawdy
[email protected]
0 Likes
2,987 Views
8 Replies
Replies (8)
Message 2 of 9

ActivistInvestor
Mentor
Mentor

GetDistance() prompts the user to pick a point.

 

DistanceTo() is used to compute the distance from one point to another point (measured directly along the vector between them, as opposed to parallel to some coordinate system axis).

 

If you're having problems figuring out how to use GetDistance(), then post whatever code you have that isn't working, and also review the example code that's included in the documentation.

 

Lastly, no one reading your post knows precisely what your conditions are (a 2d drawing, a 3d model, etc.), so it's a bit difficult to offer contextual help, although I suspect that it's a 2D drawing where level elevations are the Y ordinate. In that case, you don't use DistanceTo(), you just subtract the Y ordinates of 2 points to calculate the difference in elevation, and the X ordinates are irrelevant.

 


@sonny3gwrote:
What I have to do is first determine a point at floor level.  Then a point at the top level followed by up to 7 more points located somewhere between the floor level and the top level.  I am able to create the collection of points okay, but I need to get two height variables for each point except the floor level point.

 So, I need to know the distance from the floor level point and the top level point, then from the floor level to the next selected point (the selected points may be  in random order - floor level, top level, level 3, level 4, level 2, level 1).  This makes up the first set of distances I need.

The second set of distances I need is the spread between each point.  So, in a 6 level drawing I need to know how far is the 1st level point from the floor point, then how far is the 2nd level point from the 1st level point and so on up the to top level. 

I can have anywhere from 2 levels to 8 levels to work with.  Also, all points are in a vertical line so their X value should all be the same. 

The final problem and why I have to figure out how to get DistanceTo to work is that orientation of the view will be below the X plane of the drawing so Y will be going from the largest negative number at floor level up the lowest negative number for the top level.  Or it could be a rotated view and UCS.

So far, I cannot get DistanceTo to work in C# nor can I get GetDistance to work.

Any suggestion will be greatly appreciated!

Modify message

 


 

0 Likes
Message 3 of 9

sonny3g
Collaborator
Collaborator

Thanks for taking a look at my post and responding.  Based on what you posted, it looks like I really want to use the DistanceTo() call.  I have been searching the web and documentation trying to get a clear picture of how it is supposed to work, but so far have not figured it out.

To get a little more into what I am trying to accomplish.  The attached image shows a support that is a dynamic block.  The users will pick the alignment point for the X parameter.  Then they will pick a the floor line to establish the Y basepoint and the top level support point for the max Y point.  The user will then be asked to pick a point on the remaining conveyors to establish each required support Y point.

There are a minimum number of crossmembers required dependant on the overall height of the support and no two supports can be more than 54" apart while the bottom support has a min/max from floor it can be moved.

Once I have all of the support points determined, I will cycle through to determine the spread between each crossmember for the max dim of 54".  There is a lot more calculations I need to make to determine exact placement of each crossmember based on other parameters like type of mounting required to attach to the conveyor.  That is another story.

Finally, once all the Y points are determined I insert my dynamic block and cycle through the crossmember height properties assigning the correct floor to Y point value to each.

So far, just trying to subtract one Y value from the previous is not giving me back reliable results.  Therefore I was hoping that using DistanceTo or GetDistance would provide more reliable results.

 

GetDistanceProblem.png

Scott G. Sawdy
[email protected]
0 Likes
Message 4 of 9

sonny3g
Collaborator
Collaborator

I figured out what I did wrong.  I needed to assign the value of each of my prompointresults to a point3d variable and then use it to get DistanceTo between my points.

Thanks for the help guys.

Scott G. Sawdy
[email protected]
0 Likes
Message 5 of 9

ActivistInvestor
Mentor
Mentor

I don't think you want to use DistanceTo() to get the distance between two points, because in your application it is only the difference between their Y ordinates that is important, and I would probably want to allow the user to pick a point without requiring it to have the same X-ordinate as the point you're computing the elevation from.

 


@sonny3gwrote:

I figured out what I did wrong.  I needed to assign the value of each of my prompointresults to a point3d variable and then use it to get DistanceTo between my points.

Thanks for the help guys.


 

0 Likes
Message 6 of 9

sonny3g
Collaborator
Collaborator

Actually, I need to make sure that the user is picking all points according to the original alignment point.  This is important to this application.  I will be using the perpendicular osnap setting to keep the users picks in line with the alignment point which in turn, is the center of the support. 

 

Relying on the Y value only can get me into trouble if the user has not created a new ucs and just plops down a stack at say a 15 degree angle with the floor parallel to the stack.  Then the distance between the Y values will not be accurate, nor with the X values.

 

Scott G. Sawdy
[email protected]
0 Likes
Message 7 of 9

ActivistInvestor
Mentor
Mentor

Relying on any form of osnap is also a bad idea, especially with PERpendicular and TANgent modes, because the result depends on the value of the LASTPOINT system variable.

 

You can use GetClosestPointTo() to compute a perpendicular point without having to rely on osnap for that.

 


@sonny3gwrote:

Actually, I need to make sure that the user is picking all points according to the original alignment point.  This is important to this application.  I will be using the perpendicular osnap setting to keep the users picks in line with the alignment point which in turn, is the center of the support. 

 

Relying on the Y value only can get me into trouble if the user has not created a new ucs and just plops down a stack at say a 15 degree angle with the floor parallel to the stack.  Then the distance between the Y values will not be accurate, nor with the X values.

 


 

0 Likes
Message 8 of 9

sonny3g
Collaborator
Collaborator

Unfortunately, I cannot use the GetClosestPointTo as it will increase the likely hood that the user will pick the wrong entity and the placement of the support is critical to selecting the correct support and spacers.  This support is later extracted from the drawing to import into the order system.  Being off by a little bit can change the which support is required and they are quite expensive to accidentally order the wrong one.

Scott G. Sawdy
[email protected]
0 Likes
Message 9 of 9

ActivistInvestor
Mentor
Mentor
@sonny3gwrote:

Unfortunately, I cannot use the GetClosestPointTo as it will increase the likely hood that the user will pick the wrong entity and the placement of the support is critical to selecting the correct support and spacers.  


Not really. You can validate the entity the user picks which is something you should be doing in the first place, and if it doesn't satisfy your requirements, display a message and ask them to pick another entity.

 

Also, from your previous post:

 

Relying on the Y value only can get me into trouble if the user has not created a new ucs and just plops down a stack at say a 15 degree angle with the floor parallel to the stack.  Then the distance between the Y values will not be accurate, nor with the X values.

You shouldn't be relying on the current UCS for anything. That's a user convenience. Your coordinates should be transformed to the WCS.

 

0 Likes