wayne murphy Posted March 6, 2015 Share Posted March 6, 2015 (edited) Hi I am new to this forum. I have been using lisp for a while, but not great at writing complex ones. In this case I want to combine two lisps. The first opens a template, the second executes a query from a drawing attached to the template, and unattaches the file once complete. I would like to have these in one command so it will open the drawing , execute the query, unattach, then zoom to extents. They work well seperatly, but would be a time saver and save my users steps if combined. I have a swore head from beating against wall, I don't know what I am missing, but would appreciate any segestions or help. Lisp 1 (defun c:openD_NS&PEI nil (vla-open (vla-get-documents (vlax-get-acad-object)) "V:\\symbol\\smt\\Construction_blocks\\1-01_D_SIZE_CONSTRUCTION_PACKAGE_TEMPLATE - Nova Scotia.dwg":vlax-false)) Lisp 2 (defun c:executequery (/)(ade_errsetlevel 2)(ade_qryexecute) (foreach x (ade_dslist) (ade_dsdetach x))(command ".zoom" "e"))) Edited March 9, 2015 by wayne murphy Requested by admin Quote Link to comment Share on other sites More sharing options...
sergiu_ciuhnenco Posted March 6, 2015 Share Posted March 6, 2015 Please read the Code Posting Guidelines and edit your post to include the Code in Code Tags. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 7, 2015 Share Posted March 7, 2015 Maybe something like this but save as a script SCR scripts can handle the open dwg and keep going. (defun c:OpenD_NS&PEI nil (vla-open (vla-get-documents (vlax-get-acad-object)) "V:\\symbol\\smt\\Construction_blocks\\1-01_D_SIZE_CONSTRUCTION_PACKAGE_TEMPLATE - Nova Scotia.dwg":vlax-false) (ade_errsetlevel 2) (ade_qryexecute) (foreach x (ade_dslist) (ade_dsdetach x))(command ".zoom" "e")) ) Quote Link to comment Share on other sites More sharing options...
wayne murphy Posted March 9, 2015 Author Share Posted March 9, 2015 I had already tried that and it did not work. Loaded the template, but stoped there. I found the following lisp that worked better for opening the template: (defun c:open11x17_NS&PEI (/ cd vgad vgao vgd) (vl-load-com) (setq vgao (vlax-get-acad-object)) (setq vgad (vla-get-activedocument vgao)) (setq vgd (vla-get-documents vgao)) (setq cd "V:/symbol/smt/Construction_blocks/1-0_11x17_SIZE_CONSTRUCTION_PACKAGE_TEMPLATE - Nova Scotia.dwg") (if (= 0 (getvar "SDI")) (vla-activate (vla-open vgd cd)) ; if sdi = 0 (vla-sendcommand vgad (strcat "(command \"_open\")\n" cd "\n")(ade_errsetlevel 2)(ade_qryexecute) (foreach x (ade_dslist) (ade_dsdetach x))(command ".zoom" "e")); if sdi = 1 ) ; if (princ) ) and would still like it to run this lisp once the template is open (defun c:executequery (/)(ade_errsetlevel 2)(ade_qryexecute) (foreach x (ade_dslist) (ade_dsdetach x))(command ".zoom" "e"))) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 10, 2015 Share Posted March 10, 2015 If you want it to run automatically then just add the lisp to ACADDOC.lsp or add via Appload to your history so it autoloads. Make sure you add an extra line outside the defun (c:executequery) and it will run but also allow you to do manually. Quote Link to comment Share on other sites More sharing options...
wayne murphy Posted June 23, 2015 Author Share Posted June 23, 2015 Thanks for the solution. This worked well for me. I placed the code shown below in the acaddoc and it worked. however I would like to only detach a specific file that is attached to my template. I have tried putting the path in the lisp (replaced the x), but it is not detaching it, nor is it giving me errors or any other problems. How would I specify a specific file. The line below is what I have tried. (ade_errsetlevel 2)(ade_qryexecute) (foreach x (ade_dslist) (ade_dsdetach C:\\Temp folder extract from spatial\\File saved from Spatial.dwg))(command ".zoom" "e") Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.