no function definition: nil

no function definition: nil

Anonymous
Not applicable
4,568 Views
9 Replies
Message 1 of 10

no function definition: nil

Anonymous
Not applicable

Hi guys

 

No matter how many (princ) I place in this code, I always get an error message after processing this lisp routine, although the saving process is successful:

 

"Saving was successful.; Fehler: no function definition: nil"

 

(Fehler is German for Error.)

 

Does anyone see the reason why this is happening? I'm new to LISP/AutoCAD and started writing my own codes last week.

So far I managed to let the users switch between one Standard-Profile (with syncing tool palettes and tool palette groups) and their own personal profile.

 

This is one part of the code which allows the profile managers only to save the profiles (so that the groups of the tool palettes can be imported by a button click.)

 

Thanks in advance.

 

Cheers

 

 

(defun C:savestandardprofile ()

(setq loginname (getvar 'loginname))
(setq msgsps1 "Saving was successful.")
(setq msgsps2 "No access!")
(setq msgsps3 "The profile is not active!")

	;;With the IF-Function I check if the Standard-Profile is active. If it is, I allow saving. If it's not, I get a prompt (msgsp3).
	(if (= (getvar "cprofile") "Sample Standard Profile")
					
					;;Only 2 users of our team are allowed to apply changes to the Standard-Profile and save it. With the cond I only allow these 2 users to save. If it's another user, they will get the msgsp2 message.
					(cond 
						((= loginname (strcat "USER1"))
							
							(
								(vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) "Sample Standard Profile" (strcat "Y:\\ACAD_GLOBAL\\2018\\Profile\\Sample Standard Profile.arg"))
								(prompt msgsps1)
								(princ)
							)
						)
							
						((= loginname (strcat "USER2"))
							
							(
								(vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) "Sample Standard Profile" (strcat "Y:\\ACAD_GLOBAL\\2018\\Profile\\Sample Standard Profile.arg"))
								(prompt msgsps1)
								(princ)
							)
						)
									
						(t 
							(prompt msgsps2)
							(princ)
						)
					);cond
		(
		(prompt msgsps3)
		(princ)
		)
	);If
(princ)
);defun

 

0 Likes
Accepted solutions (1)
4,569 Views
9 Replies
Replies (9)
Message 2 of 10

DGRL
Advisor
Advisor

Hi @Anonymous

 

Right after  (defun C:savestandardprofile () you need to add (VL-LOAD-COM)

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 3 of 10

DannyNL
Advisor
Advisor
Accepted solution

It's because if you use more than one LISP statement in the IF...ELSE, you'll need to group it with PROGN.

 

So like:

(defun C:savestandardprofile ()

(setq loginname (getvar 'loginname))
(setq msgsps1 "Saving was successful.")
(setq msgsps2 "No access!")
(setq msgsps3 "The profile is not active!")

	;;With the IF-Function I check if the Standard-Profile is active. If it is, I allow saving. If it's not, I get a prompt (msgsp3).
	(if (= (getvar "cprofile") "Sample Standard Profile")
					
					;;Only 2 users of our team are allowed to apply changes to the Standard-Profile and save it. With the cond I only allow these 2 users to save. If it's another user, they will get the msgsp2 message.
					(cond 
						((= loginname (strcat "USER1"))
							
							(
								(vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) "Sample Standard Profile" (strcat "Y:\\ACAD_GLOBAL\\2018\\Profile\\Sample Standard Profile.arg"))
								(prompt msgsps1)
								(princ)
							)
						)
							
						((= loginname (strcat "USER2"))
							
							(
								(vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) "Sample Standard Profile" (strcat "Y:\\ACAD_GLOBAL\\2018\\Profile\\Sample Standard Profile.arg"))
								(prompt msgsps1)
								(princ)
							)
						)
									
						(t 
							(prompt msgsps2)
							(princ)
						)
					);cond
		(progn
                   (prompt msgsps3)
		   (princ)
		)
	);If
(princ)
);defun

But since you already have a (princ) at the end of your code, you could also omit all the princ's after your (prompt.... statements.

Just remove all the (princ) statements except the one at the end of your code.

0 Likes
Message 4 of 10

DGRL
Advisor
Advisor

@DannyNL

 

Always the progn
Did not even thought about that LOL

But he is also missing the (vl-load-com) for use with vla functions or am I wrong?

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 5 of 10

DannyNL
Advisor
Advisor

 

@DGRL, no you could be right since VLAX is being used, but not in this case.

 

If VL-LOAD-COM hadn't been executed before, the routine would already have failed earlier at the VLAX-GET-ACAD-OBJECT, but in this case it fails after the prompt which means the VL*-commands were executed successfully and the VL* commands were loaded earlier.

0 Likes
Message 6 of 10

Anonymous
Not applicable

@DGRL wrote:

Hi @Anonymous

 

Right after  (defun C:savestandardprofile () you need to add (VL-LOAD-COM)

 


@DGRL

 

Thanks for the reply.

The (vl-load-com) is the first line in the document. I just didn't post the whole document.

 

@DannyNL

 

I will try it out now and report back asap. Thank you for the help.

0 Likes
Message 7 of 10

Anonymous
Not applicable

I modified the code a little and added the progn group.

Now it works perfectly!

 

Thanks a lot @DannyNL.

 

Here's the modified code for anyone with the same problem in the future:

 

(defun C:spspeichern ()

(setq msgsps1 (strcat "Saved"))
(setq msgsps2 (strcat "Access violation"))
(setq msgsps3 (strcat "Standard Profile not active"))


	(if (= (getvar "cprofile") "Sample Standard Profile")
					
					(if (or loginname "User1" "User2")
						(progn
							(vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) "Sample Standard Profile" (strcat "Y:\\ACAD_GLOBAL\\2018\\Profile\\Sample Standard Profile.arg"))
							(prompt msgsps1)
						)
						(
						(prompt msgsp2)
						)
					);if
		(
		(prompt (msgsps3))
		)
	);if
(princ)
)
;defun
Message 8 of 10

DannyNL
Advisor
Advisor

You're welcome & glad I could help Smiley Happy

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

Some simplification suggestions, and some questions:

 

The (strcat) function is for conCATenating STRings together.  If you give it only one  string, it serves no purpose.  Also, you can set more than one variable in one (setq) function.  Try this:

 

  (setq
    msgsps1 "Saved"
    msgsps2 "Access violation"
    msgsps3 "Standard Profile not active"
  ); setq

 

I believe this:

(prompt msgsp2)

 

should be this instead:

(prompt msgsps2)

 

Does the (prompt (msgsps3)) part really work?  That would attempt to run a function  called msgsps3 [the first thing after a left parenthesis, other than within lists, is always the function name], which it's not going to find.  That should be just:

 

  (prompt msgsps3)

 

[without parentheses around msgsps3] as with the one above.

 

Likewise, there are extraneous parentheses in two instances like this:

 

  (
    (prompt msgsp2)

  )

 

which can be simply:

 

  (prompt msgsps2)
 

Kent Cooper, AIA
0 Likes
Message 10 of 10

Anonymous
Not applicable

I think you might find with your revised code that it will always allow any user to save a profile because of how the "or" condition is setup, try this..

(defun c:spspeichern ( / loginname ) ; localise variables here
    (setq loginname (getvar 'loginname)) ; do you need to save login name here or is it part of your larger code?
    (if (= (getvar 'cprofile) "Sample Standard Profile")
        (if (or (= loginname "User1") (= loginname "User2"))
            (and ; using and here means the prompt will only appear if the profile is saved successfully
                (vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) "Sample Standard Profile" "Y:\\ACAD_GLOBAL\\2018\\Profile\\Sample Standard Profile.arg")
                (prompt "Saved")
            )
            (prompt "Access violation")
        );if
    (prompt "Standard Profile not active")
);if (princ) );defun
0 Likes