Page 1 of 2

select an element

PostPosted: Sun Sep 11, 2016 5:19 am
by freshbanks31@gmail.com
hey guys, i want to to select an element programmatically like in the following picture the "model" element is selected. How can i do that?

http://imgur.com/vq8LFeF

Re: select an element

PostPosted: Mon Sep 12, 2016 8:27 am
by marlel
Hello,
Code: Select all
project.getBrowser().getContainmentTree().openNode(element);

Re: select an element

PostPosted: Tue Sep 13, 2016 3:04 pm
by freshbanks31@gmail.com
marlel wrote:Hello,
Code: Select all
project.getBrowser().getContainmentTree().openNode(element);


i tried this but i always get the following error:

The type com.nomagic.magicdraw.uml.BaseElement cannot be resolved. It is indirectly referenced from required .class files

but i think i already imported the required libs

Re: select an element

PostPosted: Wed Sep 14, 2016 12:46 am
by marlel
Make sure to add all jar files recursivelly from <Magicdraw install>/lib directory.

Re: select an element

PostPosted: Wed Sep 14, 2016 2:11 am
by freshbanks31@gmail.com
marlel wrote:Make sure to add all jar files recursivelly from <Magicdraw install>/lib directory.


ok thx it works but i have one more question.

i want to compare a string with the name of my elements in the browser tree. how can i iterate through my tree

Re: select an element

PostPosted: Wed Sep 14, 2016 5:10 am
by marlel
Are you sure you want iterate the tree? Maybe you want iterate the UML model (tree is just a presentation of a model)

Re: select an element

PostPosted: Sun Oct 09, 2016 5:41 am
by freshbanks31@gmail.com
i need a function which returns me an element of the containment tree by comparing a given string and the name of the element. I hope you can understand what i mean and can help me....

Re: select an element

PostPosted: Mon Oct 10, 2016 1:03 am
by marlel
Find any named element
Code: Select all
Class[] types = ClassTypes.getSubtypesArray(NamedElement.class);
Element element = Finder.byNameRecursively().find(project, types, name);
Collection<Element> elements = Finder.byNameAllRecursively().find(project, types, name);

Re: select an element

PostPosted: Wed Apr 10, 2019 8:59 am
by amd0023@uah.edu
Dear Forum Member,

I am able to select a node element using both project.getBrowser().getContainmentTree().openNode(element) and Finder.byNameRecursively().find(project, types, name).
However, I noticed that for an element that contains a hyperlink, openNode does not open the hyperlink.
What I want to do is open the hyperlink. However, I have checked the Cameo 18.5 SP3 API documentation and have not found anything.

Any assistance on this issue would be greatly appreciated. If you believe that this topic is too much of a diversion from the select element topic, please reply and I will create a new topic.
I just thought that selecting elements and opening hyperlinks of elements were somewhat related, so I decided to post a reply to this topic instead of creating a new topic.
Again, unlike me, if you think I am going too far astray from this topic, please let me know.

Thank you!

From,
Austin M. Deavers

Re: select an element

PostPosted: Thu Apr 11, 2019 6:24 am
by marlel
Hello,

Please create a new topic. Also please explain what you mean by "I noticed that for an element that contains a hyperlink, openNode does not open the hyperlink"