Block insert routine Autocad 2019

Block insert routine Autocad 2019

REALJOHNFROST
Explorer Explorer
422 Views
7 Replies
Message 1 of 8

Block insert routine Autocad 2019

REALJOHNFROST
Explorer
Explorer

Hie, 

I am a novice lisp programmer. I am trying to make a routine to insert a block from other file. When i run the routine i receive a warning "Unable to insert a dependent block" and i don´t understand why.

Could you help me?

Regards.

 

(defun c:7B ()

(setq blkPath "C:\\Users\\xxx\\Dropbox\\Bloques.dwg")


(setq blkName "BQ_xxxx")


(command "_.-INSERT" (strcat blkPath "|" blkName) "0,0,0" 1 1 0)


(if (tblsearch "BLOCK" blkName)
(princ "\nBloque cargado correctamente. Ahora puedes insertarlo manualmente.")
(princ "\nError: No se pudo cargar el bloque.")
)

(princ)
)

0 Likes
Accepted solutions (1)
423 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant

Hi,

this command would trying to use a block from an Xref (xref Bloques, block BQ_xxx = "Bloques|bq_xxxx"

 

 

INSERT command can insert a blockreference of an internal block,

or you can create a block by insert another .dwg as block.

 

What you try is to use a block what is defined inside another .dwg.

Use command INSERTCONTENT instead INSERT

 

Read about both in [F1]

 

 

Sebastian

Message 3 of 8

REALJOHNFROST
Explorer
Explorer

Thanks so much. The problem is that command appeared in Autocad 2021 and i use 2019.

Regards.

0 Likes
Message 4 of 8

cadffm
Consultant
Consultant

Oups!

You running ACAD2019?

Sorry, INSERTCONTENT is a new command in ACAD2021, so you can't use it in 2019.

 

What you can do in 2019:

 

v1: Extract your Block(s) as separate .dwg file

Open Bloques.dwg, run WBLOCK, option Block, select your Block, select your target file [OK] (DO NOT CHANGE ANYTHING ELSE)

   This way you create a file "BQ_xxxx" and now, you can INSERT this file (as Block).

 

  You will find some tool like "WBLOCK ALL" to extract all blocks as separate .dwg file

 

another way

v2: You can INSERT "Bloques.dwg" as Block

Cancel the last INSERT-steps, instead of basepoint, send (command)

(setq blkPath "C:\\Users\\xxx\\Dropbox\\Bloques.dwg")


(setq blkName "BQ_xxxx")


(command "_.-INSERT" blkPath)(command)

and then insert a blockreference of you block

(command "_.-INSERT" blkName "0,0,0" 1 1 0)

 

and run -PURGE to delete the unused stuff from Bloques

 

 
 

 

 

Sebastian

Message 5 of 8

cadffm
Consultant
Consultant

This post is for ACAD2021 and newer User ONLY:

 

INSERTCONTENT [F1]

 

 

Check the command workflow manually

Command: -INSERTCONTENT
External file path:D:\MyPath\MyBlockLib.dwg
Block name or [?]MyBlockName


Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate/Explode/REpeat]:0,0
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>:1
Enter Y scale factor <use X scale factor>:1

Specify rotation angle <0>:0

Command:

 

all inputs packed into a command statement, results

(command "-INSERTCONTENT" "D:\\MyPath\\MyBlockLib.dwg" "MyBlockName" "0,0,0" 1 1 0)

 

or force to work in all international language versions, forces the oiriginal command, insert in WCS 0,0,0:

(command "_.-INSERTCONTENT" "D:\\MyPath\\MyBlockLib.dwg" "*0,0,0" 1 1 0)

 

 

Sebastian

0 Likes
Message 6 of 8

REALJOHNFROST
Explorer
Explorer

Thanks! I try step by step and i have a warning when i execute this code. The warning is wrong function and appear and strange folder in the command line: "C:UUsersXXXDesktop@1BLOQUEDIN_7982.dwg", is like not understand the folder or somthing like that.

(defun c:8T ()
(princ)
;; Ruta del archivo que contiene los bloques
(setq blkPath "C:\Users\XXX\Desktop\1001\BLOQUE\DIN_7982.dwg")

;; Nombre del bloque a cargar
(setq blkName "DIN_7982")

;; Cargar el bloque desde el archivo externo
(command "_.-INSERT" (blkPath))
;;(command "_.-INSERT" (blkname "0,0,0" 110)

)

0 Likes
Message 7 of 8

cadffm
Consultant
Consultant
Accepted solution

Hi,

 

basic rule in lisp(strings), a backslash is a controle character! If you want a backslash in strings, like in your path,

you have to quote them.

How? Backslash is the controle character for quote, so you need a double backslash

\\ instead of \

for path informations, you can also use a Slash /

 

See your or my samples above!

 

 

 

Another issue in your code is (blkPath).

Without explaination, use blkPath, without ( )

 

(command "_.-INSERT" blkPath)

Followed by (command)

to cancel the insert command.

 

Later, if it works

(command "_.-INSERT" blkname "0,0,0" 1 1 0)

Sebastian

Message 8 of 8

REALJOHNFROST
Explorer
Explorer

It works! Thanks so much!

0 Likes