Get list of sub-models entity is in

How do I get a list of sub-models entity is in?

Parents
  • You can use the Where Used feature:

  • Macro to get it:

    ''MACRO TITLE: Show the submodels usage of an Entity/Table
    
    ' This macro displays the submodels used by the currently
    ' selected Entity/Table
    '-------------------------------------------------------------------
    
    Option Explicit
    
    Sub Main
    	Dim MyDiagram As Diagram
    	Dim MyModel As Model
    	Dim MyEntity As Entity
    	Dim MySubModel As SubModel
    	Dim MySelObject As SelectedObject
    
    	Dim wudo As WhereUsedDataObj
    	Dim OtherSubModel As SubModel
    
    	Dim ID As Integer
    	Dim ObjType As Integer
    
    	Dim SubModels As String
    
    	Debug.Clear
    
    	'Get the current diagram.
    	
    	Set MyDiagram = DiagramManager.ActiveDiagram
    	
    	'Get the current model.
    	
    	Set MyModel = MyDiagram.ActiveModel
    	
    	'Get the current submodel.
    	
    	Set MySubModel = MyModel.ActiveSubModel
    	
    	'Iterate through all the selected entities in the submodel
    	For Each MySelObject In MySubModel.SelectedObjects
    
    		'Get type of the selected object.
    		
    		ObjType = MySelObject.Type
    		
    		'We only want to get the entities, so check the
    		'object type.
    		
    		If ObjType = 1 Then
    		
    			'Get the ID of the selected object.
    		
    			ID = MySelObject.ID
    	
    			'Now, get the actual entity object with this ID.
    			
    			Set MyEntity = MyModel.Entities.Item(ID)
    
    			Debug.Print If(MyModel.Logical, MyEntity.EntityName, MyEntity.TableName)
    			SubModels = "SubModels for " & If(MyModel.Logical, MyEntity.EntityName, MyEntity.TableName) & vbCrLf & vbCrLf
    
    			' Display the submodels using this entity/table
    			For Each wudo In MyEntity.WhereUsedSubmodelUsage
    				Set OtherSubModel = MyModel.SubModels.Item(wudo.SubModelID)
    				SubModels = SubModels & OtherSubModel.Name & vbCrLf
    				Debug.Print OtherSubModel.Name
    			Next
    
    		End If ' only entities
    
    		Debug.Print SubModels
    		MsgBox SubModels, vbInformation, "SubModels"
    		
    	Next MySelObject
    
    End Sub

Reply
  • Macro to get it:

    ''MACRO TITLE: Show the submodels usage of an Entity/Table
    
    ' This macro displays the submodels used by the currently
    ' selected Entity/Table
    '-------------------------------------------------------------------
    
    Option Explicit
    
    Sub Main
    	Dim MyDiagram As Diagram
    	Dim MyModel As Model
    	Dim MyEntity As Entity
    	Dim MySubModel As SubModel
    	Dim MySelObject As SelectedObject
    
    	Dim wudo As WhereUsedDataObj
    	Dim OtherSubModel As SubModel
    
    	Dim ID As Integer
    	Dim ObjType As Integer
    
    	Dim SubModels As String
    
    	Debug.Clear
    
    	'Get the current diagram.
    	
    	Set MyDiagram = DiagramManager.ActiveDiagram
    	
    	'Get the current model.
    	
    	Set MyModel = MyDiagram.ActiveModel
    	
    	'Get the current submodel.
    	
    	Set MySubModel = MyModel.ActiveSubModel
    	
    	'Iterate through all the selected entities in the submodel
    	For Each MySelObject In MySubModel.SelectedObjects
    
    		'Get type of the selected object.
    		
    		ObjType = MySelObject.Type
    		
    		'We only want to get the entities, so check the
    		'object type.
    		
    		If ObjType = 1 Then
    		
    			'Get the ID of the selected object.
    		
    			ID = MySelObject.ID
    	
    			'Now, get the actual entity object with this ID.
    			
    			Set MyEntity = MyModel.Entities.Item(ID)
    
    			Debug.Print If(MyModel.Logical, MyEntity.EntityName, MyEntity.TableName)
    			SubModels = "SubModels for " & If(MyModel.Logical, MyEntity.EntityName, MyEntity.TableName) & vbCrLf & vbCrLf
    
    			' Display the submodels using this entity/table
    			For Each wudo In MyEntity.WhereUsedSubmodelUsage
    				Set OtherSubModel = MyModel.SubModels.Item(wudo.SubModelID)
    				SubModels = SubModels & OtherSubModel.Name & vbCrLf
    				Debug.Print OtherSubModel.Name
    			Next
    
    		End If ' only entities
    
    		Debug.Print SubModels
    		MsgBox SubModels, vbInformation, "SubModels"
    		
    	Next MySelObject
    
    End Sub

Children
No Data