Plotting through Core console on 2024 civil 3d

Plotting through Core console on 2024 civil 3d

faisalWJ8Y9
Enthusiast Enthusiast
3,104 Views
29 Replies
Message 1 of 30

Plotting through Core console on 2024 civil 3d

faisalWJ8Y9
Enthusiast
Enthusiast

Edit: 

 

I have since updated the script to have it working in the 2022 version of Civil 3d. However am having issues making it work on the 2024 version. Upon entering the script lines manually in 2024 it seems to work... any ideas please shoot me a response? The new script is below

 

Hello all

 

trying to make a script which I can run with core console to plot drawings through cre console by passing the need to open each drawing and close like publish.

 

At the moment the script works for single layout drawings IE 1 paper space layout and will PDF the drawings. However I want to make it so that the script will pick up that there is 2 layouts in a drawing and pdf them with the naming convention the layout has.

 

if you have any ideas can you reach out:? script is below

 

;;---------=={ A1 SAP STD Draft Plot Script }==------------;;
;; ;;
;; Prints to pdf the current drawing by using the ;;
;; drawing name and layout tab value to create the ;;
;; file name. Saves the PDF to the folder listed below: ;;
;; "U:\\pdf location\\" ;;
;; ;;
;;------------------------------------------------------------;;
;; Author: Faisal D ;;
;;------------------------------------------------------------;;
;; Version 2.0 - 17-01-2024 ;;
;;------------------------------------------------------------;;
;;------------------------------------------------------------;;
;; File Name Variables
;;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
(setvar "filedia" 0)
(command "cmdecho" "1")
(command "TILEMODE" "0" "PDMODE" "0" "ZOOM" "E" "-OSNAP" "NONE" "wipeout" "f" "off" "TEXTFILL" "1" "REGENALL");command
(setq PDF_PATH "U:\\pdf location\\")
(if (not (vl-file-directory-p PDF_PATH))
(vl-mkdir PDF_PATH))
;;-----------------------------------------------------------------------------------------------------------------------;
;; Start FOREACH loop to run through all layout tabs
;;-----------------------------------------------------------------------------------------------------------------------;
(foreach layoutname
(
(lambda ( dict / def l n )
(while (setq def (dictnext dict (null def)))
(if (not (eq "MODEL" (strcase (setq n (cdr (assoc 1 (reverse def)))))))
(setq l (cons n l))
)
)
(reverse l)
)
(cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
)
(setvar "ctab" layoutname)
;;-----------------------------------------------------------------------------------------------------------------------;
;; Start of PLOTS SETTINGS FOR A1 PDF IN COLOUR - SAP
;;-----------------------------------------------------------------------------------------------------------------------;
(command "-PLOT"
;Detailed plot configuration? [Yes/No] <No>:
"yes"
;Enter a layout name or [?] <Layout1>:
""
;Enter an output device name or [?] <AutoCAD PDF (General Documentation).pc3>:
"DWG To PDF.pc3"
;Enter paper size or [?] <ISO A4 (210.00 x 297.00 MM)>:
"ISO full bleed A1 (841.00 x 594.00 MM)"
;Enter paper units [Inches/Millimeters] <Millimeters>:
"Millimeters"
;Enter drawing orientation [Portrait/Landscape] <Portrait>:
"Landscape"
;Plot upside down? [Yes/No] <No>:
"No"
;Enter plot area [Display/Extents/Layout/View/Window] <Layout>:
"Extents"
;Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <1:1>:
"1:1"
;Enter plot offset (x,y) or [Center] <0.00,0.00>:
;"0.00,0.00"
"Center"
;Plot with plot styles? [Yes/No] <Yes>:
"yes"
;Enter plot style table name or [?] (enter . for none) <>:
"SAP_A1-A3.ctb"
;Plot with lineweights? [Yes/No] <Yes>:
"yes"
;Scale lineweights with plot scale? [Yes/No] <No>:
"no"
;Plot paper space first? [Yes/No] <No>:
"no"
;Hide paperspace objects? [Yes/No] <No>:
"no"
;name of plot file
(strcat PDF_PATH layoutname ".pdf")
;Save changes to page setup [Yes/No]? <N>:
"N"
;Proceed with plot [Yes/No] <Y>:
"Yes"
;Effective plotting area: 841.00 wide by 594.00 high
;Plotting viewport 1
);command
;;-----------------------------------------------------------------------------------------------------------------------;
;; Ends the for each loop
;;-----------------------------------------------------------------------------------------------------------------------;
);; Ends the for each loop
;;-----------------------------------------------------------------------------------------------------------------------;
;; END OF PLOT SETTINGS FOR A1 PDF IN COLOUR - SAP
;;-----------------------------------------------------------------------------------------------------------------------;
(setvar "filedia" 1)
(prompt (strcat "\n:: PDF saves in " PDF_PATH " | \\U+00A9 Faisal D " (menucmd "m=$(edtime,0,yyyy)") " ::\n"))

 

0 Likes
3,105 Views
29 Replies
Replies (29)
Message 2 of 30

Sea-Haven
Mentor
Mentor

Maybe something like this ,

 

 

;; Start of PLOTS SETTINGS FOR A1 PDF IN COLOUR - SAP
;;-----------------------------------------------------------------------------------------------------------------------;
(command "-PLOT"


(foreach lay (layoutlist)
(setvar "ctab" lay)
(setq pdfname (strcat (getvar "dwgprefix") "pdf\\" dwgname "-" (getvar "ctab")))
(command "-PLOT"

 

 

0 Likes
Message 3 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

hi mate,

 

thanks for your response. I ended up getting it to work. The problem is it only works in the 2022 version of Civil 3d. I have no idea why it won't work in 2024... lol

here is the updated script

 

;;---------=={ A1 SAP STD Draft Plot Script }==------------;;
;; ;;
;; Prints to pdf the current drawing by using the ;;
;; drawing name and layout tab value to create the ;;
;; file name. Saves the PDF to the folder listed below: ;;
;; "U:\\pdf location\\" ;;
;; ;;
;;------------------------------------------------------------;;
;; Author: Faisal D ;;
;;------------------------------------------------------------;;
;; Version 2.0 - 17-01-2024 ;;
;;------------------------------------------------------------;;
;;------------------------------------------------------------;;
;; File Name Variables
;;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
(setvar "filedia" 0)
(command "cmdecho" "1")
(command "TILEMODE" "0" "PDMODE" "0" "ZOOM" "E" "-OSNAP" "NONE" "wipeout" "f" "off" "TEXTFILL" "1" "REGENALL");command
(setq PDF_PATH "U:\\pdf location\\")
(if (not (vl-file-directory-p PDF_PATH))
(vl-mkdir PDF_PATH))
;;-----------------------------------------------------------------------------------------------------------------------;
;; Start FOREACH loop to run through all layout tabs
;;-----------------------------------------------------------------------------------------------------------------------;
(foreach layoutname
(
(lambda ( dict / def l n )
(while (setq def (dictnext dict (null def)))
(if (not (eq "MODEL" (strcase (setq n (cdr (assoc 1 (reverse def)))))))
(setq l (cons n l))
)
)
(reverse l)
)
(cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
)
(setvar "ctab" layoutname)
;;-----------------------------------------------------------------------------------------------------------------------;
;; Start of PLOTS SETTINGS FOR A1 PDF IN COLOUR - SAP
;;-----------------------------------------------------------------------------------------------------------------------;
(command "-PLOT"
;Detailed plot configuration? [Yes/No] <No>:
"yes"
;Enter a layout name or [?] <Layout1>:
""
;Enter an output device name or [?] <AutoCAD PDF (General Documentation).pc3>:
"DWG To PDF.pc3"
;Enter paper size or [?] <ISO A4 (210.00 x 297.00 MM)>:
"ISO full bleed A1 (841.00 x 594.00 MM)"
;Enter paper units [Inches/Millimeters] <Millimeters>:
"Millimeters"
;Enter drawing orientation [Portrait/Landscape] <Portrait>:
"Landscape"
;Plot upside down? [Yes/No] <No>:
"No"
;Enter plot area [Display/Extents/Layout/View/Window] <Layout>:
"Extents"
;Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <1:1>:
"1:1"
;Enter plot offset (x,y) or [Center] <0.00,0.00>:
;"0.00,0.00"
"Center"
;Plot with plot styles? [Yes/No] <Yes>:
"yes"
;Enter plot style table name or [?] (enter . for none) <>:
"SAP_A1-A3.ctb"
;Plot with lineweights? [Yes/No] <Yes>:
"yes"
;Scale lineweights with plot scale? [Yes/No] <No>:
"no"
;Plot paper space first? [Yes/No] <No>:
"no"
;Hide paperspace objects? [Yes/No] <No>:
"no"
;name of plot file
(strcat PDF_PATH layoutname ".pdf")
;Save changes to page setup [Yes/No]? <N>:
"N"
;Proceed with plot [Yes/No] <Y>:
"Yes"
;Effective plotting area: 841.00 wide by 594.00 high
;Plotting viewport 1
);command
;;-----------------------------------------------------------------------------------------------------------------------;
;; Ends the for each loop
;;-----------------------------------------------------------------------------------------------------------------------;
);; Ends the for each loop
;;-----------------------------------------------------------------------------------------------------------------------;
;; END OF PLOT SETTINGS FOR A1 PDF IN COLOUR - SAP
;;-----------------------------------------------------------------------------------------------------------------------;
(setvar "filedia" 1)
(prompt (strcat "\n:: PDF saves in " PDF_PATH " | \\U+00A9 Faisal D " (menucmd "m=$(edtime,0,yyyy)") " ::\n"))

 

0 Likes
Message 4 of 30

Sea-Haven
Mentor
Mentor

The foreach may be incomplete or done easier by just getting layout names which includes "Model" hence just use (layoutlist) as it discards "Model" and is a list ready to go much less complicated than your lambda.

Here is another example.

(PROMPT ".....PRINTING DRAWING TO pdf's....")

(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
  (setq plotabs (cons (vla-get-name lay) plotabs))
)

(setq plottablist (acad_strlsort plotabs))

(setq len (length plottablist))

(setq x 0)
(repeat	len
  (setq name (nth x plottablist))
  (princ name)
(setq dwgname (strcat "C:/temp/alan-" name))
  (if (/= name "Model")
    (progn
      (setvar "ctab" name)
      
      (COMMAND "-PLOT"  "Y"  "" "Cutepdf Writer"
	       "A3"	"m"    "LANDSCAPE"	   "N"   "W"  "-6,-6"    "807,560"	"1=2"  "C"
	       "y"	  "Designlasercolour.ctb" "Y"	"n"    "n"    "y"   "N" "N" "y"      )
    )
  )
  (setq x (+ x 1))
)
(setvar "cmddia" 1)
(setvar "filedia" 1)
(princ)

 

0 Likes
Message 5 of 30

paullimapa
Mentor
Mentor

FYI: Core Console doesn't recognize (layoutlist) function 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

thanks for the responses.

 

it turns out the script works with my plot batcher in 2o24 if I use the default - Profile ie Civil metric or whatever it was. Quite strange, we have a custom profile at my company however there isn't really any significant changes from what I can tell that would stop it from working... and funny enough it seems to work with the custom profile in 2022 civil 3d anyway so double strange.

 

thanks for pointing that out Paul. I stuck with the lambda command and well it works as of the moment. Honestly a very baffling experience.

0 Likes
Message 7 of 30

paullimapa
Mentor
Mentor

I actually use a shorter function to get a list of all the layouts:

 

(foreach x (dictsearch (namedobjdict) \"ACAD_LAYOUT\")(if (and (= (car x) 3)(/= (cdr x) \"Model\"))(progn

 

but I would have to include this line thereafter to get the actual layout name:

 

(setq layoutname (cdr x))

 

As to why one profile works and not another I would check the profile that fails with Core Console under the following 2 areas of AutoCAD's Options > Files tab:

1.  Make sure both Support File Search Path & Trusted Locations are set with the folder where the script file is saved incase it's not local but in a network drive like your U: drive

2. Maker sure Plot Style Table Search Path includes the location where your custom "SAP_A1-A3.ctb" is saved

 

Other than being limited as to what lisp functions are supported Core Console is really picky when it comes to being able to locate support files to run successfully....cheers!!!

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

yeah its very strange. I've added it to the trusted location and in the working folders/support folders. For both profiles. I also added the ctb file location in the plotting table location as well for both profiles. I actually took it a step further and enabled the security to allow autolisp function. But it still doesn't seem to work with the custom profile haha. Really is interesting.

 

I've attached the image for reference if you notice anything missing

 

0 Likes
Message 9 of 30

paullimapa
Mentor
Mentor

I see that you have the 05-Plot Styles folder listed under both Support File Search Path & Trusted Locations but that really doesn't need to be there. Instead those ctb/stb files should be under Printer Support File Path > Plot Style Table Search Path:

paullimapa_0-1705534120934.png

Also I assume your cmd or batch file that fires up core console exe is using the proper version found under the respective AutoCAD version folders?

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

Yeah, I have added it to the plot table search path, as you mentioned below as well. I found when I was running it, the script was still failing when I didn't have the ctbs path in the trusted and support path locations however started working with the default profile once I added it in..not sure why lol.

 

I would assume the batcher is firing up correctly to run the 2024 core console version. I can't check specifically because the file is a fas file. However, given that it works with the default metric profile in 2024 I think it is safe to say that it is.

 

This is the source code I think which I've attached, however. for the batcher. FYI it is quite long but I think the important part is the first few lines. I didn't set this up initially so I'm not too familiar with how it works.

0 Likes
Message 11 of 30

paullimapa
Mentor
Mentor

Lots of Lee Mac functions in this lisp code which is great because that's one way to select multiple drawings to apply a script to. I've been developing my own as well but still a work in progress.

As you say the few lines at the top of the code tells me that since this is run from inside AutoCAD it should be located the proper Core Console exe to run.

I just used it to run a plot script file on a few drawings and the pdfs created flawlessly.

But then I'm just running plain AutoCAD....

FYI: Thanks for sharing the code.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

Yeah his stuff is great.

 

No problem, glad it works for you as well. If you come up with any ideas as to why it wouldn't work for the custom profile I'm all ears. But at this stage it is technically working as intended if I use the default profiles. I may just have to explain that to my team for now.

 

 

0 Likes
Message 13 of 30

paullimapa
Mentor
Mentor

If you feeling adventurous you could try this test.

Instead of all the commands being inside the script file basically they've been taken out and saved in this lisp:

PlotAllLayoutsD.lsp:

(defun c:PlotAllLayoutsD (/ PDF_PATH)
(command "_.TILEMODE" "0" "_.PDMODE" "0" "_.ZOOM" "_E" "-OSNAP" "_NONE" "_wipeout" "_f" "_off" "_.TEXTFILL" "1" "_.REGENALL")
(setq PDF_PATH "U:\\pdf location\\")
(if (not (vl-file-directory-p PDF_PATH))
(vl-mkdir PDF_PATH))
(foreach x (dictsearch (namedobjdict) "acad_layout")
 (if (and (= (car x) 3)
          (/= (cdr x) "Model")
     )
     (command "_.-PLOT" "_Y" (cdr x) "DWG To PDF.pc3" "ISO full bleed A1 (841.00 x 594.00 MM)" "_M" "_L" "_N" "_E" "1=1" "_Center"  "_Y" "SAP_A1-A3.ctb" "_Y" "_N" "_N" "_N" (strcat PDF_PATH "-" (cdr x) ".pdf") "_N" "_Y")
 )
)
(princ)
)

Then all that's needed in your script file is:

(load"PlotAllLayoutsD")
PlotAllLayoutsD

There's an extra line at then end to execute the lisp

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 30

Sea-Haven
Mentor
Mentor

Just a suggestion when checking for pdf directory exist we made the pdf directory as same location as the dwg, so in this case don't end up with hundreds of pdf's in one directory. The U: should work ok we saved to a server.

 

; check that pdf directory exists
(setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
(if (= (vl-file-directory-p dwgpre) nil)
(vl-mkdir dwgpre)
)

 

 

0 Likes
Message 15 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

ahh yes, I think a similar thing was done here. In that a lisp was creating using lee mac code. But then it was exported as a fas file so that it is unreadable/can't be edited etc. I just happen to be quite familiar with lee mac's work so am assuming this is the same code used lol. Mainly because when tested it works the same way.

0 Likes
Message 16 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

sorry not quite sure I follow what you are saying here.

 

The U drive is my personal drive on the server, so I have just made it so that the pdf location will be there. I guess the idea is that you would plot to here and then do your check prints as per usual and then when you are happy just save it to your folder for issue

0 Likes
Message 17 of 30

paullimapa
Mentor
Mentor

I believe the Lee Mac lisp code you posted simply does the drawing collection process and script file selection.

Then it launches Core Console assigning the selected script file to run cycling through each of the collected drawings.

What I'm hoping you'd try is instead of selecting that huge { A1 SAP STD Draft Plot Script } script file shown on your initial post, you simply select the couple of lines in the script file I posted that loads & runs all the commands within the lisp code which may cause your problem profile to succeed running Core Console.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

oh okay got you. So in this case with the code you provided do I make a new lisp function and just copy paste the code in? or is this meant to be an extension of the lee mac code to add alongside the core batcher?

0 Likes
Message 19 of 30

paullimapa
Mentor
Mentor

You would still use Lee Macs code to select drawings. But instead of selecting your huge script just select the three line script I posted. But make sure you save that short script file along with the lisp code I posted in a folder that’s in Support file search path and Trusted Location. The short script just loads my lisp which runs the same commands without all those comments and making it much shorter and hopefully more acceptable by core console to create plots. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 20 of 30

faisalWJ8Y9
Enthusiast
Enthusiast

Ok,

 

I just tested it. Seems to work fine with the default profile, however still falls over with the custom profile.

 

One other thing I noticed is that it puts a dashed at the start of the pdf name. Do you have an idea why? See attached.

 

0 Likes