Need help with a basic script to insert a block from a resource file

Need help with a basic script to insert a block from a resource file

acadadmin3KNUF
Advocate Advocate
1,709 Views
12 Replies
Message 1 of 13

Need help with a basic script to insert a block from a resource file

acadadmin3KNUF
Advocate
Advocate

Hello to all:  

 

I am trying to use scripting to insert blocks from a resource file into a dwg.  My starting code is this:

 

^C^C_insert;"ResourceFile";^C-insert;"*Block_1";0,0;;;

 

The script runs, but nothing happens...then I press ENTER and get the "unknown ccommand message.  I'm attaching a pic that shows all my source info.  Do i have the support path wrong?..., that's the only thing I can think of.  Thanks for any help 😀

0 Likes
Accepted solutions (2)
1,710 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

Try it without the quotation marks.  They're not needed in a command macro.  And you may need an additional semicolon at the end [your first completes the insertion point, second and third for X and Y scale factors, but nothing for rotation], unless the Block is defined for uniform scaling.

 

I assume the unknown command message tells you what the unknown command was -- fill us in.

Kent Cooper, AIA
0 Likes
Message 3 of 13

acadadmin3KNUF
Advocate
Advocate

Here is exactly what the command line gives in return.

output.JPG

0 Likes
Message 4 of 13

paullimapa
Mentor
Mentor

First of all it looks like you are in the drawing called ResourceFile.dwg and you're trying to insert a drawing that has the same name which AutoCAD won't let you do.

Second the sequence of commands you show in Notepad is NOT a script file but a macro that will only run when placed inside a menu button.

A script file containing this sequence of commands would look something like this (note the extra return after last line):

_.-insert ResourceFile _SC 1 0,0 0
_.Erase L

_.-insert *Block_1 0,0 1 0

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 13

Sea-Haven
Mentor
Mentor

Uisng a lisp you can check does block_1 exist in this dwg, if not then go insert Resourcefile.

(if (=  (tblsearch "BLOCK" "block_1") nil)
(command "-insert" ResourceFile "_SC" 1 0,0 0)
)
(Command "-insert" "Block_1" 0,0 1 1 0)

 

0 Likes
Message 6 of 13

acadadmin3KNUF
Advocate
Advocate

Yeah I discovered that thing about the macro having to be inside a command on a menu button; i found that out after I posted the question and couldn't delete it.  I couldnt get your script text to work though.

0 Likes
Message 7 of 13

acadadmin3KNUF
Advocate
Advocate

Thanks to all that replied; I'm going to get some help from my ACAD provider tomorrow.

0 Likes
Message 8 of 13

paullimapa
Mentor
Mentor

Script files run by entering at AutoCAD's command prompt:

SCRIPT 

The Select Script File window appears showing you all files with extension .SCR

Select the Script file you want to run.

In this case I named the script file ResourceFile.scr then click the Open button

paullimapa_0-1733200869528.png

Note the drawing file is named Drawing1.dwg and does not match with the name of the Block you want to insert ResourceFile.dwg

AutoCAD will then run the commands as you entered them in the Script file:

paullimapa_1-1733200976649.png

In this case I changed the Script file from my last post to look like this:

(defun script-cancel ()(command)(command "resume"))
_.-insert ResourceFile 0,0
(script-cancel)
_.-insert *Block_1 0,0 1 0

The Script first defines a lisp function called script-cancel that would cancel the current active command and continue to resume with the next commands in the Script.

Then the Script executes the Insert command as you showed in your menu macro.

After entering the insertion point of 0,0 the Script runs the (script-cancel) function to cancel the remainder of the Insert prompts and continues to Resume to the next Insert command sequence in the Script.

Since the forum does not support the attachment of Script files, I've attached the entire Script file using extension .txt. When you save the attachment just rename the file as ResourceFile.scr. Then AutoCAD's Script command will see this in the Select Script File window.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 13

paullimapa
Mentor
Mentor

FYI, you may be interested in reading one of my recent articles I wrote on the topic of using Script files in AutoCAD:

AUGIWORLD by AUGI, Inc. - Issuu


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 13

acadadmin3KNUF
Advocate
Advocate
Accepted solution

-insert
C:/Users/matthew.neesley/Desktop/ACAD_Insert_Test/ResourceFile.dwg
0,0

 

1
0

 

The above text got me what I needed.

0 Likes
Message 11 of 13

paullimapa
Mentor
Mentor

Your macro that you posted also includes insert *block_1


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 13

acadadmin3KNUF
Advocate
Advocate
Accepted solution

Ok.  I'm really gonna throw you ALL for a loop.  Here's what I REALLY NEEDED, ALL of it 😁

 

-insert
C:/Users/matthew.neesley/Desktop/ACAD_Insert_Test/ResourceFile.dwg
0,0

 

1
0
erase
L

 

insert
Block_1
0,0
1

 

purge
b
ResourceFile
y
y

 

 

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

As suggested on other posts same task using Lee-mac Steal.lsp will do what you want just pulling the one block from another dwg. It only requires like 2-3 lines of code, you just load Lee's Steal then run the call for the required block.

(if (not stealall )(load "StealV1-8.lsp"))
(Steal "C:\\My Folder\\MyDrawing.dwg" 
   '(("Blocks" ("Block_1")))
)       

I will leave it to you to download the latest version of steal.lsp.

 

 

 

0 Likes