0

I want to find a component of a 2D file with the attribute "TAG" equivalent to "F". To do it I'm trying to use the viewer.search function. More specifically I'm doing this call:

this.viewer.search('F', searchCallback, searchCallbackErr, 'TAG');

Of course, this is a test, so I am sure this object exist which this exact attributes, as you can see in this screenshot

Although, when the success callback function is called, the id array is empty. I noticed this happens for every other search process that involves a single character value. I also noticed that when I perform such a search the every value containing an 'F' in this case is highlighted in the properties window of the viewer (as you can also notice in the previous screenshot). Mind that the search for this same component works when I look for its other attribute "DESC3" which is equal to "L1".

What am I missing? Thank you in advance for your help! I've been stuck here for quite a while now.

Alex
  • 1
  • Sounds like a [g flag issue](https://stackoverflow.com/questions/1520800/why-does-a-regexp-with-global-flag-give-wrong-results) in the Forge Viewer's code. – Teemu Oct 29 '20 at 14:45

1 Answers1

3

If I watch your screenshot, it says TAG1, not TAG, could that be your issue? Anyway, one way to verify this is to select the object which has your attribute and run this code in the debugger

NOP_VIEWER.model.getBulkProperties(NOP_VIEWER.getSelection(), null, console.log)

Take a close look to the properties array, and note there is a displayName, and a attributeName - search is using the attributeName, but the interface will use the displayName. Once you identify the attributeName you want to do a search on, run this code. For my test, I am using this example

NOP_VIEWER.model.search("Yes", console.log, console.error, ["Show Title"])

For the last argument, note it can either be a string or an array of string. There is also a non documented argument (5th arg) that you use to tell if you want to search in hidden parameters or not (default is false).

NOP_VIEWER.model.search("Yes", console.log, console.error, ["Show Title"], { searchHidden: true })

And yes, you need more than one character for a search. For example

NOP_VIEWER.model.search("1", console.log, console.error)
returns []
NOP_VIEWER.model.search("4", console.log, console.error)
returns []

but
NOP_VIEWER.model.search("4'", console.log, console.error)
returns a list of objects
cyrille
  • 2,616
  • 1
  • 10
  • 18