Routine that will write to file a selection of hatches with total area by layer

Routine that will write to file a selection of hatches with total area by layer

KPerison
Collaborator Collaborator
1,195 Views
7 Replies
Message 1 of 8

Routine that will write to file a selection of hatches with total area by layer

KPerison
Collaborator
Collaborator

Hello, I am tasked with checking some road volumes we've recieved from an external source.  I have 300+ exported CAD cross sections and have already recreated the necessary end area hatches for each section.  I have a spreadsheet set up to input the areas for each material at each section, but would like to at least automate the process of selecting the materials for each section, adding the hatches and recording the values for each station. Below is a sample of what I have to work with.

Section.JPG

What I'd like to be able to do is create a selection set consisting of the station TEXT object and the hatches for CUT,FILL and STRIPPING. Hit enter and have the routine write the total area for each material (add all hatches on same layer) to a file that indicates the Station, Layer, Total area of hatches for that layer.

Something like the following format:

26+50.000

C-SECT-VOL-CUT = 37.7885

C-SECT-VOL-FILL = 7.5674

C-SECT-VOL-STRP = 9.6441

 

Then without exiting the routine be able to make a selection set on the next cross section and have it write those values to the same file.

 

Would aryone be able to assist me with this? Thx.

 

0 Likes
Accepted solutions (1)
1,196 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

 

Can you post a sample dwg?

0 Likes
Message 3 of 8

KPerison
Collaborator
Collaborator

Here is a sample dwg. 2015 ver.

0 Likes
Message 4 of 8

KPerison
Collaborator
Collaborator

BeekeCZ,

I tried the routine you suggested by cadstudio. 

 

But it won't allow subsequent selections on other sections, thus it keeps overwriting the previous values and you must write the file out each section.

This is the output:

.C-SECT-VOL-CUT 37.7885 =37.7885
.C-SECT-VOL-FILL 7.5674 =7.5674
.C-SECT-VOL-STRP 9.6441 =9.6441
.C-SECT-VOL-STA 0.0000 =0.0000

 

Here's how I see the workflow:

  1. Start the routine.
  2. Ask for a path\file name at the start of the routine
  3. User makes 1st selection set (including the station text and all the hatches for that one station)
  4. User hits enter
  5. Routine writes the values to the file
  6. Routine asks for another selection set
  7. User selects objects on next section
  8. repeat until all sections processed
  9. Hit enter 2x to complete routine
  10. File is closed.

Ideally the format would have station listed on 1st line with layer values and total areas below:

26+00.000
.C-SECT-VOL-CUT = 22.1940
.C-SECT-VOL-FILL = 1.0243
.C-SECT-VOL-STRP = 7.6892

 

26+50.000
.C-SECT-VOL-CUT = 37.7885
.C-SECT-VOL-FILL = 7.5674
.C-SECT-VOL-STRP = 9.6441

.

.

.

repeat

 

Thx for the help.

 

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

BeekeCZ,

I tried the routine you suggested by cadstudio. 

 

But it won't allow subsequent selections on other sections, thus it keeps overwriting the previous values and you must write the file out each section.

This is the output:

.C-SECT-VOL-CUT 37.7885 =37.7885
.C-SECT-VOL-FILL 7.5674 =7.5674
.C-SECT-VOL-STRP 9.6441 =9.6441
.C-SECT-VOL-STA 0.0000 =0.0000

 

 

....

 


Yes. I know that... that's why I erased that. I did not read carefully.

This your task is clear now... if nobody steps in i'll look at that tomorrow.

0 Likes
Message 6 of 8

KPerison
Collaborator
Collaborator

Thank you very much.  I've just been asked to add an assumed rock depth as well, so I'll have to re-run the volumes a second time.  So any help getting this partially automated is much appriciated.

 

I've thought about it a little more and if I could request that the format be like below so it could easilly be imported to a spreadsheet then each cell could get mapped to the appropriate cell on my earthworks spreadsheet

 

Station Stripping Cut Fill
26+00.000 7.6892 22.1940 1.0243
26+50.000 9.6441 37.7885 7.5674

 

Attached is a sample of the volume spreadsheet I've started to manually input the end areas on the 1st workbook. The 2nd workbook is how I see the export from the routine to be formated.

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Yes, I see your point. I did same thing couple of year ago... Now I let a software do that (inroads or civil). 

 

Spoiler
(defun c:SectionArea ( / *error* i file sta cut fill strp lay en rep)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))

  ;------------------------------------------------------------------------------------------------------
  
  (if (and (setq file (open (getfiled "Define name of exported file" (getvar 'DWGPREFIX) "csv" 1) "a"))
	   (write-line "Station,Stripping,Cut,Fill" file))
    (while (setq ss (ssget '((-4 . "<OR")
			     (-4 . "<AND") (0 . "TEXT")  (8 . "*C-SECT-VOL-STA") (-4 . "AND>")
			     (-4 . "<AND") (0 . "HATCH") (8 . "*C-SECT-VOL-CUT,*C-SECT-VOL-FILL,*C-SECT-VOL-STRP") (-4 . "AND>")
			     (-4 . "OR>")
			     )))
      (setq sta  "NONE"
	    cut  0.
	    fill 0.
	    strp 0.)
      (repeat (setq i (sslength ss))
	(setq lay (cdr (assoc 8 (entget (setq en (ssname ss (setq i (1- i))))))))
	(cond ((wcmatch lay "*C-SECT-VOL-STA")
	       (setq sta (cdr (assoc 1 (entget en)))))
	      ((setq area (vlax-get (vlax-ename->vla-object en) 'area))
	       (cond ((wcmatch lay "*C-SECT-VOL-CUT")
		      (setq cut (+ cut area)))
		     ((wcmatch lay "*C-SECT-VOL-FILL")
		      (setq fill (+ fill area)))
		     ((wcmatch lay "*C-SECT-VOL-STRP")
		      (setq strp (+ strp area)))))))
      (setq rep (strcat sta "," (rtos strp 2 4) "," (rtos cut 2 4) "," (rtos fill 2 4)))
      (princ "Station,Stripping,Cut,Fill")
      (princ rep)
      (write-line rep file)))
  (*error* "end")
)
Message 8 of 8

KPerison
Collaborator
Collaborator

BeekeeCZ,

 

You are in deed the Bee's Knees! That worked exactly as requested. Thank you very much!

 

I prefer to let Civil3D do the heavy lifting when it comes to road design too.  I can't honestly remember the last time I had to hand calc road end area volumes before this.  These sections were produced by another company and we do not have access to the digital content used to generate the sections. We simply wanted to confirm volume estimates that were based off them.

 

Again thanks for your assistance.  You've restored my faith in the internet. 🙂

 

PS.

 

The routine stumbled and exited out a couple times on certain hatched sections for some reason.   When I listed the offenting hatches I could not determine any difference between them and the ones that were working.  I simply deleted / re-hatched them and restarted the routine from that section. Not sure why, but something to look out for if someone else uses it.

 

Samples for others to test are attached.

0 Likes