TBC Macros and Extensions

 View Only
Expand all | Collapse all

quick way to shrink-wrap a bunch of PolySegs?

  • 1.  quick way to shrink-wrap a bunch of PolySegs?

    Posted 06-29-2026 03:46

    As last step in my vehicle sweep path simulation I need to shrink-wrap all computed trace-lines to get the max affected area.

    Currently I'm using Trimble.Vce.Geometry.Region.Region.Union.

    union_list = Region.Union(env_regions, HoleProcessingOptions.RemoveChildHoles)

    That works but is extremely slow, sometimes several seconds, when the whole trace line computation is only tens of seconds.

    The manual shrink-wrap function on the same lines is much faster, but I haven't found out yet how to call it from a macro.



    ------------------------------
    Ronny Schneider
    ------------------------------


  • 2.  RE: quick way to shrink-wrap a bunch of PolySegs?

    Posted 06-30-2026 11:04

    Here's the bulk majority of shrink wrap. 

    var entities = m_SourceSelection.SelectedMembers(proj);
                var entityGroups = entities.OfType<ISnapIn>().GroupBy(x => ISnapInHelpers.GetViewSite(x, out ISnapIn _)).ToList();
    
                var settings = Trimble.Vce.Gem.Model3DCompSettings.ProvideSettingsObject(proj);
                proj.TransactionManager.AddBeginMark(CommandGranularity.Command, Caption);
                foreach (var entiryGrpup in entityGroups)
                {
                    IMemberManagement mm = null;
                    var gem = new Gem(Gem.ModelType.Dtm);  
                    gem.MaxOuterLength = d;
                    foreach (var entity in entiryGrpup)
                    {
                        if (mm == null)
                            ISnapInHelpers.GetMemberManagement(entity, out mm);
                        if (entity is IPolyseg ip)
                        {
                            int iVertexLast = -1;
                            var poly = ip.ComputePolySeg();
                            if (poly == null || poly.NumberOfNodes < 2)
                                continue;
                            poly = poly.Linearize(settings.HorzProximityTolerance, double.MaxValue, double.MaxValue, null, false);
                            var points = poly.Point3Ds();
                            foreach (Point3D point in points)
                            {
                                var z = double.IsNaN(point.Z) ? 0 : point.Z;
                                var p = new Point3D(point.X, point.Y, z);
                                var iVertex = gem.AddVertex(false, GemVertexType.Control, 0, ref p);
                                if (iVertexLast >= 0)
                                    gem.AddBreakline(false, 0, iVertexLast, iVertex);
                                iVertexLast = iVertex;
                            }
                        }
                        else if (entity is Vce.Interfaces.Point.IPointLocation pl)
                        {
                            var p = pl.Position;
                            if (double.IsNaN(p.Z))
                                p.Z = 0;
                            gem.AddVertex(false, GemVertexType.Control, 0, ref p);
                        }
                    }
                    gem.ConstructSurface();
                    var pts = gem.ExtractOutlines();
                    if (pts.Count < 3)
                        return;
                    using (var tr = new TransactMethodCall(proj.TransactionCollector))
                    {
                        try
                        {
                            Linestring lineString = mm.Add(typeof(Linestring)) as Linestring;
                            lineString.Layer = m_layer.SelectedSerialNumber;
                            var poly = new PolySeg();
                            var array = pts.ToArray();
                            for (int i = 0; i < array.Length; i++)
                            {
                                var p = array[i];
                                if (p.Z == 0)
                                {
                                    p.Z = double.NaN;
                                    array[i] = p;
                                }
                            }
                            poly.Add(pts.ToArray());
                            lineString.Append(poly, null, false, false);
                            tr.Commit();
    
                        }
                        catch (Exception)
                        {
                            clientSupport.MessageBoxService.ShowError(StringTable.CreateRectangle_Error_Adding_Rectangle_To_Container);
                            return;
                        }
                    }
                }

    Hopefully this helps. 



    ------------------------------
    Bryce Haire
    ------------------------------



  • 3.  RE: quick way to shrink-wrap a bunch of PolySegs?

    Posted 06-30-2026 17:53

    Thanks Bryce,

    that worked and is faster, I had always wondered how to triangulate without creating a Model3D in worldview.

    Creating the Gem with a dedicated ModelType seems key here.

    I wonder what ModelType.Solid does, is it for triangulating IFC mesh objects?

    I'm able to add vertices and breaklines to a Gem(Gem.ModelType.Solid)

    But that one fails upon calling gem.ConstructSurface() with "Vertex could not be located during construction"

    If that's not the way to do it, how do you triangulate a 3D IFC Meshes from just breaklines and vertices?



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 4.  RE: quick way to shrink-wrap a bunch of PolySegs?

    Posted 07-02-2026 03:28
      |   view attached

    This is one of many items on the rather long list of missing features that leave paying customers wondering why, after more than a decade, this is still not possible in a civil construction software package.

    It took me a few evenings with a chatbot. This time, I didn't write any code myself; I simply pointed it to my extensive collection of existing code and the SDK while continuously reviewing its reasoning. Occasionally, I had to stop it and steer it in the right direction, particularly when it presented assumptions as facts. You need to challenge those immediately, otherwise it will most likely start running in circles.



    ------------------------------
    Ronny Schneider
    ------------------------------