In my design file I have several (up to hundreds) of lines drawn. They are of the following data type: line, line string, block, complex chain, circle, arc, and bspline. I'm trying to write some VBA (my first attempt at using VBA in MicroStation) that will go through all of these lines and place a cell at a random point on these lines. The issue I'm stumped at is how to find the random point on any of these lines. I have the following code:
dim aLine as LineElement
Do While scanFile.MoveNext set aLine = scanFile.Current //The following code is what I'd like to be able to do // dim ranPoint as Point3d //set ranPoint.X = aLine.ranX //set ranPoint.Y = aLine.ranY //set ranPoint.Z = aLine.ranZ Loop
In the code above, ranX, ranY, and ranZ are imaginary properties of a LineElement that would give me my desired result. Any help would be appreciated
Thanks
alternate_exterior: In the code above, ranX, ranY, and ranZ are imaginary properties of a LineElement that would give me my desired result.
In the code above, ranX, ranY, and ranZ are imaginary properties of a LineElement that would give me my desired result.
Well, I usually ask anyone posting a question to post a code sample, but in your case, I don't have to: you already supplied some imaginary code!
Unsurprisingly, there isn't a 'random point' property of a LineElement, or any other element for that matter. What you could do is invoke the PointAtDistance method, which is a method of many linear and curved elements. The trick will be to scale the distance so it's smaller than the element's length. Something like this:
Dim oLine As LineElement ... get oLine from somewhere Dim distance As Double distance = (oLine.Length * Rnd (100, 0)) / 100 Dim point As Point3d point = oLine.PointAtDistance (distance)
Regards, Jon Summers LA Solutions
Brilliant, Jon!
Thanks. Works great. I had even already tinkered a bit with PointAtDistance but it seems I didn't quite understand it well enough. I made one change to your code, however, a very minor issue which may be due to the VBA version we're each using.
distance = ( oLine.Length * Rnd(100, 0)) / 100
Because of a "wrong number of arguments" error I had to change it to:
distance = ( oLine.Length * (Rnd() * 100)) / 100
Thanks again!
mwrbentley:You need to call the Randomize function before RND to get a random string of values for each time you use RND.
Randomize is better only once at the beginning of macro. Do not use it before every call to RND, because it can make the same results every time. The correct name of that function should be ResetTimerForRandomizer, because it just do that...