Jump to content

Draw a polyline between selected midpoints


Recommended Posts

Hello,

 

I was hoping someone might be able to help?

 

I am looking for a way to draw a polyline which links the midpoints of a group of selected lines?

 

Specifically, I am trying to draw a polyline along the center of a road. I have a number of lines which run perpendicular to the path of the road and the mid point of these lines defines the middle of the road. So I would like to be able to select all these perpendicular lines and automatically draw a polyline which passes through all these points? Creating the red center line shown in the attachment (sorry for the cartoon-ish appearance!)

 

I say automatically as some of these paths will potentially be Km long and contain hundreds of lines...

 

Many thanks

Center Line.png

Link to comment

Hi, 

 

Thanks a lot for your quick response...!

 

I was looking for a way to create the line in red, from the lines in green below? Compose would only seem to "join" connected lines... the way I would normally go about doing this would be to just manually draw a polyline through all these lines using "snap to midpoint" however I was hoping there was an easier way?

 

Many thanks

Center Line 2.png

Edited by shodkin
Link to comment

The geometry parsing itself would be very easy even for a novice, to fetch the proper sequence (which orthogonal line comes next) is not something that can be resolved simply. All in all if you have great many of such objects, you should indeed ask for someone to script it for you.

 

I advise you against learning marionette or vectorscript it just for this task, because it is not a straight forward task that will bring you the joy of scripting, and that would be a pity. But if you want to get it going, ask in the Vectorscript forum.

 

Link to comment
  • 4 weeks later...

Hi,

 

Thanks for the responses.

 

I ended up approaching this using Python rather than VectorScript due to the number of available libraries out there for Python.

 

I found a number of the many approaches I found it seemed that the Voronoi method was one the most accurate and the Straight Skeleton method was one of the fastest. They both have their limitations and, for my uses, require some cleaning up once they have run, but they are a good starting point.

 

I have attached the resulting image and code for each method below, should anyone else wish to implement something similar...

 

Untitled.thumb.png.433a5de8a3c65387c8aa696724fa5b4a.png

Voronoi Method:

"
import vs
from shapely.geometry import Polygon
from ladybug_geometry_polyskel.polyskel import skeleton_as_edge_list

def Create_Center_Polys_Skel(p):
    #create a blank array to hold the of the shape we wish to
    #    find the centerline for
    list = []
    #Loop through each vertex in the shape and add its coordinates
    #    to the list
    for currentPoint in range(vs.GetVertNum(p)):
        x1, y1 = vs.GetPolyPt(p, currentPoint+1)
        list.append([x1, y1])
    #Create a "shapely" object of polygon from the vaules in the 
    #    list we have just generated
    polygon = Polygon(list)
    #Run the "Labybug PolySkel" function on that polygon and assign
    #    the return vaule, to "skelcenterline"
    skelcenterline = skeleton_as_edge_list(list)
    #Loop through each created vertex in "skelcenterline" and extract
    #    the start coordinates and end coordinates of each line that was
    #    created. When the start and end coordinates have been separated
    #    move the Vectorworks "cursor" to the start point of the line,
    #    and draw a line terminating at the end point
    for m in skelcenterline:
        startcord, endcord = m
        startx, starty = startcord
        endx, endy = endcord
        vs.MoveTo(startx, starty)
        vs.LineTo(endx, endy)
    #Run the menu command "compose" on all created objects to try and 
    #    consolidate them into as few polylines as possible for manipulation
    #    later
    vs.DoMenuTextByName('Compose',0);


#Set "selectedPoly" to be the currently selected Vectorworks polygon
selectedPoly = vs.FSActLayer()
#Run "Create_Center_Polys_Skel" passing it the polygon we just created
#    from the selected poly in Vectorworks
Create_Center_Polys_Skel(selectedPoly)
"

Straight Skeleton Method:
"
import vs
from shapely.geometry import Polygon
from ladybug_geometry_polyskel.polyskel import skeleton_as_edge_list
def Create_Center_Polys_Skel(p):
    #create a blank array to hold the of the shape we wish to
    #    find the centreline for
    list = []
    #Loop through each vertex in the shape and add its coordinates
    #    to the list
    for currentPoint in range(vs.GetVertNum(p)):
        x1, y1 = vs.GetPolyPt(p, currentPoint+1)
        list.append([x1, y1])
    #Create a "shapely" object of polygon from the values in the 
    #    list we have just generated
    polygon = Polygon(list)
    #Run the "Labybug PolySkel" function on that polygon and assign
    #    the return value, to "skelcenterline"
    skelcenterline = skeleton_as_edge_list(list)
    #Loop through each created vertex in "skelcenterline" and extract
    #    the start coordinates and end coordinates of each line that was
    #    created. When the start and end coordinates have been separated
    #    move the Vectorworks "cursor" to the start point of the line,
    #    and draw a line terminating at the end point
    for m in skelcenterline:
        startcord, endcord = m
        startx, starty = startcord
        endx, endy = endcord
        vs.MoveTo(startx, starty)
        vs.LineTo(endx, endy)
    #Run the menu command "compose" on all created objects to try and 
    #    consolidate them into as few polylines as possible for manipulation
    #    later
    vs.DoMenuTextByName('Compose',0);

#Set "selectedPoly" to be the currently selected Vectorworks polygon
selectedPoly = vs.FSActLayer()
#Run "Create_Center_Polys_Skel" passing it the polygon we just created
#    from the selected poly in Vectorworks
Create_Center_Polys_Skel(selectedPoly)
"

 

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...