Trouble converting current dwg to template.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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")
)