Line exploding

Hi all,

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…

Can you post the lisp you were using?

Hi Jacob - I tried but It said it wasn’t a supported file type. - I can paste the code if that helps?

;;
;;;
;;;    By Dominic Panholzer
;;;
;;;    Modified original TXTEXP.LSP from Express Tools
;;;    Copyright © 1999 by Autodesk, Inc.
;;     LINEXP.LSP modifications by XANADU
;;;
;;;    Your use of this software is governed by the terms and conditions of the
;;;    License Agreement you accepted prior to installation of this software.
;;;    Please note that pursuant to the License Agreement for this software,
;;;    "[c]opying of this computer program or its documentation except as
;;;    permitted by this License is copyright infringement under the laws of
;;;    your country.  If you copy this computer program without permission of
;;;    Autodesk, you are violating the law."
;;;
;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
;;;    UNINTERRUPTED OR ERROR FREE.
;;;
;;;    Use, duplication, or disclosure by the U.S. Government is subject to
;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;    (Rights in Technical Data and Computer Software), as applicable.
;;;
;;;  ----------------------------------------------------------------
;;;
;;;  External Functions:
;;;
;;;     ACET-ERROR-INIT           --> ACETUTIL.FAS   Intializes bonus error routine
;;;     ACET-ERROR-RESTORE        --> ACETUTIL.FAS   Restores old error routine
;;;     ACET-GEOM-ZOOM-FOR-SELECT --> ACETUTIL.FAS   Zoom boundry to include points given
;;;     ACET-LAYER-LOCKED         --> ACETUTIL.FAS   Checks to see if layer is locked
;;;     ACET-GEOM-PIXEL-UNIT      --> ACETUTIL.FAS   Size of pixel in drawing units
;;;     ACET-GEOM-TEXTBOX         --> ACETUTIL.FAS   Returns the textbox for any text
;;;     ACET-GEOM-MIDPOINT        --> ACETUTIL.FAS   Returns midpoint between two points
;;;     ACET-GEOM-VIEW-POINTS     --> ACETUTIL.FAS   Returns corner points of screen or viewport
;;;     ACET-STR-FORMAT           --> ACETUTIL.ARX   String builder
;;;     ACET-WMFIN                --> ACETUTIL.FAS   Brings in WMF file
;;;
 
(defun c:linexp (/ grplst getgname blknm FLTR GLST GDICT SS VIEW UPLFT TMPFIL TBX
                   TMPFIL CNT PT1 PT2 ENT TXT TXTYP PTLST ZM LOCKED GNAM vpna vplocked)
  (acet-error-init
        (list
         (list   "cmdecho" 0
                 "highlight" 1
                 "osmode" 0
                 "Mirrtext" 1
                 "limcheck" 0
         )
         T
        )
  )
 
; --------------------- GROUP LIST FUNCTION ----------------------
;   This function will return a list of all the group names in the
;   drawing and their entity names in the form:
;   ((<ename1> . <name1>) ... (<enamex> . <namex>))
; ----------------------------------------------------------------
 
  (defun acet-txtexp-grplst (/ GRP ITM NAM ENT GLST)
 
    (setq GRP  (dictsearch (namedobjdict) "ACAD_GROUP"))
    (while (setq ITM (car GRP))       ; While edata item is available
      (if (= (car ITM) 3)             ; if the item is a group name
        (setq NAM (cdr ITM)           ; get the name
              GRP (cdr GRP)           ; shorten the edata
              ITM (car GRP)           ; get the next item
              ENT (cdr ITM)           ; which is the ename
              GRP (cdr GRP)           ; shorten the edata
              GLST                    ; store the ename and name
                  (if GLST
                    (append GLST (list (cons ENT NAM)))
                    (list (cons ENT NAM))
                  )
        )
        (setq GRP (cdr GRP))          ; else shorten the edata
      )
    )
    GLST                              ; return the list
  )
 
; ------------------- GET GROUP NAME FUNCTION --------------------
;   This function returns a list of all the group names in GLST
;   where ENT is a member. The list has the same form as GLST
; ----------------------------------------------------------------
 
  (defun acet-txtexp-getgname (ENT GLST / GRP GDATA NAM NLST)
    (if (and GLST (listp GLST))
      (progn
        (foreach GRP GLST
          (setq GDATA (entget (car GRP)))
          (foreach ITM GDATA                   ; step through the edata
            (if (and
                  (= (car ITM) 340)            ; if the item is a entity name
                  (eq (setq NAM (cdr ITM)) ENT) ; and the ename being looked for
                )
              (setq NLST                       ; store the ename and name
                      (if NLST
                        (append NLST (list (cons (car GRP) (cdr GRP))))
                        (list (cons (car GRP) (cdr GRP)))
                      )
              )
            )
          )
        )
      )
    )
    NLST
  )
 
; ----------------------------------------------------------------
;                          MAIN PROGRAM
; ----------------------------------------------------------------
 
  (if (and                                                ; Are we in plan view?
        (equal (car (getvar "viewdir")) 0 0.00001)
        (equal (cadr (getvar "viewdir")) 0 0.00001)
        (> (caddr (getvar "viewdir")) 0)
      )
 
    (progn
 
      (prompt "\nSelect lines to be EXPLODED: ")
 
      (Setq FLTR    '((-4 . "<AND")
                        (-4 . "<OR")                      ; filter for mtext and text
                          (0 . "MTEXT")
                          (0 . "TEXT")
                        (-4 . "OR>")
                        (-4 . "<NOT")
                          (102 . "{ACAD_REACTORS")        ; and not leader text
                        (-4 . "NOT>")
                      (-4 . "AND>")
                     )
            GLST     (acet-txtexp-grplst)                             ; Get all the groups in drawing
            GDICT    (if GLST
                       (dictsearch (namedobjdict) "ACAD_GROUP")
                     )
            SS       (ssget);  FLTR)
            CNT      0
      )
      ;; filter out the locked layers
      (if SS
        (setq SS (car (bns_ss_mod SS 1 T)))
      ) ;if
 
      ;; if we have anything left
      (if SS
        (progn
          (setq CNT 0)                                 ; Reset counter
          (while (setq ENT (ssname SS CNT))            ; step through each object in set
 
            (and
              GLST                                     ; if groups are present in the drawing
              (setq GNAM (acet-txtexp-getgname ENT GLST))          ; and the text item is in one or more
              (foreach GRP GNAM                        ; step through those groups
                (command "_.-group" "_r"               ; and remove the text item
                  (cdr GRP) ENT ""
                )
              )
            )
 
            (setq TBX (acet-geom-textbox (entget ENT) 0))   ; get textbox points
 
            (setq TBX (mapcar '(lambda (x)
                                 (trans x 1 0)         ; convert the points to WCS
                               )
                        TBX
                      )
            )
 
            (setq PTLST (append PTLST TBX))            ; Build list of bounding box
                                                       ; points for text items selected
 
            (setq CNT (1+ CNT))                        ; get the next text item
          ); while
 
          (setq PTLST (mapcar '(lambda (x)
                                 (trans x 0 1)         ; convert all the points
                               )                       ; to the current ucs
                      PTLST
                    )
          )
 
          (if (setq ZM (acet-geom-zoom-for-select PTLST))          ; If current view does not contain
            (progn                                     ; all bounding box points
              (setq ZM
                (list
                  (list (- (caar ZM) (acet-geom-pixel-unit))     ; increase zoom area by
                        (- (cadar ZM) (acet-geom-pixel-unit))    ; one pixel width to
                        (caddar ZM)                    ; sure nothing will be lost
                  )
                  (list (+ (caadr ZM) (acet-geom-pixel-unit))
                        (+ (cadadr ZM) (acet-geom-pixel-unit))
                        (caddr (cadr zm))
                  )
                )
              )
              (if (setq vpna (acet-currentviewport-ename))
                  (setq vplocked (acet-viewport-lock-set vpna nil))
              );if
              (command "_.zoom" "_w" (car ZM) (cadr ZM))  ; zoom to include text objects
            )
          )
 
          (setq VIEW     (acet-geom-view-points)
                TMPFIL   (strcat (getvar "tempprefix") "txtexp.wmf")
                PT1      (acet-geom-midpoint (car view) (cadr view))
                PT2      (list (car PT1) (cadadr VIEW))
          )
 
          (if (acet-layer-locked (getvar "clayer"))       ; if current layer is locked
            (progn
              (command "_.layer" "_unl" (getvar "clayer") "")  ; unlock it
              (setq LOCKED T)
            )
          )
 
          (command "_.mirror" SS "" PT1 PT2 "_y"
                   "_.WMFOUT" TMPFIL SS "")
 
          (if (findfile tmpfil)                           ; Does WMF file exist?
            (progn
              (command "_.ERASE" SS "")                   ; erase the orignal text
              (setq ss (acet-wmfin TMPFIL))               ; insert the WMF file
              (command "_.mirror" ss "" PT1 PT2 "_y")
            ) ;progn
          ) ;if
 
 
          (if LOCKED
            (command "_.layer" "_lock" (getvar "clayer") "") ; relock if needed
          ) ;if
 
          (if ZM (command "_.zoom" "_p"))              ; Restore original view if needed
          (if vplocked 
              (acet-viewport-lock-set vpna T) ;re-lock the viewport if needed.
          );if
          (prompt (acet-str-format "\n%1 object(s) have been exploded to lines."  CNT))
          (prompt "\nThe line objects have been placed on layer 0.")
        )
      )
    )
    (prompt "\nView needs to be in plan (0 0 1).")
  );if equal
  (acet-error-restore)                                  ; Retsore values
  (princ)
)


(princ)

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.

If that makes sense.

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?


The above is what I have the the moment - idea being that these values are what would cross reference to the catalogue

That would work, if you are 1000% sure that everything will always be in the catalog and no one will ever add a new line type or rename a linetype…

I am not 1000% sure, are you?

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. :slight_smile:

I appreciate any and all help - You sir are quickly becoming my hero haha

Looks like you’ll have to clean out some duplicate vertexes.
image

LineType Catalogue.xlsx (12.2 KB)

Line type catalogue.

Hmm OK I guess prune duplicates would be useful in that instance; oor I could just use Map clean and that seemed to resolve the issue.

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. :slight_smile:

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?

  1. export sdf format
  2. import sdf file in infraworks(coverage)
  3. select line type
  4. Add buffer value

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)


What would you recommend for unresolved nodes?

You need to install the packages those nodes come from.

This was built for Dynamo for Civil 3D, if you open it there and install Civil3D Toolkit you should be fine.

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.