Intent: Export road marking linework to sdf for use in infraworks.
Issue: Road markings have been drawn as long polylines and styled using a linetype to replicate the dashes of the road marking; when imported into infraworks the linetype is lost and line is continuous.
I have found a lisp routine (linexp.lsp) which does what I want (explodes the long line into outlines) however this is based off of exporting and importing vectorised linework and as such depends on the zoom level of the model as to the accuracy of the exploded lines; and so if I have a large drawing it would take some time to complete as I would need to do the drawing in sections.
The lisp routine creates what I can describe as a TIN network of 2D polylines, however it creates a lot of these lines just for a single dash and I was wondering if there is a way to do this in Dynamo? Example Dwg.dwg (1012.1 KB) Example Dwg after Line Exp.dwg (1.3 MB)
Initially my first though was to go through the dwg and use the linexp.lsp then take the linework created and some how simplify the geometry to only take the outer edge of the marking (i don’t know how to do that either) but thought there might be an more efficient way of doing that in dynamo. I also found the LINKDWG package and LINKDWG2 package but have no idea on how to actually use them.
If someone could telepathically transfer me their knowledge of Dynamo i would appreciate it!
From a pure Dynamo perspective, this wouldn’t be too hard to manage. But from a AutoCAD perspective it’s a bit tougher, as I don’t believe there are any nodes for accessing linetype definitions directly…
My thinking with regards to linetype definitions was grab the linetype names used in the drawing then recreate the definition in dynamo i.e. 4m mark, 2m gap, for each type, then use the existing geometry line to create new geometry specifying a 4m section and a 2m section, then add an offset 1/2 the global width of the line (as it would be centre) and filter out only the sections where I want the mark i.e. the 4m part and then tell dynamo to create the boundary of that mark.
Absolutely makes sense, and is the easy part I mentioned. However… how would you access those line type definitions? Sadly there isn’t a node for ‘get the line type geometry definition’.
Create a catalogue in something like excel (from the .lin file used for the linetype definitions) stating what each linetype means, i.e. 1004 has a 4m line folled by 2m break then match them with the linetype of the polylines?
In terms of road markings I am sure - they are defined by design guidance and don’t think they would need to be amended. Potentially there could be a problem with the Bylayer or byblock; but these could be parsed into a new drawing (I assume)to be reviewed and amended to the correct linetype then run through the OG script again.
This would only be used for road markings (which we keep in a separate file) which is based on the design series item they reflect i.e. road markings and signage.
Would is be an large issue if they didnt match? Other than a return of Null or something?
it would trigger a warning, which would result in a null result. If a null result was present ast ehf irst item in a list it can cause everything after it to be null.
Best to go into the DWG directly (which is doable via API and why I asked for the lisp), as if you can avoid the issue then why not do so? Hope to have something soon but no promises as only part of my weekend plans fell though.
Got a POC for pulling the line type pattern dimensions out of an object (line or polyline) at the given scale, no external dictionary required. However I ran out of time to get it posted. I’ll upload later.
Maybe you already thought about it but keep in mind that linetypes should not be dependent on scale, they must always have the same appearence.
A quick idea, how do you set the elevation on the objects to have them draped on a surface or set to a specific level in Infraworks? Could this be made in C3D in the same flow, and also set the elevation about an inch or 2.5mm above the surface to make them visable and not in collision with the surface?
This code should get you the pattern lengths at the scale of the line type.
import sys #import the sys module into the Python environment
import clr #import the common language runtime (clr)into the Python environment so we can utilize .net libraries
# Add Assemblies for AutoCAD and Civil3D to the clr
[clr.AddReference(i) for i in ['AcMgd','AcCoreMgd','AcDbMgd','AecBaseMgd','AecPropDataMgd','AeccDbMgd']]
# Import classes from AutoCAD to the python environment
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
# Import classes from Civil3D to the Python environment
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
adoc = Application.DocumentManager.MdiActiveDocument #get the active document
sourceLines = IN[0] #the source lines from the Dynamo environment
if not sourceLines.__class__ == list: sourceLines = [sourceLines] #ensure the sourcelines variable is a list
patternLengths = [] #an empty list to hold the results
for sourceLine in sourceLines: #for every source line in the source lines variable
internalLine = sourceLine.get_InternalDBObject() #get the autocad internal line object
lineTypeName = internalLine.Linetype #get the name of the linetype
lineTypeScale = internalLine.LinetypeScale #get the linetype scale
with adoc.LockDocument(): #lock the document
with adoc.Database as db: #get the autocad database
with db.TransactionManager.StartTransaction() as t: #start a transaction
lineTypeTable = t.GetObject(db.LinetypeTableId, OpenMode.ForRead) #get the line type table for reading
lineTypeTableRecords = [t.GetObject (i, OpenMode.ForRead) for i in lineTypeTable] #get each line type from the line type table
lineTypeTableRecord = [i for i in lineTypeTableRecords if i.Name == lineTypeName][0] #get the line type table record with a name that matches the line type name from the source line
dashCount = lineTypeTableRecord.NumDashes # get the number of items in the line type
dashLengths = [lineTypeTableRecord.DashLengthAt(i)*lineTypeScale for i in range(dashCount)] #get the length of each dash in the line type
if dashLengths == []: dashLengths = [0] #if the list of dashes was an empty list, make it a list containing just zero
patternLengths.append(dashLengths) #append the dash lengths list to the pattern lengths variable
t.Abort() #cancel the transaction so we aren't modifying the document
pass #just in case we want o ensure we close the loop cleanly
OUT = patternLengths #return the pattern lengths to the Dynamo environment
From there you can filter out anything without a pattern (just a zero for the output) and thicken it directly to get the solid lines addressed.
I haven’t worked out how the line types are centered on the curves yet (likely as I dont’ know AutoCAD well enough), but this should give you a start on generating the polycurves from the linetypes. Feel free to adjust the design script and report back when you get the solution. LineType to Lines.dyn (125.4 KB)
This only really works if the lines are drawn as singular entities, in cases such as a centre marking which is a long line styles with a dash it doesnt work as the linetype does not come through into infraworks. I did think about styling them as a barrier but then that means I will have a mixture of connection types where some markings which are coverages and some are barriers, which to mean seems overly messy and inconsistent.
@jacob.small did an awesome job of getting the bones of what I want, and am grateful for that but what seems to happen is as he said the placement of the outlines don’t match what the linetype is being displayed as due to the centering of the pattern (linetype) along the length of the line.