Get component Behaviours - [SOLVED]


I trying to get components inside a layout with valid connections in I/O ports.
I can get components by using the following script

 foreach (ISimComponent comp in app.World.Components)

And get the behaviors that are connections with

foreach (IBehavior b in comp.Behaviors)
   if (b.Name.ToLower().Contains("conn")) 
   //The connections starts with "Conn_"

Each behavior has a field called “IsConnected”. In the debug mode inside Visual Studio I can get the status of this field using the call:


and it returns me a Boolean.

But if I try to use that call in the code, the compiler does not recognize “Revolution” class. What should I import to get the “IsConnected” field? Is there any way to get this field?


I could not link the Revolution.dll to the project references. It says to check if the file is accessible, or if it’s a valid assembly or a COM component.

Thanks for the assistance.

Just cast you IBehavior to ISimInterface instead, it has that IsConnected property.
The wrapper classes are internal, you should only use the interfaces defined in Create3D.Shared.

Dear, TSy,

I tried

foreach (ISimInterface b in comp.Behaviors)

but got the following exception:

Unhandled exception occurred:System.InvalidCastException: Unable to cast object of type ‘VisualComponents.Revolution.OneWayPathWrapper’ to type ‘VisualComponents.Create3D.ISimInterface’.

Whays may be wrong?

Not every behavior is an “interface” behavior so you can’t cast all of them to ISimInterface.

foreach (IBehavior behavior in comp.Behaviors)
    // "safe cast" that returns null if cast fails.
    ISimInterface interfaceBehavior = behavior as ISimInterface;
    if (interfaceBehavior != null &&
        interfaceBehavior.Name.ToLower().Contains("conn") &&
        // This behavior is of type ISimInterface, its name contains "conn", and it is connected.

This is pretty basic C# stuff you can easily learn from online tutorials. VC .NET API reference you can find from the help tab of the software.

Many thanks, TSy, that solved the problem. I appreciate your prompt reply and clarifications!