Clash analysis automation value

Emanuel Hristea

Clash analysis automation value

Hello,

I am running a series of clash + clearance computations from .net.

The way I do it is to create two groups of products, add a bunch of products to each group using AddExplicit then I assign the two groups to FirstGroup and SecondGroup members of the Clash object and run a clash computation between two (catClashComputationTypeBetweenTwo). The interference type I use is catClashInterferenceTypeClearance.

Everything works fine, the only problem is that the value of the conflicts is always 0. I found no way to get the actual conflict value from the code. In CATIA, once you click on a clash in the report window it marks the line as relevant and computes the value. How can I do the same in code? (I tried to mark it as relevant in code but it does nothing).

I have tried the same in Vba in Catia and I get the same behavior as in .Net. I feel there is something very basic that i'm missing here. The clearance value is set correctly and if I compute a distance between the first and second product on the conflict I get the correct value (this is the workaround I am using at the moment), it is just impossible to get it directly from the conflict object.

Thanks,

Emanuel

Edited By:
Emanuel Hristea[Subscriber Members] @ Jun 03, 2021 - 12:13 AM (Europe/Bucharest)
Emanuel Hristea[Subscriber Members] @ Jun 03, 2021 - 12:15 AM (Europe/Bucharest)
Emanuel Hristea[Subscriber Members] @ Jun 03, 2021 - 12:16 AM (Europe/Bucharest)
Emanuel Hristea[Subscriber Members] @ Jun 03, 2021 - 12:19 AM (Europe/Bucharest)

Emanuel Hristea

RE: Clash analysis automation value
(in response to Emanuel Hristea)

I am replying to my own question, but it may help somebody else in the future. 

The problem was due to the way I was accessing the Conflicts collection.

I was using a foreach loop thus using the iterator. In this case the value is not computed. However if the Conflict is accessed using Conflicts.Item(i) method then the value is computed.

Very non-intuitive getter with side-effects!

Are there any other places where such a behavior is present?

Little Cthulhu

RE: Clash analysis automation value
(in response to Emanuel Hristea)

I like how you use adjective "unintuitive" instead of saying "another ugly bug".

Thanks for posting the solution.

Emanuel Hristea

RE: Clash analysis automation value
(in response to Little Cthulhu)

I am not sure it is really a bug, seems to me like some sort of performance improvement hack. If you run the clash from the UI, the values of the conflicts are not computed automatically (at least in the latter versions of CATIA v5) but as soon as you select one, then the value is computed.

I have noticed that the value computation can be expensive especially for a long list of conflicts so I guess that hack was kind of an workaround towards that. From an API standpoint it is kind of a bug because it breaks the contract with the consumer of the library. 

I am actually planning to use this quirk to my advantage. I have in some cases lists of 1000 conflicts. If I use Item to get the conflict info it takes >10s (I suspect it does a distance computation for each when accessed), however by using the iterator I get them instantly  and can build my report. When the user interacts with a particular conflict then I can use the Item(i) getter to get the actual value.

Edited By:
Emanuel Hristea[Subscriber Members] @ Jun 08, 2021 - 02:26 PM (Europe/Bucharest)
Emanuel Hristea[Subscriber Members] @ Jun 08, 2021 - 02:33 PM (Europe/Bucharest)

Little Cthulhu

RE: Clash analysis automation value
(in response to Emanuel Hristea)

I failed to reproduce described behaviour with VBA.

Do you call Clash.Compute method? What release are you on? Can you post your c# code?

Emanuel Hristea

RE: Clash analysis automation value
(in response to Little Cthulhu)

I'm using R29 (v5-6 release 2019)

Yes I am calling compute on the clash. This is a sample of the code where the two behaviors occur:

 

foreach (Conflict conflict in clash.Conflicts) {

    var value = conflict.Value; // value is always zero. Performance is quite good compared to method below

}

for (var i = 1; i <= clash.Conflicts.Count; ++i) {
      var conflict = clash.Conflicts.Item(i); // Here we get the performance hit. Catia actually computes the value (probably a distance) when Item is called.
      var value = conflict.Value;  // here the value is computed.
}

 

The clash is computed identically in both cases:

private Clash? ComputeClash(
    IReadOnlyCollection p1,
    IReadOnlyCollection  p2,
    double clearance,
    CatClashInterferenceType iType = CatClashInterferenceType.catClashInterferenceTypeClearance,
    CatClashComputationType cType = CatClashComputationType.catClashComputationTypeBetweenTwo)
{
    try {
        if(p1.Count ==0 || p2.Count == 0) {
            return null;
        }

        var key = GetProductGroupsKey(p1,p2);
        if (!_clashCache.ContainsKey(key)) {
            var cls = Clashes?.Add();
            var firstGroup = Groups?.Add();
            var secondGroup = Groups?.Add();


           if (cls == null || firstGroup == null || secondGroup == null) {
               return null;
           }

            foreach(var prd in p1) {
                firstGroup.AddExplicit(prd);
            }

            foreach(var prd in p2) {
                secondGroup.AddExplicit(prd);
            }

            cls.FirstGroup = firstGroup;
            cls.SecondGroup = secondGroup;
           _clashCache[key] = cls;
        }

        var clash = _clashCache[key];
        clash.ComputationType = cType;
        clash.Clearance = clearance;
        clash.InterferenceType = iType;
        clash.Compute();
        return clash;
    } catch {
        ClearClashes();
    }
    return null;
}

 

Clashes, Groups are objects that are obtained using GetTechnologicalObject.

the _clashCache is just a cache, I need it for processing at later stages.

Best regards,

Emanuel

Edited By:
Emanuel Hristea[Subscriber Members] @ Jun 13, 2021 - 02:38 PM (Europe/Bucharest)
Emanuel Hristea[Subscriber Members] @ Jun 13, 2021 - 02:40 PM (Europe/Bucharest)
Emanuel Hristea[Subscriber Members] @ Jun 13, 2021 - 02:42 PM (Europe/Bucharest)