-- List of input Elements (ARRAY of DBREF)
!refElements = ARRAY()
!refElements.append(/Element1 )
!refElements.append(/Element2 )
!refElements.append(/Element3 )
-- Loop on the list
Do !i index !refElements
-- Get the element of the iteration
!refElement = !refElements[!i]
-- Get the position of the element
!refElementPosition = !refElement.position.wrt(world)
--Collect all elements within the volume of !refElement + a margin of 500mm for example
VAR !withinElements COLLECT ALL WITHIN VOL $!refElement 500mm
-- Get position of each within element
!withinPos = ARRAY()
Do !withinElement values !withinElements
-- This step may vary if the element does not have a "position" attribute (you can use the center of its volume in this case, or skip)
!withinPos.append(!withinElement.dbref().position.wrt(world))
Enddo
-- Sort within elements according to their distance with reference element
!sortedDistanceIndices = !withinPos.evaluate(OBJECT BLOCK('!withinPos[!evalindex].distance(!refElementPosition)')).sortedIndices()
!withinElements.reindex(!sortedDistanceIndices)
-- Get number of within elements, or 'Find Nothing' if 0
!withinNumber = IFTRUE(!withinElements.empty(), 'Find Nothing', !withinElements.size())
-- Get fullname of nearest element, or 'Unset' if not found
!nearestElement = IFTRUE(!withinElements.empty(), 'Unset', !withinElements.first().dbref().fullname)
-- Debug
$p ---
$p $!refElement
$p $!withinNumber
$p $!nearestElement
Enddo
on your macro , can i get sequence of all nearest elements based on their distance? Presently its is giving only one nearest element.
for example, if we got 6 element in $!withinNumber, all element names should reflect based on their distance.
Hello Sgar,
Absolutely, in the macro the founded elements are already sorted, according to their distances, in the !withinElements variable.
In the example I use the first one, but you can just query the variable (q var !withinElements) to get the complete list.
If you want a readable format, you can also get the name of each of these elements and join all the names in one string, with space delimiter for example. At the level of the "Debug" part of my code:
!withinElementsString = !withinElements.evaluate(OBJECT BLOCK('!withinElements[!evalindex].dbref().fullname')).join(' ')
$p $!withinElementsString
Thanks and that's great working for me.
I have one more query -
VAR !withinElements COLLECT ALL WITHIN VOL $!refElement 500mm
on this above line, it was taking a long time to identify the elements within 500mm(maybe it is evaluating all components in this case).
where in my case I need to identify all the elements within 500mm from a particular zone.
which may take less time.
You can add the target like this:
VAR !withinElements COLLECT ALL WITHIN VOL $!refElement 500mm for /ZONE-NAME
You have examples of collections here if needed:
https://help.aveva.com/AVEVA_Everything3D/3.1/wwhelp/wwhimpl/js/html/wwhelp.htm#href=DBRM/DBRM11.html
ALL WITHIN means wholly within or wholly and part within?THX