Jump to content

Recommended Posts

Posted (edited)

 I wrote a program to manipulate blocks overwriting them via the command "entmake":

 

; Block make
   (entmake (list (cons 0 "BLOCK") (cons 10 pt) (cons 2 bn) (cons 70 0)))
   (setq i (sslength ss))
   (while (>= i (setq i (1- i)) 0)
      (setq ent (ssname ss i) elist (entget ent))
      (entmake elist)
   )
   (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))

 

The program replaces correctly all the blocks keeping the same name but, after that, it hangs and it loops this message in the command line:

"Command:
Current settings: Object conversion=Delete
Enter name of output file:
Enter name of existing block or
[= (block=output file)/* (whole drawing)] <define new drawing>:"

 

I tried to modify the BLOCKCREATEMODE system variable but it doesn't affect this problem.

Any suggestion?

 

 

 

Edited by Marc_AM
Posted

Just stab in the dark...

Perhaps try changing (while) loop to (repeat) loop...

 

; Block make
   (entmake (list (cons 0 "BLOCK") (cons 10 pt) (cons 2 bn) (cons 70 0)))
   (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i))) elist (entget ent))
      (entmake elist)
   )
   (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))

 

  • Like 1
Posted (edited)

Think it is in this:

(while (>= i (setq i (1- i)) 0)

 

Like Marko, I very much go for keep it simple as much as I can. Add extra lines in so it is clearer what you are going

 

 

   (entmake (list (cons 0 "BLOCK") (cons 10 pt) (cons 2 bn) (cons 70 0)))
   (setq i (sslength ss))
   (while (> i 0)
      (setq ent (ssname ss i) elist (entget ent))
      (entmake elist)
      (setq i (- i 1))
   )
   (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))

 

EDIT:

Ignore that, loop should work OK, think it is block creation

 

 

 

My first line tends to be:

(0 . "BLOCK") (cons 2 Name) (cons 70 64) (cons 10 Origin)

 

(can't rememeber what the 70 - 64 represents). Sometimes the order is important

 

 My endblk

(entmakex '((0 . "ENDBLK")))

 

Once you end block I'm not sure if you can put it on a layer (cons 8 "0"), that would come from the insert command.

 

Edited by Steven P
Posted

I think the problem exists elsewhere in the program - it looks like an extra "" is perhaps being issued to the command line and repeating the WBLOCK command.

  • Like 1
Posted

shouldn't it be (cons 0 "INSERT")..?

Posted

I think you should show more of your code so we can understand what's going on.

Posted

Hello everyone,

this is the full code and a sample of drawing file in use.

 

(defun explodeinsert ()
   (setq w (ssname ss1 n))
   (setq a (entget w))
   (setq insertname (cdr (assoc '2 a)))
   (command ".-inser" insertname pt0 "" "" "")
   (setq ultimo (entlast))
   (ssadd ultimo ss2)
   (command "._explode" ss2 "")
   (ssdel ultimo ss2)
   (keepregion)
   (setq n (1- n))
)
(defun keepregion ()
   (setq ultimi (ssget "_p"))
   (setq n3 (1- (sslength ultimi)))
         (while (>= n3 0)
		    (progn
			   (setq w3 (ssname ultimi n3))
               (setq a3 (entget w3))
			   (setq name3 (cdr (assoc '0 a3)))
		       (if (= name3 "REGION")
			      (progn
				     (setq hatchlayer (cdr (assoc '8 a3)))
				     (ssadd w3 ss3)
				     (command "._explode" ss3 "")
					 (ssdel w3 ss3)
                     (setq ss (ssget "_p"))
                     (obj2blk1)					 
					 (entdel w3)
					)
                    (entdel w3)
		    	)
            )
           (setq n3 (1- n3))
         )
)
(defun obj2blk1 ()
; Block name and base point
   (setq bn insertname)
   (setq pt '(0 0))

; Block make
   (entmake (list (cons 0 "BLOCK") (cons 10 pt) (cons 2 bn) (cons 70 0)))
   (setq i (sslength ss))
   (while (>= i (setq i (1- i)) 0)
      (setq ent (ssname ss i) elist (entget ent))
      (entmake elist)
   )
;   (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
   (entmake (list (cons 0 "ENDBLK")))

; delete originals
   (command "._erase" ss "")
)


(defun c:test ()
   (setq ecocoms (getvar "cmdecho"))
   (setq osnapcoms (getvar "osmode"))
   (setvar "cmdecho" 0)
   (setvar "osmode" 0)
   (command "._zoom" "_a")

   (setq qaf (getvar "QAFLAGS"))
   (setvar "QAFLAGS" 1)
   (setq ss1 (ssget "X" '((0 . "INSERT"))))
   (setq ss2 (ssadd))
   (setq ss3 (ssadd))
   (setq n (1- (sslength ss1)))
   (setq totblocchi (1+ n))
   (setq pt0 '(0 0))
   (while (>= n 0) (explodeinsert))

   (command "._regen")
   (setvar "QAFLAGS" qaf)
   (princ)
   (command "._zoom" "_e")
   (command "._zoom" "0.97x")

   (setvar "osmode" osnapcoms)
   (setvar "cmdecho" ecocoms)

   (princ)
)

 

 

The block replacement works fine but, just after that, it hangs with this message in the command line:

"Command:
Current settings: Object conversion=Delete
Enter name of output file:
Enter name of existing block or
[= (block=output file)/* (whole drawing)] <define new drawing>:"

Disegno2.dwg

Posted

There are some very obvious spelling mistakes in your code: " (assoc '# " , "inser".... I think you should spend 5 minutes reviewing it yourself. It's easy: the AI will help you. Plus, it's easier for you.
And maybe that's enough to get your code working.

Try it.
If you can't get it, we'll be happy to help you 🙂

Posted
1 hour ago, GLAVCVS said:

There are some very obvious spelling mistakes in your code: " (assoc '# " , "inser"....

 

The "inser" is correct: I am working with a localized version of AutoCAD (Italian).

The AI suggests that my problem is related to (entmake (list (cons 0 "BLOCK") ...))

 

AI quote:

"you're creating a raw block definition. But if AutoCAD already has that block in memory, you're clashing with it."

 

AI is not able to give me a simple workaround to solve this problem.

Posted

Try using the VLIDE or Visual Studio Code to debug.

 

The only error I am getting is the block isn't on my computer.

 

None found.; error: bad argument type: lselsetp nil

 

Posted

@Marc_AM I've tested your code by changing the command to "_insert" and removing the quotes after assoc: the code runs correctly, redefining all the blocks.
Although I don't quite understand the final result.

Posted
4 minutes ago, GLAVCVS said:

@Marc_AM I've tested your code by changing the command to "_insert" and removing the quotes after assoc: the code runs correctly, redefining all the blocks.
Although I don't quite understand the final result.

 

Yes, the code runs correctly also on my side but at the end it hangs and it loops this message in the command line:

"Command:
Current settings: Object conversion=Delete
Enter name of output file:
Enter name of existing block or
[= (block=output file)/* (whole drawing)] <define new drawing>:"

 

Don't you have this message at all?

Posted

No
What version of AutoCAD are you using?

2025? 

Posted

I'll try it again this afternoon with AutoCAD 2021.

Posted
2 minutes ago, GLAVCVS said:

No
What version of AutoCAD are you using?

2025? 

 

AutoCAD 2024.

Posted

I think there might be a problem with blocks whose name begins with "_" ("_NESTBLK_1", for example):
AutoCAD might interpret it as part of the localization system (English command).
From what little I've seen, it seems that, depending on the version of AutoCAD, this could be a problem.
I think it would be a good idea to replace (command "_insert"... ) with ENTMAKE.

Posted

Try replacing

(command "inser" insertname pt0 "" "" "")

by

(entmake (list '(0 . "INSERT") (cons 2 insertname) (cons 10 pt0) '(41 . 1) '(42 . 1) '(43 . 1) '(50 . 0)))

 

  • Thanks 1
Posted
14 hours ago, GLAVCVS said:

Try replacing

(command "inser" insertname pt0 "" "" "")

by

(entmake (list '(0 . "INSERT") (cons 2 insertname) (cons 10 pt0) '(41 . 1) '(42 . 1) '(43 . 1) '(50 . 0)))

 

 

I'm testing your suggestion and it works fine: no more errors. I could never have imagined that this was a localization-related problem.

 

Thank you.

  • Marc_AM changed the title to Program hanging after modyfing blocks (solved)
Posted

FWIW, to avoid localisation issues, use the underscore command prefix ("_") when supplying commands and command options in LISP, e.g.:

(command "_.-insert" ...)

 

Here:

  • "_" means use the English command name, independent of the localisation of the application in which the program is being executed (i.e. (command "_LINE" ...) will always issue the LINE command in any language-version of AutoCAD, regardless of the translation of LINE).
  • "." means use the original, non-redefined, version of the command (i.e. even if the user has redefined the LINE command, (command ".LINE" ...) will use the original version of the command).
  • "-" means use the command-line version of the command (where available).

The "_" and "." prefixes can be combined in any order, e.g. (command "._LINE" ...) and (command "_.LINE" ...) will have the same effect.

  • Like 1

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...