# Get all from and to relationships - Open API

**URL:** <https://forums.visual-paradigm.com/t/get-all-from-and-to-relationships-open-api/16137>\
**Category:** Plug-in & Open API\
**Tags:** code-engineering\
**Created:** [June 11, 2020, 3:23am UTC](https://forums.visual-paradigm.com/t/get-all-from-and-to-relationships-open-api/16137 "2020-06-11T03:23:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalitnagpal](https://avatars.discourse-cdn.com/v2/letter/l/c6cbf5/32.png) [@lalitnagpal](https://forums.visual-paradigm.com/u/lalitnagpal)\
**Post date:** [June 11, 2020, 3:23am UTC](https://forums.visual-paradigm.com/t/get-all-from-and-to-relationships-open-api/16137/1 "2020-06-11T03:23:08Z")

</div>

Hi Team

From open API code

Q. How do I get all the from and to relationships of a view?

Q. How do I get all the diagrams that a view appears in?

Q. How do I get the model or the diagram where the master view for a view was created?

Q. If i replace the model for a view ( see code below ), does it impact in any other diagrams where views are created? I am trying to replace the duplicate views and do not want to use merge here.

`diagramElement.setModelElement( someOthermodel )`

Q. Is there a way to replace 2 duplicate views in 1 diagram with just 1 combined view retaining all relationships from both into 1 single view in the diagram?

Thanks a lot for your help

---

<div class="post-metadata">

**Author:** ![peter.wong](https://forums.visual-paradigm.com/user_avatar/forums.visual-paradigm.com/peter.wong/32/3250_2.png) [@peter.wong](https://forums.visual-paradigm.com/u/peter.wong)\
**Post date:** [June 15, 2020, 8:13am UTC](https://forums.visual-paradigm.com/t/get-all-from-and-to-relationships-open-api/16137/2 "2020-06-15T08:13:57Z")

</div>

Let me try to reply the first 3 questions first:

**Q. How do I get all the from and to relationships of a view?**

```auto
IDiagramElement view = ...
IConnectorUIModel[] fromConnectors = view.toFromConnectorArray(); // the connectors connected from this view
IConnectorUIModel[] toConnectors = view.toToConnectorArray(); // the connectors connected from this view

```

For example:  
 ![FromToConnectors](https://forums.visual-paradigm.com/uploads/default/original/2X/d/d1df69c1fc2e5571368d82ee4f441a1307615162.png)

**Q. How do I get all the diagrams that a view appears in?**  
Background:

- 1 view must be appeared in 1 diagram.
- But 1 model element may have multiple views.
- Different views can be appeared in different diagrams.

```auto
IDiagramElement view = ...;
IModelElement modelElement = view.getModelElement(); // this view presents which model element
IDiagramElement[] views = modelElement.getDiagramElements(); // this model element is presented by which view(s).
for (IDiagramElement v : views) {
	IDiagramUIModel diagram = v.getDiagramUIModel(); // that view is shown on which diagram
	
}

```

**Q. How do I get the model or the diagram where the master view for a view was created?**

```auto
IDiagramElement view = ...;
boolean isMasterView = view.isMasterView();

IDiagramElement masterView = view.getModelElement().getMasterView();
IDiagramUIModel diagram = masterView.getDiagramUIModel();

```

About the last 2 questions:  
First, let me try to explain the structure between ModelElement \<\> View \<\> Diagram

 ![ModelView](https://forums.visual-paradigm.com/uploads/default/original/2X/0/04e4e458c608c5cb7d91bac85a37ccefa2dbb828.png)

**Q. If i replace the model for a view ( see code below ), does it impact in any other diagrams where views are created? I am trying to replace the duplicate views and do not want to use merge here.**  
It won’t impact other views. But you need to make sure, the view connected to correct connectors as the model.

**Q. Is there a way to replace 2 duplicate views in 1 diagram with just 1 combined view retaining all relationships from both into 1 single view in the diagram?**  
You need to _move_ the relationships+connectors from modelB+viewB to modelA+viewA

```auto
IModelElement modelA = ...;
IModelElement modelB = ...;
for (ISimpleRelationship relationship : modelB.toFromRelationshipArray()) {
	relationship.setFrom(modelA);
}
for (IRelationshipEnd relationshipEnd : modelB.toFromRelationshipEndArray()) {
	relationshipEnd.setModelElement(modelA);
}
for (ISimpleRelationship relationship : modelB.toToRelationshipArray()) {
	relationship.setTo(modelA);
}
for (IRelationshipEnd relationshipEnd : modelB.toToRelationshipEndArray()) {
	relationshipEnd.setModelElement(modelA);
}

IShapeUIModel viewA = ...;
IShapeUIModel viewB = ...;
for (IConnectorUIModel connector : viewB.toFromConnectorArray()) {
	connector.setFromShape(viewA);
}
for (IConnectorUIModel connector : viewB.toToConnectorArray()) {
	connector.setToShape(viewA);
}

```

Sample:

 ![Combine](https://forums.visual-paradigm.com/uploads/default/original/2X/4/428db4096e69a1c2fc289faaa70bc59fdcfc5997.png)
