select an element

General discussions about code engineering

Moderator: Moderators

select an element

Postby freshbanks31@gmail.com » Sun Sep 11, 2016 5:19 am

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
freshbanks31@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 9
Posts Rating:0
Joined: Thu Jun 23, 2016 7:18 pm

Re: select an element

Postby marlel » Mon Sep 12, 2016 8:27 am

Hello,
Code: Select all
project.getBrowser().getContainmentTree().openNode(element);
Best regards,
Martynas
marlel
No Magic
No Magic
 
Posts: 383
Posts Rating:28
Joined: Wed Jul 11, 2012 2:31 am

Re: select an element

Postby freshbanks31@gmail.com » Tue Sep 13, 2016 3:04 pm

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
freshbanks31@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 9
Posts Rating:0
Joined: Thu Jun 23, 2016 7:18 pm

Re: select an element

Postby marlel » Wed Sep 14, 2016 12:46 am

Make sure to add all jar files recursivelly from <Magicdraw install>/lib directory.
Best regards,
Martynas
marlel
No Magic
No Magic
 
Posts: 383
Posts Rating:28
Joined: Wed Jul 11, 2012 2:31 am

Re: select an element

Postby freshbanks31@gmail.com » Wed Sep 14, 2016 2:11 am

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
freshbanks31@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 9
Posts Rating:0
Joined: Thu Jun 23, 2016 7:18 pm

Re: select an element

Postby marlel » Wed Sep 14, 2016 5:10 am

Are you sure you want iterate the tree? Maybe you want iterate the UML model (tree is just a presentation of a model)
Best regards,
Martynas
marlel
No Magic
No Magic
 
Posts: 383
Posts Rating:28
Joined: Wed Jul 11, 2012 2:31 am

Re: select an element

Postby freshbanks31@gmail.com » Sun Oct 09, 2016 5:41 am

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....
freshbanks31@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 9
Posts Rating:0
Joined: Thu Jun 23, 2016 7:18 pm

Re: select an element

Postby marlel » Mon Oct 10, 2016 1:03 am

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);
Best regards,
Martynas
marlel
No Magic
No Magic
 
Posts: 383
Posts Rating:28
Joined: Wed Jul 11, 2012 2:31 am

Re: select an element

Postby amd0023@uah.edu » Wed Apr 10, 2019 8:59 am

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
amd0023@uah.edu
Forum Newbie
Forum Newbie
 
Posts: 12
Posts Rating:0
Joined: Mon Mar 25, 2019 8:59 am

Re: select an element

Postby marlel » Thu Apr 11, 2019 6:24 am

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"
Best regards,
Martynas
marlel
No Magic
No Magic
 
Posts: 383
Posts Rating:28
Joined: Wed Jul 11, 2012 2:31 am

Next

Return to Code engineering

Who is online

Users browsing this forum: No registered users and 0 guests