Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

HiddenLineDrawing.Compute with Blocks

$
0
0

@rajaa I am working along the below example to implement a custom version of HiddenLineDrawing.Compute.

Relevant part of example code:

    //add objects to hld_param
    foreach (var obj_ref in _obj_refs)
    {
      var obj = obj_ref.Object();
      _hld_params.AddGeometry(obj.Geometry, Transform.Identity, obj.Id);
    }

I am not able to add blocks or any other custom objects (VisualArq objects) to the HDL parameters. AddGeometry() returns null when trying to do so. How would I go about to add those? I assume I have to get to their geometry or is there a faster way?

Please find a demo script and test file below.

import Rhino.Geometry as rhg
import scriptcontext as sc
import rhinoscriptsyntax as rs


def test_hidden_line():
    viewport = sc.doc.Views.ActiveView.ActiveViewport
    
    # Setup HLD parameters
    parameters = rhg.HiddenLineDrawingParameters()
    parameters.AbsoluteTolerance = sc.doc.ModelAbsoluteTolerance
    parameters.IncludeHiddenCurves = False
    parameters.IncludeTangentEdges = False
    parameters.IncludeTangentSeams = False
    parameters.SetViewport(viewport)
    
    # Process all of the document objects
    rh_obj_guids  = rs.AllObjects(include_references=True)
    not_added = []
    added = []
    for obj_guid in rh_obj_guids:
        rh_obj = rs.coercerhinoobject(obj_guid)
        res = parameters.AddGeometry(rh_obj.Geometry, rh_obj.Id)
        if res:
            added.append(obj_guid)
        else:
            not_added.append(obj_guid)
    
    # DEBUG: Objects not added are selected <--------------- Blocks are ignored
    rs.UnselectAllObjects()
    rs.SelectObjects(not_added)
    
    # Create the hidden line drawing geometry
    hld = rhg.HiddenLineDrawing.Compute(parameters, True)
    
    # Add hidden line drawing to doc
    flatten = rhg.Transform.PlanarProjection(rhg.Plane.WorldXY)
    page_box = hld.BoundingBox(True)
    delta2D = rhg.Vector2d(0, 0)
    delta2D = delta2D - rhg.Vector2d(page_box.Min.X, page_box.Min.Y)
    delta3D = rhg.Transform.Translation(rhg.Vector3d(delta2D.X, delta2D.Y, 0.0))
    flatten = delta3D * flatten
    
    attributes = sc.doc.CreateDefaultAttributes()
    crvs = []
    for hld_curve in hld.Segments:
        if (hld_curve is None 
            or hld_curve.ParentCurve is None 
            or hld_curve.ParentCurve.SilhouetteType == rhg.SilhouetteType.None):
            continue
        crv = hld_curve.CurveGeometry.DuplicateCurve()
        if crv:
            crv.Transform(flatten)
            if hld_curve.SegmentVisibility == rhg.HiddenLineDrawingSegment.Visibility.Visible:
                if hld_curve.ParentCurve.SilhouetteType == rhg.SilhouetteType.SectionCut:
                    sc.doc.Objects.AddCurve(crv, attributes)
                else:
                    sc.doc.Objects.AddCurve(crv, attributes)
            elif hld_curve.SegmentVisibility == rhg.HiddenLineDrawingSegment.Visibility.Hidden:
                if hld_curve.ParentCurve.SilhouetteType == rhg.SilhouetteType.SectionCut:
                    sc.doc.Objects.AddCurve(crv, attributes)
                else:
                    sc.doc.Objects.AddCurve(crv, attributes);


test_hidden_line()

HiddenLineTest.3dm (5.4 MB)

Thanks for your help!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles