Help Consolidating Dynamo Graphs

I had 3 individual Dynamo graphs for a single workflow that was working really well, but I was hoping to consolidate the 3 graphs into a single graph for my team to use. I was able to consolidate the second and third graph successfully, but I am struggling to get the first one to combine due to a node at the end that is using a lineworkshrinkwrap command through some python code to generate a boundary around some inserted AutoCAD blocks. Right now, the python code really just initiates the lineworkshrinkwrap command in the command line and prompts you to select all, so it takes some very minor input from the user to (left-click mouse in model space, then hit ENTER on the keyboard), then I can open the other graph to finish out the process. Is it possible to allow user inputs like this in the middle of graph if I try to combine them into 1 larger graph? If not, any ideas on how to get the lineworkshrinkwrap command to run without user input? Attached is my graph with the lineworkshrinkwrap python script in there in case anyone wants to see it.
_1_OPTIMA Boundary Creation.dyn (51.8 KB)

Not entirely sure what lineworkshrinkwrap does, but you could:

  1. Pull the geometry of all objects onto the surface you want to work with so that you have ‘surfaces’.
  2. Union the surfaces into a single surface with the Surface.ByUnion node.
  3. Get the external loops via the Python here: Get the outer edge of a Road - #3 by jacob.small

Can you help detail out what you would do on the first step? Below is a screenshot of the AutoCAD Blocks (just a simple square shape) that one example project brings in, and I have selected the outlined polylines generated from the lineworkshrinkwrap command.

Sure - the first step is Object.Geometry.

Depending on what you get from that your next node will vary.

Could I use a my insertion points of my block to recreate this square as a rectangle object? Would that then be able to translate to a surface?

I think this is what I needed! I stumbled my way a bit, but I was able to make it create a boundary for me when I gave it two predetermined points, but now that I am trying merged my original graph in with the logic you have provided me, I am struggling to get the PolyCurve.ByJoinedCurves node to work. Seems like this node doesn’t like it when I input more than a single point into it, but I will have hundreds of points that I need to create a “rectangle.bywidthlength” and need a surface generated as well. Thoughts? Current Dynamo graph attached. Screenshot of the error below:


Alternate to Lineworkshrinkwrap_combined with Step 1.dyn (33.4 KB)

@jacob.small

I am not sure if I need that polycurve node? That might be my mistake, when I take that out, I dont get an errors up until the python script you lead me to from another forum. Now I am getting some errors there. Thoughts on that? Updated Dynamo graph attached, too. Thank you!
Alternate to Lineworkshrinkwrap_combined with Step 1_v2.dyn (30.9 KB)

Need a .dwg as well - will try to have a look tomorrow if you post one.

1 Like

@jacob.small

Attached is all I can think of to provide in support of this - I really appreciate it!

The Lineworkshrinkwrap.dyn graph is what I had at the start of the forum post.
The Lineworkshrinkwrap Graphy_Result.dwg is what I was creating from that that graph mentioned above.
The Alternate to Lineworkshrinkwrap_combined with Step 1.dyn is the latest script I mentioned in my last post.
Lineworkshrinkwrap Graph.dyn (43.4 KB)
It won’t let me add the csv, so I am not sure how to give you that data.

Lineworkshrinkwrap Graph_Result.dwg (1.6 MB)
Alternate to Lineworkshrinkwrap_combined with Step 1_v2.dyn (33.4 KB)

You can rename it to ‘fileName.csv.txt`. Think I can manage without it though. :slight_smile:

Nice work-around. CSV attached now. Thank you again!
pilesinviolations.csv.txt (5.4 KB)

1 Like

Your current issue is that the as soon as Surface.ByUnion detects a disjointed surface it returns all surfaces integrated into a single polysurface, rather than merging adjacent/overlapping surfaces into a series of surfaces, and then building a polysurface from the result.

This Python should make short work of that:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

surfs = IN[0] #the surfaces to union from the Dynamo environment
mergedSurfaces = [] #the resulting groups of surfaces

while surfs: #while there are items in the surfs list
    srf = surfs.pop(0) #take the first surface out of the list
    found = False #set found to false
    tested = [] #an empty list for tested surfaces
    toTest = [i for i in surfs] #set toTest to each item in the surfs list
    while toTest: #while there are items in the toTest list
        test = toTest.pop(0) #take the first item out of the toTest list
        if test.DoesIntersect(srf): #if the test item intersects the srf
            surfs.remove(test) #remove the test item from the surfs list
            srf = Surface.ByUnion([srf,test]) #set the srf to the union of the the test item and the srf 
            found = True #set found to true
        else: #if not intersecting
            pass
    if not found: mergedSurfaces.append(srf) #if found was not set to true, append the srf object to the merged surfaces list
    else: surfs.append(srf) #otherwise append the srf object to the surfs list

OUT = mergedSurfaces #return the merged surfaces

From there you can proceed with building the polysurface, and extracting the outside edges. However it looks as if your can leverage Surface.PerimeterCurves and convert to a PolyCurve directly by way of the PolyCurve.ByGroupedCurves node.

Looks something like this:

From there you should have the Dynamo equivalent of the “shrinkwrap” done, and you can move onto the integration as desired (perhaps by generating the linework in the model as polylines; or by skipping that step and moving into the second and third graph). I leave that work to you though - you’re pretty close from what I see!

2 Likes

This did it - you are the best! I can’t thank you enough!

1 Like

Happy to help!

Note that the Python there is well annotated for a beginner’s use, so hopefully you (and really others, including the future me) can learn a few tricks from it if you have needs that are similar in the future. :slight_smile:

1 Like