Archi Forum

Archi Plug-ins => jArchi => Topic started by: rchevallier on January 05, 2021, 09:17:21 AM

Title: current view ?
Post by: rchevallier on January 05, 2021, 09:17:21 AM
model variable allow to obtain the current model
is there an equivalent for the current view?

I know you can obtain it from a selected visual object thru the .view attribute. But is there is no object in the view or no object selected, is there a way ?

Thanks
Title: Re: current view ?
Post by: Jean-Baptiste Sarrodie on January 05, 2021, 09:29:03 AM
Hi,

You can always access the collection of selected objects through "selection" variable. So if you run a script while the view itself is selected, "selection.first()" points to the view.

Regards,

JB
Title: Re: current view ?
Post by: rchevallier on January 05, 2021, 16:05:50 PM
Thanks

The only issue is if you select something in the concept tree ("Models" tab), I don't see how you can obtain then the current opened view (if there is any). You can list the  views of a model, but I don't see how to obtain the one opened and in particular the current one (if any)
Title: Re: current view ?
Post by: Jean-Baptiste Sarrodie on January 05, 2021, 16:10:12 PM
Hi,

Quote from: rchevallier on January 05, 2021, 16:05:50 PM
The only issue is if you select something in the concept tree ("Models" tab), I don't see how you can obtain then the current opened view (if there is any). You can list the  views of a model, but I don't see how to obtain the one opened and in particular the current one (if any)

There is no notion of "current view" in jArchi, only one of "current selection". In fact, there is no "current view" in Archi at all either as you could well change your window layout to have several views visible at the same time. So you have to assume that your script will be run with the current view opened and selected in the editor, or selected in the model tree. That's why I usually add some code to check this in my scripts.

Regards,

JB
Title: Re: current view ?
Post by: rchevallier on January 05, 2021, 18:04:33 PM
Thanks for the precision. At least I can detect if there is no current active view selected directly or indirectly thru the selected visual object. That shall be enough
Title: Re: current view ?
Post by: René on March 09, 2021, 16:29:42 PM
I wanna do $something with everything in the current view:

x = $(selection).first();
if(x.type == "archimate-diagram-model")
{
$(x).find("element").each(function(e){
console.log(e, e.fillColor);
})
}
else
{
console.log(x);
$(x).viewRefs().each(function(a){
console.log(a);
});
}


If nothing is selected, the view itself is selected. Everythings fine.

But: If I select one element inside this view, how do I reach the view itself? I tried viewRefs and refView. Any glue?
Title: Re: current view ?
Post by: Phil Beauvoir on March 09, 2021, 16:51:04 PM
You can use:

object.view

See https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Object#view