How to get connected element and corresponding connectors

How to get connected element and corresponding connectors

thomas.herrmann2
Participant Participant
377 Views
1 Reply
Message 1 of 2

How to get connected element and corresponding connectors

thomas.herrmann2
Participant
Participant

Can somebody help me how to get the name of a connected element and the corresponding connectors which are used for this connection?

 

thomasherrmann2_0-1628498295737.png

 

c#:

 

foreach (CurrencyAPIv2.IAssetInstance s in objects)
{
  var c = s.NativeObject as ComponentOccurrence;
}

 

 

I need to know how to find it in IAssetInstance or ComponentOccurrence.

0 Likes
378 Views
1 Reply
Reply (1)
Message 2 of 2

thomas.herrmann2
Participant
Participant

We solved it with the XML-files which can also be watched in AttributeHelper:

 

 

thomasherrmann2_0-1634045748714.png

 

thomasherrmann2_1-1634045748733.png

 

 

        void LoadConnectors(Document document, List<ConnectionElement> connections, List<ConnectedComponent> components)
        {
            var am = document.AttributeManager;

            var d = new Dictionary<string, string>();
            var entities = am.FindObjects("*", "*");
            foreach (var e in entities)
            {
                try
                {
                    dynamic o = e;
                    foreach (AttributeSet attrS in o.AttributeSets)
                    {
                        foreach (Inventor.Attribute a in attrS)
                        {
                            d.Add(o.Name, a.Value as string);
                        }
                    }
                }
                catch(Exception)
                { }
            }

            foreach (var element in d)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(element.Value);

                var connectionNodes = xmlDoc.SelectNodes("//ObjectData[@Type='42']");
                var componentNodes = xmlDoc.SelectNodes("//ObjectData[@Type='38']");

                // Verbindungen
                if (connectionNodes.Count > 0)
                {
                    var link1Node = xmlDoc.SelectSingleNode("//ObjectData/Link1") as XmlElement;
                    var link2Node = xmlDoc.SelectSingleNode("//ObjectData/Link2") as XmlElement;
                    var connection = new ConnectionElement();
                    connection.Name = element.Key;
                    connection.Link1 = link1Node.GetAttribute("VAL");
                    connection.Link2 = link2Node.GetAttribute("VAL");
                    connections.Add(connection);
                }
                // Komponenten
                else if (componentNodes.Count > 0)
                {
                    var componentConnectorNodes = xmlDoc.SelectNodes("//ObjectData/Connector");
                    var componentConnectors = new List<ComponentConnector>();
                    foreach (XmlNode cc in componentConnectorNodes)
                    {
                        var idNode = cc.SelectSingleNode("Id") as XmlElement;
                        var displayNameNode = cc.SelectSingleNode("DisplayName") as XmlElement;

                        var connector = new ComponentConnector();
                        connector.DisplayName = displayNameNode.GetAttribute("VAL");
                        connector.Id = idNode.GetAttribute("VAL");
                        componentConnectors.Add(connector);
                    }
                    
                    if (components.FirstOrDefault(x => x.Name == element.Key) != null)
                    {
                        components.FirstOrDefault(x => x.Name == element.Key).Connectors.AddRange(componentConnectors);
                    }
                    else
                    {
                        var component = new ConnectedComponent();
                        component.Name = element.Key;
                        component.Connectors = new List<ComponentConnector>();
                        component.Connectors.AddRange(componentConnectors);
                        components.Add(component);
                    }
                }
            }
        }

 

0 Likes