Trouble converting current dwg to template.

Trouble converting current dwg to template.

Patrick.Bissell
Explorer Explorer
306 Views
5 Replies
Message 1 of 6

Trouble converting current dwg to template.

Patrick.Bissell
Explorer
Explorer

Hi,

 

I am hoping to create a lisp that wblocks an incoming dwg into our 3D template. My approach is;

- Set units to m (if the drawing is already in m then there is one less command than if it comes in mm and hence there is a dummy step before which switches the dwg to decimeters in order to maintain the same amount of commands no matter what the original scale is. Would prefer to not have to do this)

- Wblock everything in the dwg to 'temp_block'

- Open up 3D template

- Paste in 'temp_block'

- Explode, purge and zoom extents

 

I can't seem to make the lisp paste into the current opened template. It wblocks fine and opens the template fine but then pastes the block back into the original dwg I tried to block out of. Essentially all the commands work I just need it to switch the current open dwg to the template. It worked fine as a script but all I can find online is that through lisps you can't change dwg?

 

Here is my script, I have hidden some parts of the filepaths etc for security:

 

(defun c:Block_DWG_3D ()
(setq blockPath (strcat "C:/Users/" username "/DC/ACCDocs/***COMPANY NAME***/Project Files/C3D/Civil3D/Scripts/temp_block.dwg")) ; Path of temp_block
(setq templatePath (strcat "C:/Users/" username "/DC/ACCDocs/**COMPANY NAME***/Project Files/C3D/Civil3D/Template/CIVIL 3D TEMPLATE.dwt")) ; Specify the path to your DWT template file
(command "-dwgunits" "5" "2" "4" "N" "Y" "N") ; Set dwgunits to a dummy scale(decimeters) otherwise there is the wrong number of commands when switching between mm and m
(command "-dwgunits" "6" "2" "4" "N" "Y" "N") ; Change back to m
(command "-wblock" blockpath "Y" "*")
(vl-load-com) ; Load the Visual LISP environment
(setq acadObj (vlax-get-acad-object)) ; Get the AutoCAD object
(setq documents (vla-get-Documents acadObj)) ; Get the Documents collection
(setq newDoc (vla-Add documents templatePath)) ; Create a new drawing from the template
(vla-Activate newDoc) ; Activate the new drawing
)


(command "FILEDIA" "1")
(command "MODEL") ; Go to modelspace
(setq blockPath (strcat "C:/Users/" username "/DC/ACCDocs/***COMPANY NAME***/Project Files/C3D/Civil3D/Scripts/temp_block.dwg")) ; Path of temp_block
(command "_INSERT" blockpath "0,0" "1" "1" "0")
(command "_.EXPLODE" "last") ; Explode the inserted block
(command "_.PURGE" "blocks" "temp_block" "N") ; Purge any previous instances of the block
(command "_zoom" "extents")
)

 

0 Likes
307 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor

As you’ve discovered that the limitation of lisp is that the code runs only in the current opened dwg. Why not include in your lisp code to write a script file (.scr) which at the end of the lisp code would execute the scriit command to run the script file which opens the template, inserts and then explodes the block?


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

Sea-Haven
Mentor
Mentor

Am I missing something ? You wblock using * which is an all option, so why not just open the dwg got to model space zoom e and use Ctrl+c to copy all objects. Then go to the template and paste to "original co-ordinates" this is the way we have done it for years no need for code.

 

I did play with OBDX not sure if Wblock is supported.

0 Likes
Message 4 of 6

Patrick.Bissell
Explorer
Explorer

Thanks for your reply, I'm currently using ACC and supposedly scripts can't be saved onto ACC but I'll have a try, we're hoping to run everything on lisps but if that's a limitation of a lisp then it is what it is.

0 Likes
Message 5 of 6

Patrick.Bissell
Explorer
Explorer

I want to do it all in one lisp hence the post.

0 Likes
Message 6 of 6

DGCSCAD
Collaborator
Collaborator

Start in the template drawing and insert the other one.

 

Call a LISP function to prompt for the drawing (or hard code it), which sets insunits, then inserts the dwg etc.. automagically from a pre-defined template that has all sysvars etc. already setup. To achieve this, you'll need to place this code in a ACADDOC.lsp or Startup Suite:

 

(if (and (= (getenv "LastTemplate") "Your_Drive:\\Your_Folder\\Your_3D_Template.dwt") (= (getvar "DWGTITLED") 0))
	(progn
		(load "Your_LISP")
		(c:Your_LISP)
	)
)

 

*Change the "Your_" names to suit.

 

Every time you start a drawing with that template, you'll run the "Your_LISP" routine.

AutoCad 2018 (full)
Win 11 Pro
0 Likes