ENTMAKE crashes Autocad after call to VBA

ENTMAKE crashes Autocad after call to VBA

caddhelp
Explorer Explorer
455 Views
5 Replies
Message 1 of 6

ENTMAKE crashes Autocad after call to VBA

caddhelp
Explorer
Explorer

I have Fatal error on newer versions of Autocad

 

Lisp  function is calling VBA and then entmake crashes Autocad

The first lisp is calling VBA MsgBox. You will need to save dvb vile at c:\Temp\msgbox.dvb

The second(NewLine) is crashing on entmake

(defun MsgBox ( StringParam / retList ret )
	(setq retList '("None" "OK" "CANCEL" "ABORT" "RETRY" "IGNORE" "YES" "NO")) 
	(vl-vbaload C:\\Temp\\msbbox.dvb"))
	(setq ret(atoi(getstring(command "-VBARUN" "vbMsgBox" StringParam))))
	(nth ret retList) 
)

(defun NewLine()
  (msgbox "Create a New Line, 64, Title")
  (entmake (list'(0 . "LINE")(cons 10 (getpoint))(cons 11 (getpoint))))
)

 

This is a VBA code. Create a new VBA project and save it at c:\Temp\msgbox.dvb

 

Sub vbMsgBox()
  Dim arrParam, ret
  Param1 = ThisDrawing.Utility.GetString(False)
  arrParam = Split(Param1, ",")
  ret = MsgBox(arrParam(0), CInt(arrParam(1)), arrParam(2))
  ThisDrawing.SendCommand ret & vbCr
End Sub

 

We cannot use C# or VB.net. Only Autodesk VBA or VisualLisp

Any ideas? Does it crash only my Civil3D?

Thanks.

 

0 Likes
456 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

What about using @Lee_Mac 's LM:popup?

 

;; Popup  -  Lee Mac
;; A wrapper for the WSH popup method to display a message box prompting the user.
;; ttl - [str] Text to be displayed in the pop-up title bar
;; msg - [str] Text content of the message box
;; bit - [int] Bit-coded integer indicating icon & button appearance
;; Returns: [int] Integer indicating the button pressed to exit

(defun LM:popup ( ttl msg bit / wsh rtn )
    (if (setq wsh (vlax-create-object "wscript.shell"))
        (progn
            (setq rtn (vl-catch-all-apply 'vlax-invoke-method (list wsh 'popup msg 0 ttl bit)))
            (vlax-release-object wsh)
            (if (not (vl-catch-all-error-p rtn)) rtn)
        )
    )
)

(defun NewLine()
  (LM:popup "Title" "Create a New Line" 64)
  (entmake (list'(0 . "LINE")(cons 10 (getpoint))(cons 11 (getpoint))))
)

 

I would have two pieces of advice:
Avoid mixing programming environments (it is often much less simple than it seems)
Forget the AutoCAD VBA (personal opinion)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

hak_vz
Advisor
Advisor

Check this line

(vl-vbaload C:\\Temp\\msbbox.dvb"))

Change to

(vl-vbaload C:\\Temp\\msgbox.dvb"))

 Also, it is always better to check if all parameters for entmake are set

(entmake (list'(0 . "LINE")(cons 10 (getpoint))(cons 11 (getpoint))))

change to

(cond 
	((and (setq a (getpoint))(setq b (getpoint)))
		(entmake (list '(0 . "LINE")(cons 10 a)(cons 11 b)))
	)
)

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 4 of 6

caddhelp
Explorer
Explorer

Thank you for the responses. I really appreciate the brainstorming! 

 

MsgBox is just an example of using VBA. The real program is using huge Dialog with bunch of Combo Boxes and more.

The entmake here makes a single line is also a simplification. The real thing is creating a lot more, also using entmakex(hence the crush) to generate dictionaries.

 

 

(vl-vbaload C:\\Temp\\msbbox.dvb"))

Add open quote

(vl-vbaload "C:\\Temp\\msbbox.dvb"))

 

(entmake (list '(0 . "LINE")(cons 10 a)(cons 11 b)))

could be simpler

(entmake (list '(0 . "LINE")(cons 10 0 0 0)(cons 11 1 1 0)))

 

 

I did send the Autodesk Error report, but from my experience ;(

 

Keep digging!

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

Another msg box method.

 

(defun MsgBox (title buttons message time / return WshShell)
    (setq WshShell (vlax-create-object "WScript.Shell"))
    (setq return (vlax-invoke
            WshShell
            'Popup
            message
            time
            title
            (itoa buttons)
    ))
    (vlax-release-object WshShell)
    return
)

Another

(alert "this is a 2 line message \n2nd line")
0 Likes
Message 6 of 6

caddhelp
Explorer
Explorer

The call to MsgBox is just an example of Lisp->VBA->Lisp technique.

Mixing programing have been done forever with different languages.

I think the problem here is something to do with ENTMAKE. It could've been rewritten in C# so now it actually opens object for writing while VBA32 is still in the memory.

0 Likes