BIGAL 发表于 2022-7-7 00:12:35

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")))

vernonlee 发表于 2022-7-7 00:16:07

OMG i realised something. All layout tabs are names differently across my lots of drawings.
 
If this is the case, what is the solution?

JamCAD 发表于 2022-7-7 00:18:28

Try this

ATTREQ 1ATTDIA 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)savey

vernonlee 发表于 2022-7-7 00:22:09

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 1ATTDIA 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)savey
 
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.
 
 
 
 
 
 
 
 

JamCAD 发表于 2022-7-7 00:23:28

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 1ATTDIA 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)savey

vernonlee 发表于 2022-7-7 00:26:31

Hi BIGAL,
 
do not quite understand the process.
 
I will just stick to the basic script instead
 
Thanks for the help as well
 

vernonlee 发表于 2022-7-7 00:31:44

NP bro. Appreciate the help.
 
The revised script now works without issues.
 
Thanks
 

vernonlee 发表于 2022-7-7 00:32:35

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 1ATTDIA 0(setq osnapsave (getvar "osmode"))(setvar "osmode" 0)ctabA2-INSERT"*d:\new block.dwg"2527.1006043527,827.369441206792310ctabA3-INSERT"*d:\new block.dwg"2527.1006043527,827.369441206792310(setvar "osmode" osnapsave)savey

BIGAL 发表于 2022-7-7 00:36:31

Thought this was discussed already OSMODE

vernonlee 发表于 2022-7-7 00:39:39

 
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.
页: 1 [2]
查看完整版本: HELP:Advise on script to inser