[C# Custom Addins] Remove GC association from an element

Hi all,

I am writing a custom node that will "Bake" GCElements into the model. I have got it working to a certain point, where it will add the elements into the active model, however I cannot find the method to remove the link / association as a GC Element? Code so far:

    public class Bake : GeometricNode
    {
        [GCDefaultTechnique]
        
        public NodeUpdateResult PlaceInActiveModel
        (
            NodeUpdateContext updateContext,
            [GCReplicatable, GCDgnModelProvider] object Elements
        )
        {
            try
            {
                ElementBasedNode node = Elements as ElementBasedNode;
                ElementCopyContext copyContext = new ElementCopyContext(Session.Instance.GetActiveDgnModel());

                foreach (Element nodeElement in node.Elements())
                {
                    Element cloned = copyContext.DoCopy(nodeElement);
                    NativeDgnTools.SetIsLocked(cloned, false);
                    NativeDgnTools.RemoveSelfDependLinkFromElement(cloned);
                }
                copyContext.Dispose();
                
                return NodeUpdateResult.Success;
            }
            catch(Exception ex)
            {
                return new NodeUpdateResult.TechniqueException(ex);
            }
        }
    }

If I try and edit the newly placed element I get the warning "Change rejected in order to preserve associations".

One other thing I have noticed, is that the node.Elements() doesn't seem to get a handle on native nodes GCElements? It will only work for my custom node that I have created which places an element as a platform native Element first, then makes use of the SetElement() method. Would be nice to figure out how to get a handle on all ElementBasedNode Elements, so that they could be baked into the model as well!

Thanks,

Ed

Parents
  • Hi Edward,

    Im just curios, it sound like you are trying to recreate the Export node? is there something this node does not do that has lead you to create your own node?

    Regards

    Brenden

    Brenden Roche

    Applications Engineer

    Bentley Systems, Manchester UK


    This is a test

  • Hi Brenden,

    I guess you're right it is somewhat of a home-baked version of the export node... reason for creating this is the export node doesn't allow you to export Parametric Cells (or any other unsupported node/geometry types that I have created). Additionally it would be nice to have flexibility to export to the active model as well, but that is a lesser priority for me.

  • Hi edward,

    I am reaching out, internally!!, to see if someone can help you.

    Brenden

    Brenden Roche

    Applications Engineer

    Bentley Systems, Manchester UK


    This is a test

  • Hi Edward can you share a copy of the script and a file with the geometry you are trying to bake?

    Brenden Roche

    Applications Engineer

    Bentley Systems, Manchester UK


    This is a test

  • Thanks Brenden,
    It might be difficult to send you a file / script since you would also need my custom nodes in order for that to work, but the theory is just to obtain the native elements from the input GC node, copy them and then remove the lock from the resulting elements that GC still has on them. So in theory in order to replicate on your end the code posted above should still work with standard nodes too, so long as we modify the code slightly so that it obtains the reference to the native dgn Element/s contained within the input node.


    I suspect the reason node.Elements() doesn't work on the standard nodes is because GC classifies each nodes elements differently e.g. BSplineCurve might = node.BSplineCurve instead for example (haven't tested this theory but it would make sense since GC is very particular about element types).

    Additionally, I suspect the reason for my code not working at removing the lock is due to the attached ecSchema that gc adds to the elements; if this was removed it might free the element from GC's lock? This would make the most sense since the elements I copy from input nodes still remain under a lock, even though the element reference is different now - possibly due to the schema still being retained on the resulting elements

    Hope this makes sense, will do some more testing when I get time but been busy with other tasks this week

    Thanks,

    Ed

Reply
  • Thanks Brenden,
    It might be difficult to send you a file / script since you would also need my custom nodes in order for that to work, but the theory is just to obtain the native elements from the input GC node, copy them and then remove the lock from the resulting elements that GC still has on them. So in theory in order to replicate on your end the code posted above should still work with standard nodes too, so long as we modify the code slightly so that it obtains the reference to the native dgn Element/s contained within the input node.


    I suspect the reason node.Elements() doesn't work on the standard nodes is because GC classifies each nodes elements differently e.g. BSplineCurve might = node.BSplineCurve instead for example (haven't tested this theory but it would make sense since GC is very particular about element types).

    Additionally, I suspect the reason for my code not working at removing the lock is due to the attached ecSchema that gc adds to the elements; if this was removed it might free the element from GC's lock? This would make the most sense since the elements I copy from input nodes still remain under a lock, even though the element reference is different now - possibly due to the schema still being retained on the resulting elements

    Hope this makes sense, will do some more testing when I get time but been busy with other tasks this week

    Thanks,

    Ed

Children
No Data