Highlighting Text When a Part is Selected in the Forge Viewer - autodesk-forge

Currently, I have successfully been able to isolate and highlight parts or assemblies in the autodesk-forge viewer, with external buttons. When a button is pressed externally, it will automatically zoom into the selected part inside the viewer. It is explained more here. My next step now, is to have those external parts on the website, highlight when a part is clicked inside the viewer. How can I have a function be executed (a highlight text function) when the user selects a part on the viewer. I have tried the following code but it doesn't work:
if (viewer.isolate(dbId) == true){
highlightFunction()
}
Any help on how a function can be executed when a user selects a part on the viewer would be greatly appreciated.
Thanks!

If I understand you correctly, then all you need to do is listen to the selection event and call your function from there:
viewer.addEventListener(
Autodesk.Viewing.SELECTION_CHANGED_EVENT,
(event) => { // do what you need }
)
Here is a sample: Selection override
If you're working with multiple models in the Viewer then listen to the AGGREGATE_SELECTION_CHANGED_EVENT event instead. See Multi-model refresher

Related

How do I enable text selection in Autodesk Forge Viewer with DWG as document

So I have a Forge Viewer correctly setup displaying my DWG/DXF.
I want to allow the user to click any Text or Multiline Text object and be able to handle a javascript event based on the selection.
For example, if you click on 1L2C in the Forge Viewer, a javascript event occurs with the selected item, thus allowing me to do a query to my API and display a popup.
The test file in question has a single Layout called "Layout 1" and is 2D.
The viewer doesn't have a "text selection" feature specifically, but you can:
get notified when a certain element of your 2D or 3D design is selected, by subscribing to the SELECTION_CHANGED_EVENT
extract metadata of any individual design element using the viewer.getProperties method, and see if it perhaps contains any property with its text content
You could try something like this:
viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, function () {
const selectedIds = viewer.getSelection();
if (selectedIds.length === 1) {
viewer.getProperties(selectedIds[0], function (result) {
for (const prop of result.properties) {
console.log(prop.displayName, prop.displayValue);
// see if any of the properties of the element contains its text content
}
});
}
});

how to zoom asset in forge viewer

we have implemented the forge viewer in our web application. When clicking the asset in forge viewer, we need to make our entire page should be loaded.
any click event is available when object is selected in viewer?
please provide the function name or code, we need to hit any function when asset selecting.
you can use below even, you can write this event after you create instance of viewer
viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectionChanged);
function onSelectionChanged()
{
perform your operation;
}
for zooming the asset you can use
viewer.fitToView([arrayofdbid],viewer.model);
if you want to highlight selection, you can use,
viewer.select([array of dbid]);

Copy an Image from Flex Application (Web) and paste it outside the application

I have a requirement that we should be able to copy an image displayed in our application, to Clipboard and paste it outside (Like on Excel).
I was trying the below code snippet (Inside a button Click).
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT,
byteArray, false);
The dataLoaded object is true, however it does not paste anything when tried on Excel or MsPaint.
Do we have any way to achieve this?
Thanks.
The code you are showing is not enough in itself to get a successful transfer. Like many other operations within the security sandbox of a FP app (web) this code can only respond to a direct user interaction. So your code without any valid context cannot work of course but if called within a mouse down listener for example (a true user generated mouse event, creating a fake mouseevent would still not work) it should respond correctly:
private function handleMouseClick(event:MouseEvent):void
{
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT, byteArray, false);
}

MessageHandler captured in various tabs - Flex

The architecture is based on the use of the following frameworks: Flex, Cairngorm and Parsley.
I use a dispatcher with an event "AdicionarItemVendaMercadoriaEvent" within a popuppanel: PopupPanel.
I capture the event with [MessageHandler] within the FormPM.as injected into Form.mxml.
Within Form.mxml, I have a mx: TabNavigator and each tab is within one s: NavigatorContent.
It turns out that when there is more than one open tab mx: TabNavigator the dispatched event is captured in all Form of all tabs.
Normal operation was to capture the only event of the tab where the PopupPanel was dispatched, not all tabs.
Please, any suggestions for solving this problem?
I appreciate the help.
How about using straight forward function callbacks?
When you create your PopUpPanel, pass in a function callback that you want to be executed when the popup is closed. Rather than using an event, you'd simply call the function. i.e.
Inside FormPM:
public function showPopup():void
{
var popup:PopUpPanel = new PopUpPanel();
popup.onCompletion = handleResult;
PopUpManager.addPopUp(popup, ...);
}
private function handleResult(someData:*):void
{
// My popup has completed.. what do I want to do with the result.
}
You might want to consider the Spicelib 3.0 command framework and have a command to popup your panel and then add the error/success callbacks to that: http://www.spicefactory.org/parsley/docs/3.0/manual/?page=commands&section=intro

Having issues with event on click

I have a button instance named "instructionButton" and I'm trying to trace "Clicked." to the output when it is clicked as a test but I haven' been successful thus far. Is there something I'm missing?
I'm using code in Flash Pro 6
import flash.events.MouseEvent;
var clickedVar:String = "Clicked.";
var runVar:String = "mice running...";
trace(runVar);
function instructionOpen(event:MouseEvent):void
{
trace(clickedVar);
gotoAndPlay(255);
}
instructionsButton.addEventListener (MouseEvent.CLICK, instructionOpen);
And of course if there's a more simple way to approach this, all knowledge will be helpful.
Check instance name is provided or not in the property window for the button (click the button and go to menu 'Window->Properties' to open property window)
What name is mentioned in the property window for the button, should use the same instance name in action script coding. Ensure the spelling from both script(code) and property window instance name.
I don't really see anything wrong with your button code, but here's how i do mine in AS3, it may help :) Creating a simple function within the event listener, I use stopPropgation to prevent my button from clicking anything that may be below it in the flash file. ( say you have two buttons on top of one another, you'll click both instead of one)
instructionsButton.addEventListener(MouseEvent.CLICK, function(e){
e.stopPropagation();
trace("Clicked.");
gotoAndPlay(255);
});
This is one button, if you need say fifteen, let me know as I have a code sample I'll give you that i use to create a limitless amount of buttons and eventlistners using switch/case which has been a huge help to me :)
The only way this will not work is if you are not reaching this frame.
Try add this code on your first frame and tell me if this helping.