Autocad dies suddenly

Autocad dies suddenly

saitoib
Advocate Advocate
634 Views
5 Replies
Message 1 of 6

Autocad dies suddenly

saitoib
Advocate
Advocate

Hi all.

The following program converts a circle into a specified block.

 

When I changed the sub function from A to B, AutoCAD started to die suddenly.
It seems to stop at (command "-insert" block "" "" ""), but the contents of the block are the same and I don't know the cause.

Can you tell me what the cause is?

 

Help me.

A

(defun _replace
	(pt1 pt2
	 / dai block obj ent newss nn i pnt
	)

	(setq dai (getreal "\n target diameter is : "))
	(setq block (getstring "\nreplacement block name is : "))
	(setq dai (/ dai 2))
	(setq newss (ssget "_C" pt1 pt2 (list (cons 0 "circle") (cons 40 dai))))
	(setq nn (sslength newss))

	(setq i 0)
	(repeat nn
		(setq obj (ssname newss i))
		(setq ent (entget obj))
		(setq  pnt (cdr (assoc 10 ent)))
		(entdel (ssname newss i))
		(command "-insert" block pnt "" "" "")
		(setq i (+ i 1))
	)
	(princ)
)

B

(defun _replace
	(pt1 pt2 dai block
	/ obj ent newss nn i pnt
	)

	(setq dai (/ dai 2))
	(setq newss (ssget "_C" pt1 pt2 (list (cons 0 "circle") (cons 40 dai))))
	(setq nn (sslength newss))

	(setq i 0)
	(repeat nn
		(setq obj (ssname newss i))
		(setq ent (entget obj))
		(setq  pnt (cdr (assoc 10 ent)))
		(entdel (ssname newss i))
		(command "-insert" block pnt "" "" "")
		(setq i (+ i 1))
	)
	(princ)
)
Saitoib
0 Likes
635 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

One thing may what happens when the sssget is NIL there is no error check

 

 

(if (= newss nil)
(alert "No objects found ")
(progn
..........
)
)

Is Block a reserved word ? Maybe use bname

 

0 Likes
Message 3 of 6

saitoib
Advocate
Advocate

Thank you for your advice.
I changed the part you pointed out, but it didn't solve the problem.

 

There was one more point I forgot to mention.
It is that the B sub-function is called from the sub-function called from action_taile after the dialog is displayed.
I don't know if this has anything to do with it.

 

Is there anything else you can think of?

Saitoib
0 Likes
Message 4 of 6

hak_vz
Advisor
Advisor

You have two function codes, go from line to line and check what is missing, or what is not defined. This is the only way to learn programming.

In code A you have first line

(setq dai (getreal "\n target diameter is : "))

In code B first line is

(setq dai (/ dai 2))

 

In both codes variable dai is localized (don't exist as long is not assigned a value). In coda A you ask to enter that value, while in code B you don't, and directly start dividing that is equal to

(setq dai (/ nil 2))

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 6

saitoib
Advocate
Advocate

Thanks for the reply.

Originally, the code in A was to find the diameter of the target circle on the command line.
This has been working fine.

 

I would like to change this program.
I want to display a list of circles in a dialog list box and
Select one of these circles and pass it as an argument to the sub-function of B.

So, when I check in the watch window, both dai and block have the expected data.

 

Could it be that it is not possible to change the CAD screen elements while the dialog is displayed?

Though the sub-function that deletes all the selected circles from the list box in the same dialog is working fine.

 

The cause is unknown.

Saitoib
0 Likes
Message 6 of 6

saitoib
Advocate
Advocate

For the time being, I was able to solve the problem by drawing the shape after quitting the dialog display.

I still have some questions, so I will ask in another thread.

 

Thank you.

Saitoib
0 Likes