Lisp Error- No Function Definition

Lisp Error- No Function Definition

rmordov
Participant Participant
8,363 Views
12 Replies
Message 1 of 13

Lisp Error- No Function Definition

rmordov
Participant
Participant

I am running into the following error when attempting to use a custom lisp. "Error: no function definition: VLAX-ENAME->VLA-OBJECT" I found a few other posts regarding no function defintion but all were more customized to the specific lisp. I am newer to C3D and don't know much about writing my own lisp codes but have found several I use often. I've used this same lisp in the same drawing I'm getting the error in multiple times and have never run into this issue. Any ideas what might cause this problem out of nowhere? Thanks in advance!

 

The code is as follows:

(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
(vl-load-com)
(cond
;;Select the text/mtext objects
((or
(null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
(= 0 (setq ssl (sslength ss1)))
)
nil ;nothing selected
)
(T
(setq
Textobj (vlax-ename->vla-object (ssname ss1 0))
ActSpace (if (= 0 (getvar "cvport"))
(vla-get-paperspace
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-get-modelspace
(vla-get-activedocument (vlax-get-acad-object))
)
)
StartPt (getpoint "\nPick location for point of arrow head: ")
txt (vla-get-TextString Textobj)

TextPt
(vla-get-insertionpoint textobj)
TextPt
(vlax-variant-value TextPt)
TextPt
(vlax-safearray->list TextPt)
ptlist
(vlax-make-safearray
vlax-vbdouble
'(0 . 5)
)
ptlist
(vlax-safearray-fill ptlist (append StartPt TextPt))
MLObj
(vla-addmleader
ActSpace
ptlist
'LeaderIndex
)
)
(vla-put-textstring mlobj txt)
(vla-delete Textobj)

)
)
)

Error Code.PNG

0 Likes
8,364 Views
12 Replies
Replies (12)
Message 2 of 13

RobDraw
Mentor
Mentor

Have you tried asking over in the LISP and Customization forum?


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
0 Likes
Message 3 of 13

rmordov
Participant
Participant

I am also new to trying to use the forums correctly... I will post over there now. Thanks!

0 Likes
Message 4 of 13

dbroad
Mentor
Mentor

Try adding (vl-load-com) before your code.  If that doesn't work, we'd need to know more about your setup (version, profile, recent reinstallation, computer type (PC vs MAC).

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 13

rmordov
Participant
Participant

I think (vl-load-com) is already at the beginning of the code? The problem appears to be specific to this particular lisp (others I have on hand seem to work fine) I did do a reinstall a couple months ago but I have definitely used the lisp after that was complete. I'm using C3D 2020 but it's on a work computer (PC) so I'm not totally sure if any updates would have been done without my knowledge. Would an update be able to render the lisp inoperable?

0 Likes
Message 6 of 13

dbroad
Mentor
Mentor

Actually (vl-load-com) isn't at the top of the code as you might think. Neither is the program being defun'ed as you might think. Given this code snippet.

 

(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
(vl-load-com)
....

 

The alias for the program, which is what you are probably using most of the time is being defined to execute a function that doesn't exist (unless it's been previously loaded).  The (vl-load-com) is nested into the long form of the user defined function, which is a horrible location.  If in doubt about whether Active-X functions have been loaded, put the (vl-load-com) statement outside any user defined function, preferably as the first statement of the lisp file.

 

To be clearer,

(defun c:mlte (/) (c:MLeaderToExistingtext))

is equivalent to 

(defun c:mlte (/) (function_doesn't_exist))

IOW, it will cause an error immediately unless the file has been loaded before.

 

Always put aliases at the end of a file, never at the beginning.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 7 of 13

hak_vz
Advisor
Advisor

@rmordov

For me, code worked instantly without any problem. In newer version (vl-load-com) is loaded at startup. It is not a problem if code tries to load it again, it won't run if already loaqded.

 

I didn't change a thing in a code, just localized variables and rearranged function calls. I hope it will work.

 

(vl-load-com)
(defun MLeaderToExistingtext (/ ss1 Textobj ActSpace StartPt txt TextPt ptlist MLObj ) 
	(cond
		;;Select the text/mtext objects
		((or (null (setq ss1 (ssget ":S" '((0 . "text,mtext"))))) (= 0 (setq ssl (sslength ss1))) ) nil) 		
		(T
			(setq
				Textobj (vlax-ename->vla-object (ssname ss1 0))
				ActSpace 
					(if (= 0 (getvar "cvport"))
						(vla-get-paperspace
						(vla-get-activedocument (vlax-get-acad-object))
						)
						(vla-get-modelspace
						(vla-get-activedocument (vlax-get-acad-object))
						)
					)
				StartPt (getpoint "\nPick location for point of arrow head: ")
				txt (vla-get-TextString Textobj)

				TextPt (vla-get-insertionpoint textobj)
				TextPt(vlax-variant-value TextPt)
				TextPt (vlax-safearray->list TextPt)
				ptlist(vlax-make-safearray vlax-vbdouble '(0 . 5)) 
				ptlist(vlax-safearray-fill ptlist (append StartPt TextPt))
				MLObj(vla-addmleader ActSpace ptlist 'LeaderIndex)
			)
			(vla-put-textstring mlobj txt)
			(vla-delete Textobj)
		)
	)
(princ)	
)
(defun c:mlte nil (MLeaderToExistingtext))
(defun c:MLeaderToExistingtex nil (MLeaderToExistingtext))

 

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 8 of 13

john.uhden
Mentor
Mentor

As much as I infinitely respect your input, I think I have to disagree.

Defining the shortcut before defining the long form should not cause a problem at all unless the shortcut is called before the long form is defined.  The shortcut won't call the long form until the shortcut is called.

Now if he tried (setq c:this c:longthis) before c:longthis was defined, then yes, c:this is nil.

Also, it shouldn't matter if vl-load-com is invoked after a function is defined.  It should matter only if a vl-* function were called before vl-load-com was invoked.

BTW, I put vl-load-com near the top of every c: function.  It doesn't hurt to call it over and over and over again unless you are worried about losing a nanosecond or two during a day's work.

Another BTW, you really don't want to (setq c:this c:longthis) because the memory used to store c:longthis is now doubled, whereas (defun c:this ()(c:longthis)) is next to nothing because it doesn't include the definition of c:longthis but only a call to it.

John F. Uhden

Message 9 of 13

dbroad
Mentor
Mentor

"Infinitly huh?"  Please tell my children.

Thanks for the correction though.  You are very right - Interesting.  That's a good reason for not using setq unless you want to fix the program structure so the subfunctions can't be redefined.

 

 So my logic and reasoning of why the OP's program didn't work doesn't hold water.  Wonder what the problem actually is.

 

I do know that the program will only work when the current mleader style doesn't have a content type of "block".

Architect, Registered NC, VA, SC, & GA.
Message 10 of 13

john.uhden
Mentor
Mentor

I'm gonna guess that your kids are no more kids than my kids are kids.  🙂

John F. Uhden

Message 11 of 13

dbroad
Mentor
Mentor

Yep. My kids also have kids who don't listen to them either.

Architect, Registered NC, VA, SC, & GA.
Message 12 of 13

cadffm
Consultant
Consultant

@dbroad  schrieb:

Wonder what the problem actually is.


 

For 99% the registry entries for that are broken.

I send a private message yesterday @rmordov about a test and fix,

but didn't get feedback until now about that is the case or not.

Sebastian

Message 13 of 13

john.uhden
Mentor
Mentor
I figure that in ten years or less I'll be Great Grandpa, but they do
listen to me. My oldest daughter tries to negotiate with hers. But as a
young coworker once told me, "Kids are like terrorists. You can't
negotiate with terrorists!"

John F. Uhden