anchor.diff:        (atof (nth 3 manholeData))
         (atof (nth 4 manholeData))
         (atof (nth 5 manholeData))
  -    )
  -  );END if
  +    );END list
  +  );END if
  +
  +  ; v0.0 - 2017.01.25 - First issue
  +  ; Author: David Torralba
  +  ; Last revision: 2017.01.25
   )
   (defun DT:DrawManhole ( manholeData startPoint datum verticalExageration layFoul layStorm / pBase lay )
  -  (princ "\nmanholeData = ")(princ manholeData)
  +  ; Draw manhole data on the long section
  +  ; Return list of drawn entities if successful
  +  ; Return nil if something wrong
     (if (and manholeData datum startPoint)
       (if (= 'list (type manholeData))
  -      (if (= 8 (length manholeData))
  +      (if (= 9 (length manholeData))
           (if (or (= (substr (nth 1 manholeData) 1 1) "S") (= (substr (nth 1 manholeData) 1 1) "F") )
             (progn
  -            ; Find manhole position (chainage wise)
  -            (setq pBase (polar startPoint 0 (nth 0 manholeData)) )
  -
  -            ; Select layer
  +            (setq
  +              ; Get manhole position in long section according to its chainage
  +              pBase (polar startPoint 0 (nth 0 manholeData))
  +              ; Get manhole layer
  +              lay (nth 8 manholeData)
  +            )
  +            ; Draw manhole data on long section
               (cond
  -              ((= (substr (nth 1 manholeData) 1 1) "S") (setq lay layStorm) )
  -              ((= (substr (nth 1 manholeData) 1 1) "F") (setq lay layFoul) )
  +              ((= (substr (nth 1 manholeData) 1 1) "S")
  +                ; Return all drawn entity names, and append them to later wrap them in a group (name the group with the manhole name)
  +                (DT:SetGroup
  +                  (append
  +                    (list (DT:DrawStormInvertLevelBoxLine pBase lay))
  +                    (DT:DrawManholeInvertLevelTexts (polar pBase (* 1.5 pi) 45) lay (nth 2 manholeData) (nth 3 manholeData) (nth 4 manholeData) (nth 5 manholeData))
  +                    (list
  +                      (DT:DrawVerticalAxis pBase (polar pBase (* 0.5 pi) 110) lay)
  +                      (DT:WriteVerticalAxisLabel (polar pBase (* 0.5 pi) 110.5) lay (nth 1 manholeData))
  +                    );END list
  +                    (DT:MarkInvertLevel pBase (DT:GetILFromManholeData manholeData) datum verticalExageration lay)
  +                  );END append
  +                );END DT:SetGroup
  +              );END subcond
  +              ((= (substr (nth 1 manholeData) 1 1) "F")
  +                (DT:SetGroup
  +                  (append
  +                    (list
  +                      (DT:DrawFoulInvertLevelBoxLine pBase lay)
  +                    );END list
  +                    (DT:DrawManholeInvertLevelTexts (polar pBase (* 1.5 pi) 51) lay (nth 2 manholeData) (nth 3 manholeData) (nth 4 manholeData) (nth 5 manholeData))
  +                    (list
  +                      (DT:DrawVerticalAxis pBase (polar pBase (* 0.5 pi) 110) lay)
  +                      (DT:WriteVerticalAxisLabel (polar pBase (* 0.5 pi) 110.5) lay (nth 1 manholeData))
  +                    );END list
  +                    (DT:MarkInvertLevel pBase (DT:GetILFromManholeData manholeData) datum verticalExageration lay)
  +                  );END append
  +                );END DT:SetGroup
  +              );END subcond
               );END cond
  -
  -            (if lay
  -              (progn
  -                ; Draw invert level box line and ILs
  -                (cond
  -                  ((= (substr (nth 1 manholeData) 1 1) "S")
  -                    (DT:DrawStormInvertLevelBoxLine pBase lay)
  -                    (DT:WriteInvertLevels (polar pBase (* 1.5 pi) 45) lay (nth 2 manholeData) (nth 3 manholeData) (nth 4 manholeData) (nth 5 manholeData))
  -                    (DT:DrawVerticalAxis pBase (polar pBase (* 0.5 pi) 110) lay)
  -                    (DT:WriteVerticalAxisLabel (polar pBase (* 0.5 pi) 110.5) lay (nth 1 manholeData))
  -                    (DT:MarkInvertLevel pBase (DT:GetILFromManholeData manholeData) datum verticalExageration)
  -                  );END subcond
  -                  ((= (substr (nth 1 manholeData) 1 1) "F")
  -                    (DT:DrawFoulInvertLevelBoxLine pBase lay)
  -                    (DT:WriteInvertLevels (polar pBase (* 1.5 pi) 51) lay (nth 2 manholeData) (nth 3 manholeData) (nth 4 manholeData) (nth 5 manholeData))
  -                    (DT:DrawVerticalAxis pBase (polar pBase (* 0.5 pi) 110) lay)
  -                    (DT:WriteVerticalAxisLabel (polar pBase (* 0.5 pi) 110.5) lay (nth 1 manholeData))
  -                    (DT:MarkInvertLevel pBase (DT:GetILFromManholeData manholeData) datum verticalExageration)
  -                  );END subcond
  -                );END cond
  -              );END progn
  -              (progn (princ "\nERROR @ DT:DrawManhole > impossible to choose layer")(princ))
  -            );END if
             );END progn
  -          (progn (princ "\nERROR @ DT:DrawManhole > manhole name doesn't start with \"S\" or \"F\"")(princ))
  +          (progn (princ "\nERROR @ DT:DrawManhole > manhole name doesn't start with \"S\" or \"F\"")(princ) nil )
           );END if
  -        (progn (princ "\nERROR @ DT:DrawManhole > provided manholeData list has wrong number of items")(princ))
  +        (progn (princ "\nERROR @ DT:DrawManhole > provided manholeData list has wrong number of items")(princ) nil )
         );END if
  -      (progn (princ "\nERROR @ DT:DrawManhole > provided manholeData has wrong data type")(princ))
  +      (progn (princ "\nERROR @ DT:DrawManhole > provided manholeData has wrong data type")(princ) nil )
       );END if
  -    (progn (princ "\nERROR @ DT:DrawManhole > manholeData/datum/startPoint = nil")(princ))
  -  );END if
  -)
  +    (progn (princ "\nERROR @ DT:DrawManhole > manholeData/datum/startPoint = nil")(princ) nil )
  +  );END if
  +
  +  ; v0.0 - 2017.01.25 - First issue
  +  ; Author: David Torralba
  +  ; Last revision: 2017.01.25
  +)
  
positive.code: (defun c:1() (DT:ExtarctManholeChainages))
  (defun c:2 ( / old_error old_sysvars ent_name startPoint datum verticalExageration)
    ; SAVE SETTINGS
    (save_environment (list "osmode" "attdia" "attreq"))
  
negative.code:   );END foreach
  
    ; OPERATION - Return list of manholes in correct order
    (setq manholeChainageListSorted (acad_strlsort manholeChainageList))
  
    ; OPERATION - Rebuild data lists shorted by chainages
    (foreach ch manholeChainageListSorted
      (cond
        ((/= "" ch)
          (setq
            ; get position of the chainage at manholeChainageList (non-sorted list of chainages)
            position (vl-position ch manholeChainageList)
            ; copy data associated to the current chainage to manholeDatabaseSorted
            manholeDatabaseSorted (append manholeDatabaseSorted (list (nth position manholeDatabase)))
          );END setq
        )
      );END cond
    );END foreach
  
    ; v0.2 - 2107.01.29 - Tidy up comments
    ;                   - Add layer to de manholeData
    ;                   - Split code into simpler functions
    ;                   - Wrap long section manhole entities in separate groups
    ; v0.1 - 2017.01.25 - Function fully rewritten
    ; v0.0 - 2016.08.08 - First issue
    ; Author: David Torralba
    ; Last revision: 2017.01.29
  )
  (defun DT:GetManholeDataForLongSection ( manholeEnt_name )
    ; Return manhole data list as so:
    ; (list
    ;   Manhole Block Chainage            = (nth 0 man_data)
    ;   Manhole Block "ID" attribute      = (nth 1 man_data)
    ;   Manhole Block "IL1" attribute     = (nth 2 man_data)
    ;   Manhole Block "IL2" attribute     = (nth 3 man_data)
    ;   Manhole Block "IL3" attribute     = (nth 4 man_data)
    ;   Manhole Block "IL4" attribute     = (nth 5 man_data)
    ;   Manhole Block "visibility state"  = (nth 6 man_data)   para tener el tamano de la arqueta (DN1200, etc.)
    ;   Manhole Block "manhole size"      = (nth 7 man_data)
    ;   Manhole Block layer               = (nth 8 man_data)  para luego poder dibujarlo en la misma capa en el long section
    ; );END list
  
    (if manholeEnt_name
      (if (= "INSERT" (cdr (assoc 0 (entget manholeEnt_name))))
        ; Check if is a Manhole Block
        (if (= "W-Manhole" (substr (LM:effectivename (vlax-ename->vla-object manholeEnt_name)) 2 9))
          ; Return manhole data
          (list
            (DT:PK (vlax-ename->vla-object centrelineEnt_name) (cdr (assoc 10 (entget (cadr a)))))        ; Get manhole chainage
            (LM:vl-getattributevalue (vlax-ename->vla-object (cadr a)) "ID")                ; Extract Manhole Block "ID" attribute
            (LM:vl-getattributevalue (vlax-ename->vla-object (cadr a)) "IL1")               ; Extract Manhole Block "IL1" attribute
            (LM:vl-getattributevalue (vlax-ename->vla-object (cadr a)) "IL2")               ; Extract Manhole Block "IL2" attribute
            (LM:vl-getattributevalue (vlax-ename->vla-object (cadr a)) "IL3")               ; Extract Manhole Block "IL3" attribute
            (LM:vl-getattributevalue (vlax-ename->vla-object (cadr a)) "IL4")               ; Extract Manhole Block "IL4" attribute
            (LM:getvisibilitystate (vlax-ename->vla-object (cadr a)))                       ; Extract Manhole Block "visibility state"
            (cdr (assoc "Manhole size" (LM:getdynprops (vlax-ename->vla-object (cadr a))))) ; Extract Manhole Block "Manhole size"
            (cdr (assoc 8 (entget (cadr a))))                                               ; Extract Manhole Block layer
          );END list
          (progn (princ "\nERROR @ DT:GetManholeDataForLongSection > manholeEnt_name is not a manhole block\n")(princ) nil )
        );END if
        (progn (princ "\nERROR @ DT:GetManholeDataForLongSection > manholeEnt_name is not a block\n")(princ) nil )
      );END if
      (progn (princ "\nERROR @ DT:GetManholeDataForLongSection > manholeEnt_name = nil\n")(princ) nil )
    );END if
  
    ; v0.0 - 2017.01.29 - First issue
    ; Author: David Torralba
    ; Last revision: 2017.01.29
  )
  (defun DT:ExtractManholeChainages ( / centrelineEnt_name ans )
    ; ALMOST FINISHED - Purpose: store the chainages of selected manholes, to later draw them in the long section with another function
    ; PRECAUTION - If any manhole is not within the line, the routine will assign them the chainage at the beginning or end of the centreline.
    ;
    ; INPUT - Ask user to select a centreline
    (while (not centrelineEnt_name)
      (if (not (setq centrelineEnt_name (car (entsel "\nSelect centreline: "))))
        (princ "missed. Try again.")
        (progn
          (if
            (or
              (= "POLYLINE"   (cdr (assoc 0 (entget centrelineEnt_name))))
              (= "LWPOLYLINE" (cdr (assoc 0 (entget centrelineEnt_name))))
            );END or
            (princ "object selected.")
            (progn
              (princ "selected object is not a polyline. Try again.")
              (setq centrelineEnt_name nil)
            );END progn
          );END if
        );END progn
  