Trying to write a script

Trying to write a script

Anonymous
Not applicable
1,222 Views
9 Replies
Message 1 of 10

Trying to write a script

Anonymous
Not applicable

Hi all

 

This is my first time trying a script so go easy on me. My intent is to open a couple hundred files and replace the titleblock. Could and expert take a look at what i have put together down below and tell me what im doing wrong?

 

What i am getting from this is:

1. a new folder named new

2. autocad opens up

3. says cannot find file name

 

Step 1 = script file

 

INSERTcompany P&IDTblk=e:\bctest
0,0 1 1 0
ERASE L

(load "e:\\bctest\\bctest_update.lsp")
bctest_update
QUIT
Y

 

step 2 = batch file

 

md e:\bctest\new
for %%f in (e:\bctest\A*.dwg) do START/WAIT c:\"program files"\"autodesk"\"Autocad 2015"\acad.exe "%%f"/b e:\bctest\bctest_update.scr

 

step 3 = lisp program

 

(defun e:bctest_update(/ dn pa panbdn)
(setq dn (getvar "dwgname"))
(setq pa (getvar "dwgprefix"))
(setq panbdn (strcat pa "new\\" dn))
(command "save" panbdn )
)

0 Likes
1,223 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous.shanks wrote:

.... 

Step 1 = script file

 

INSERTcompany P&IDTblk=e:\bctest
0,0 1 1 0
ERASE L

(load "e:\\bctest\\bctest_update.lsp")
bctest_update
QUIT
Y

 

....

On the Script part, I notice a couple of things:

 

If "INSERTcompany" is not a custom defined command name, and you mean it to be an INSERT command, you are missing a space after it.  And if the Block name has a space in it, it will need to be wrapped in double-quotes, or AutoCAD's going to think "company" by itself is the Block name:

 

INSERT "company P&IDTblk"=e:\bctest

 

[I'm not sure without trying it whether maybe the whole blockname=filename stretch should be in double-quotes together: "company P&IDTblk=e:\bctest".]

 

Also, you will need another return to complete the selection for the Erase command.

Kent Cooper, AIA
0 Likes
Message 3 of 10

doni49
Mentor
Mentor

In addtion to Kent's advice:

  • If the block already exists in the dwg file when you try to do this insert, acad will prompt you asking whether or not to redefine the block.  So you will need to respond Y in that case.  (if you know that will ALWAYS be true, then you can safely just add the Y response).
  • I'm not sure but I believe you can just cancel out of the insert command instead of placing the block and then deleting it.  By that time the block should already have been redefined (assuming you provided the Y response as noted above).


Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 4 of 10

Anonymous
Not applicable
Kent - ok so i've edited it to look like this. But still getting the same error " cannot find specified drawing file"

Step 1 = script file

INSERT "company P&IDTblk"=e:\bctest
0,0 1 1 0
ERASE L

(load "e:\\bctest\\bctest_update.lsp")
bctest_update
QUIT
Y

step 2 = batch file

md e:\bctest\new
for %%f in (e:\bctest\A*.dwg) do START/WAIT c:\"program files"\"autodesk"\"Autocad 2015"\acad.exe "%%f"/b e:\bctest\bctest_update.scr

step 3 = lisp program

(defun e:bctest_update(/ dn pa panbdn)
(setq dn (getvar "dwgname"))
(setq pa (getvar "dwgprefix"))
(setq panbdn (strcat pa "new\\" dn))
(command "save" panbdn )
)


Doni49 - Where would i put the Y that your recommending?
0 Likes
Message 5 of 10

doni49
Mentor
Mentor

Try INSERT "company P&IDTblk=e:\bctest".  And are you certain that e:\bctest.dwg does actually exist (i.e. there could be a typo).

 

Type in (Findfile "e:\\bctest.dwg") at the command prompt.  If it returns nil, then it's unable to find that file for some reason.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 6 of 10

doni49
Mentor
Mentor

@Anonymous.shanks wrote:
Doni49 - Where would i put the Y that your recommending?

The following was copy/pasted when I did something similar here -- the block name and filename/path are different.  But the block does exist and the file does exist.  So when I ran it, acad prompted me asking if I wanted to redefine the block.  I answered Y.  Then instead of actually providing an insertion coordinate, I canceled out of it -- but at that point, the block had already been redefined.

 

Command: -insert Enter block name or [?]: "_ClosedBlank=N:\CAD\Shared\Content\Symbols Library\General\DetailMarkA.dwg"
Block "_ClosedBlank" already exists. Redefine it? [Yes/No] <N>: y
Block "_ClosedBlank" redefined
Units: Inches   Conversion:    0.0833
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: *Cancel*



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous.shanks wrote:
Kent - ok so i've edited it to look like this. But still getting the same error " cannot find specified drawing file"

Step 1 = script file

INSERT "company P&IDTblk"=e:\bctest
....
(load "e:\\bctest\\bctest_update.lsp")
....

Doni49 - Where would i put the Y that your recommending?

That (load) function makes it look like bctest on the e: drive is a folder, rather than a drawing.  Insert can't bring a folder in, only a drawing.  Unless there's also a drawing called bctest.dwg in the e: root directory, then you're missing a drawing file name, and it should be:

 

INSERT "company P&IDTblk"=e:\bctest\SomeDrawing

 

The Y would go right after that, if there will always already be a Block named "company P&IDTblk" in the drawing, because that's where it's going to ask you whether you want to redefine it.  And I agree, you could just have it cancel the insertion once you've agreed to redefine it, rather than go through with it and then Erase it.  Something like:

 

INSERT "company P&IDTblk"=e:\bctest\SomeDrawing Y ^C^C

 

and then immediately into the (load) function.

Kent Cooper, AIA
0 Likes
Message 8 of 10

Anonymous
Not applicable

Ok still not working here is what i have up to this point. I have all files and dwgs in a folder named bctest on my c: drive(c:\bctest). I'll make an example list below.

 

a.102.0.01.dwg

a.103.1.07.dwg

a.104.1.01.dwg

etc.......

company P&idTblk.dwg

bctest_update.bat

bctest_update.lsp

bctest_update.scr

 

script file

 

INSERT "kbi P&IDTblk"=c:\bctest\A* Y ^C^C
0,0 1 1 0
ERASE L

(load "c:\\bctest\\bctest_update.lsp")
bctest_update
QUIT
Y

 

lisp file

 

(defun c:bctest_update(/ dn pa panbdn)
(setq dn (getvar "dwgname"))
(setq pa (getvar "dwgprefix"))
(setq panbdn (strcat pa "new\\" dn))
(command "save" panbdn )
)

 

batch file

 

md c:\bctest\new
for %%f in (c:\bctest\A*.dwg) do START/WAIT c:\"program files"\"autodesk"\"Autocad 2015"\acad.exe "%%f"/b c:\bctest\bctest_update.scr

 

 

When i initiate the bat file it creates a folder named new, opens up acad, then cannot find any of the files.

 

I've attached a snapshot of the errors that come up

 

Sorry this is dragging out so long. I am new to all of this. thanks for your help.

 

 

0 Likes
Message 9 of 10

Anonymous
Not applicable

kbi p&idtblk.dwg is the file name

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous.shanks wrote:

.... 

a.102.0.01.dwg

a.103.1.07.dwg

a.104.1.01.dwg

etc.......

company P&idTblk.dwg

.... 

script file

 

INSERT "kbi P&IDTblk"=c:\bctest\A* Y ^C^C
0,0 1 1 0
ERASE L

(load "c:\\bctest\\bctest_update.lsp")

....


That INSERT line looks like it's going after multiple drawing names, which of course Insert cannot use as a source for a Block redefinition.  Shouldn't it be something like:

 

INSERT "kbi P&IDTblk"=c:\bctest\a.102.0.01 Y ^C^C

 

instead?

 

Then, if you cancel it before completing the Insertion [and come to think of it, I don't recall whether ^C works as a cancel in a Script, the way it does in a command macro], then as described before, you must leave out the insertion point/scales/rotation and the Erase Last part, and go straight to the (load) function.

Kent Cooper, AIA
0 Likes