Jump to content

HELP:Advise on script to insert block to multiple drawings with more than 1 layout


vernonlee

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • vernonlee

    11

  • BIGAL

    5

  • JamCAD

    3

  • steven-g

    2

Top Posters In This Topic

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 .

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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? :oops:

 

 

 

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

Link to comment
Share on other sites

Got it working with this script. :shock:

 

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 :beer:

 

 

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 like

Ctab "layout 2" use " if you have spaces in layout name.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

OMG i realised something. All layout tabs are names differently across my lots of drawings.:cry:

 

If this is the case, what is the solution? :(

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Hi BIGAL,

 

do not quite understand the process.

 

I will just stick to the basic script instead :P

 

Thanks for the help as well :beer:

 

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

Link to comment
Share on other sites

NP bro. Appreciate the help.

 

The revised script now works without issues. :D

 

Thanks :beer:

 

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

Link to comment
Share on other sites

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 by vernonlee
Link to comment
Share on other sites

Thought this was discussed already OSMODE

 

OMG. You are right.

 

Now how did i copied the old code instead? :o :?

 

WIll test it when back in office but i believe should be no issue now. :oops:

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...