vernonlee Posted January 7, 2015 Share Posted January 7, 2015 I needed to insert a block into many drawings at the same location. After some study, I am able to run this script with scriptpro. ATTREQ 1 ATTDIA 0 -INSERT "*d:\new block.dwg" 2527.1006043527,827.3694412067923 1 0 save y But the issue is i have 2 layout. The above script will only insert to the default layout only. Can someone advise how insert in both layout? Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 8, 2015 Share Posted January 8, 2015 Very simple the ctab variable can be used to change layouts so in your script (Setvar "ctab" "layout 2") and add Mspace Z E just in case your inside a layout viewport other wise it will insert in the model. NOTE must use brackets this is a mini lisp command in a script . Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 Very simple the ctab variable can be used to change layouts so in your script (Setvar "ctab" "layout 2") and add Mspace Z E just in case your inside a layout viewport other wise it will insert in the model. NOTE must use brackets this is a mini lisp command in a script . Ok. I will give it a shot. BTW, since you mention it is now a mini lisp command in a script, i can still run it with scriptpro? Thanks Quote Link to comment Share on other sites More sharing options...
steven-g Posted January 8, 2015 Share Posted January 8, 2015 You could use BIGAL's idea just adding the 2 lines to your script CTAB layout 2 I honestly don't know if it will make a difference, being an LT user I don't know the effects of adding lisp code to scripts Quote Link to comment Share on other sites More sharing options...
JamCAD Posted January 8, 2015 Share Posted January 8, 2015 Try replacing your insert part of the script with this. (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 8, 2015 Share Posted January 8, 2015 Sorry it will not work with LT Steven is correct just do it as a command you can do on one line if you like Ctab "layout 2" use " if you have spaces in layout name. Quote Link to comment Share on other sites More sharing options...
steven-g Posted January 8, 2015 Share Posted January 8, 2015 BIGAL I don't think the OP has LT I just added the comment for any possible LT users who may look-in :>) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 Hi guys. Thanks for the input. I am using autocad full version. I will try to study all inputs & see how to work it out. Thanks Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 Hi JamCAD. I add in as suggested in 2 different ways and i got errors for both. 1st way script ATTREQ 1 ATTDIA 0 -INSERT (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) 1 0 save y 1st way error Command: Command: _.SCRIPT Enter script file name : D:\Office\AutoCAD\Scripts\03_Insert Block___Testing\insert block script 2.SCR Command: ATTREQ Enter new value for ATTREQ : 1 Command: ATTDIA Enter new value for ATTDIA : 0 Command: -INSERT Enter block name or [?]: (foreach layout (layoutlist) (_> (setvar "ctab" layout) (_> (command "pspace") (_> (command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) Regenerating layout. Regenerating model. pspace "pspace.dwg": Can't find file in search path: C:\Windows\system32\ (current directory) D:\Office\AutoCAD\Scripts\03_Insert Block___Testing\ C:\Users\Vernon_Lee\appdata\roaming\autodesk\autocad 2014\r19.1\enu\support\ C:\program files\autodesk\autocad 2014\support\ C:\program files\autodesk\autocad 2014\support\en-us\ C:\program files\autodesk\autocad 2014\fonts\ C:\program files\autodesk\autocad 2014\help\ C:\program files\autodesk\autocad 2014\express\ C:\program files\autodesk\autocad 2014\support\color\ C:\program files\autodesk\applicationplugins\fusionplugin.bundle\contents\resources\ C:\program files\autodesk\applicationplugins\fusionplugin2013.bundle\contents\resources\ D:\office\autocad\lsp\ C:\programdata\autodesk\applicationplugins\autodesk importskp.bundle\contents\resources\ C:\Program Files\Autodesk\AutoCAD 2014\drv\ C:\Program Files\Autodesk\AutoCAD 2014\ *Invalid* ; error: Function cancelled Command: 2nd way script ATTREQ 1 ATTDIA 0 (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) 1 0 save y 2nd way error Command: Command: _.SCRIPT Enter script file name : D:\Office\AutoCAD\Scripts\03_Insert Block___Testing\insert block script 3.SCR Command: ATTREQ Enter new value for ATTREQ : 1 Command: ATTDIA Enter new value for ATTDIA : 0 Command: (foreach layout (layoutlist) (_> (setvar "ctab" layout) (_> (command "pspace") (_> (command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) pspace Already in paper space. Command: -insert Enter block name or [?]: d: ew block.dwg Invalid block name. ; error: Function cancelled Command: What did I do wrong? Try replacing your insert part of the script with this. (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 Got it working with this script. ATTREQ 1 ATTDIA 0 ctab A2 -INSERT "*d:\new block.dwg" 2527.1006043527,827.3694412067923 1 0 ctab A3 -INSERT "*d:\new block.dwg" 2527.1006043527,827.3694412067923 1 0 save y Thanks guys You could use BIGAL's idea just adding the 2 lines to your script CTAB layout 2 I honestly don't know if it will make a difference, being an LT user I don't know the effects of adding lisp code to scripts Very simple the ctab variable can be used to change layouts so in your script (Setvar "ctab" "layout 2") and add Mspace Z E just in case your inside a layout viewport other wise it will insert in the model. NOTE must use brackets this is a mini lisp command in a script . Sorry it will not work with LT Steven is correct just do it as a command you can do on one line if you likeCtab "layout 2" use " if you have spaces in layout name. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 8, 2015 Share Posted January 8, 2015 Two ways make lisp 1 line only unfortunately if it hits end of line before close bracket get error, (foreach layout (layoutlist)(setvar "ctab" layout)(command "pspace")(command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) second save the foreach as a lisp then script just has two lines this is a universal way of doing it can be used elsehwere (load "foreachtab") (foreachtab "d:\new block.dwg" "2527.1006,827.3694") (foreachtab (blknanme pt / ) (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "-insert" blkname pt "1" "0") ) ) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 OMG i realised something. All layout tabs are names differently across my lots of drawings. If this is the case, what is the solution? Quote Link to comment Share on other sites More sharing options...
JamCAD Posted January 8, 2015 Share Posted January 8, 2015 Try this ATTREQ 1 ATTDIA 0 (setq osnapsave (getvar "osnap")) (setvar "osnap" 0) (foreach layout (layoutlist) (setvar "ctab" layout) (if (/= 1 (getvar "cvport")) (command "pspace")) (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "0") ) (setvar "osnap" osnapsave) save y Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 9, 2015 Author Share Posted January 9, 2015 Hi JamCAD Tested the script as indicated but got this error:- Command: Command: _.SCRIPT Enter script file name : D:\Office\AutoCAD\Scripts\03_Insert Block___Testing\insert block script 5.SCR Command: ATTREQ Enter new value for ATTREQ : 1 Command: ATTDIA Enter new value for ATTDIA : 0 Command: (setq osnapsave (getvar "osnap")) nil Command: (setvar "osnap" 0) ; error: AutoCAD variable setting rejected: "osnap" 0 Command: (foreach layout (layoutlist) (_> (setvar "ctab" layout) (_> (if (/= 1 (getvar "cvport")) (command "pspace")) (_> (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "0") (_> ) Regenerating layout. Regenerating model. -insert Enter block name or [?]: d:\new block.dwg Substituting [simplex.shx] for [helv.shx]. Substituting [simplex.shx] for [universExtraBlack]. Units: Millimeters Conversion: 1.0000 Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]: 2527.1006,827.3694 Enter X scale factor, specify opposite corner, or [Corner/XYZ] : 1 Enter Y scale factor : 0 Value must be nonzero. ; error: Function cancelled Enter Y scale factor : *Cancel* Command: So i took out this 3 lines(setq osnapsave (getvar "osnap")) (setvar "osnap" 0) (setvar "osnap" osnapsave) And also added "1" for the Y scale This script now is this:- ATTREQ 1 ATTDIA 0 (foreach layout (layoutlist) (setvar "ctab" layout) (if (/= 1 (getvar "cvport")) (command "pspace")) (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "1" "0") ) (setvar "osnap" osnapsave) save y And manage to get it to work. All layouts regardless of name has the new block inserted. Thanks bro. But then kindly advise the purpose of the 3 lines of code & if it is necessary to prevent future errors & how to incoporate it to the script such that it can work correctly. Thanks again. Try this ATTREQ 1 ATTDIA 0 (setq osnapsave (getvar "osnap")) (setvar "osnap" 0) (foreach layout (layoutlist) (setvar "ctab" layout) (if (/= 1 (getvar "cvport")) (command "pspace")) (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "0") ) (setvar "osnap" osnapsave) save y Quote Link to comment Share on other sites More sharing options...
JamCAD Posted January 9, 2015 Share Posted January 9, 2015 Hi JamCAD Tested the script as indicated but got this error:- So i took out this 3 lines (setq osnapsave (getvar "osnap")) (setvar "osnap" 0) (setvar "osnap" osnapsave) And also added "1" for the Y scale This script now is this:- ATTREQ 1 ATTDIA 0 (foreach layout (layoutlist) (setvar "ctab" layout) (if (/= 1 (getvar "cvport")) (command "pspace")) (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "1" "0") ) (setvar "osnap" osnapsave) save y And manage to get it to work. All layouts regardless of name has the new block inserted. Thanks bro. But then kindly advise the purpose of the 3 lines of code & if it is necessary to prevent future errors & how to incoporate it to the script such that it can work correctly. Thanks again. Sorry, I'm trying to answer these questions on my phone and I'm not able to test it before I post. Those few lines of code are to disable the object snap so when you are inserting the block it doesn't accidentally snap to the incorrect point. I forgot that the system variable for the osnap settings is actually osmode. This should work now. ATTREQ 1 ATTDIA 0 (setq osnapsave (getvar "osmode")) (setvar "osmode" 0) (foreach layout (layoutlist) (setvar "ctab" layout) (if (/= 1 (getvar "cvport")) (command "pspace")) (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "1" "0") ) (setvar "osmode" osnapsave) save y Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 9, 2015 Author Share Posted January 9, 2015 Hi BIGAL, do not quite understand the process. I will just stick to the basic script instead Thanks for the help as well Two ways make lisp 1 line only unfortunately if it hits end of line before close bracket get error, (foreach layout (layoutlist)(setvar "ctab" layout)(command "pspace")(command "-insert" "d:\new block.dwg" "2527.1006,827.3694" "1" "0")) second save the foreach as a lisp then script just has two lines this is a universal way of doing it can be used elsehwere (load "foreachtab") (foreachtab "d:\new block.dwg" "2527.1006,827.3694") (foreachtab (blknanme pt / ) (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "-insert" blkname pt "1" "0") ) ) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 9, 2015 Author Share Posted January 9, 2015 NP bro. Appreciate the help. The revised script now works without issues. Thanks Sorry, I'm trying to answer these questions on my phone and I'm not able to test it before I post. Those few lines of code are to disable the object snap so when you are inserting the block it doesn't accidentally snap to the incorrect point. I forgot that the system variable for the osnap settings is actually osmode. This should work now. ATTREQ 1 ATTDIA 0 (setq osnapsave (getvar "osmode")) (setvar "osmode" 0) (foreach layout (layoutlist) (setvar "ctab" layout) (if (/= 1 (getvar "cvport")) (command "pspace")) (command "-insert" "d:\\new block.dwg" "2527.1006,827.3694" "1" "1" "0") ) (setvar "osmode" osnapsave) save y Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 9, 2015 Author Share Posted January 9, 2015 (edited) I also added this 3 lines to my initial script base on layout names:- (setq osnapsave (getvar "osmode")) (setvar "osmode" 0) (setvar "osmode" osnapsave) Script ATTREQ 1 ATTDIA 0 (setq osnapsave (getvar "osmode")) (setvar "osmode" 0) ctab A2 -INSERT "*d:\new block.dwg" 2527.1006043527,827.3694412067923 1 0 ctab A3 -INSERT "*d:\new block.dwg" 2527.1006043527,827.3694412067923 1 0 (setvar "osmode" osnapsave) save y Edited January 12, 2015 by vernonlee Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 10, 2015 Share Posted January 10, 2015 Thought this was discussed already OSMODE Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 10, 2015 Author Share Posted January 10, 2015 Thought this was discussed already OSMODE OMG. You are right. Now how did i copied the old code instead? WIll test it when back in office but i believe should be no issue now. 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.