Jump to content

Recommended Posts

Posted

I am trying to run a lisp from a setq.

 

Im sure there is a more efficient way but Im self tough & have minimal knowledge.

 

I have a lisp that I want to use for a number of block inserts, text notes & a few various other things.

Im not looking for a rewritten code I just need to be able to run a "defun" from a setq.

The setq's at the beginning of the code are the only things that will change in each file. I did have the code working but had to go thru & find & edit each difference. I am trying to make it a lot easier to change.

 

her is an extract of my code. I have a seperate c:defun that is run and calls up the "the-sub-command" & I have both the new1 & new2 defun's written in the same lisp. my problem is running either new1 or new2

 

 

(setq value-1 "changeable-value") ;this is the 1st stored value

(setq new1 (strcat value-1 "generic text1")) ;this is the 1st stored value combined with a 1st generic value.

(setq new2 (strcat value-1 "generic text2")) ;this is the 1st stored value combined with a 2nd generic value.




(defun the-sub-command()
(initget 1 "EXG PROP")
(setq exg-prop (getkword  "\nExisting or Proposed? [Existing/Proposed]: "))        ;get INFO
(COND 
((= exg-prop "EXG") new1)


((= exg-prop "PROP") new2)


(T (prompt "\nOpps there was an error!"))
 )
 (princ)
)



(defun new1()
......the commands
 (princ)
)


(defun new2()
......the commands
 (princ)
)

Posted
 ;; ...
 (COND 
((= exg-prop "EXG") [b][color="red"]([/color][/b]new1[b][color="red"])[/color][/b])


((= exg-prop "PROP") [b][color="red"]([/color][/b]new2[b][color="red"])[/color][/b])


(T (prompt "\nOpps there was an error!"))
 )
 ;; ...

Posted

Thanks for the reply but I had tried that prior to my post & just double checked with not success.

 

The command that it is trying to run doesnt have a C: before the Defun.

When running the code instead of the command running I get an error in the command line

 

; error: bad function: "changeable-valuegeneric text1"

Posted

What BlackBox advised you is correct!

 

Please pay attention that the New1/New2 functions seems to be defined after where called; this issue is masked by the fact that you used the same symbols to store a string and later a function definition!

Posted

Thanks,

 

So is what im trying to do my achievable?

I am sort of trying to learn LIPS by over coming issues when they arise so if there is a correct way could someone please point me in the right direction :D

Cheers

Posted

I see no reasons why cannot be achived! Try to adjust your code like below:

 

(setq value-1 "changeable-value") ;this is the 1st stored value
(setq [color=red][s]new1[/s] string1[/color] (strcat value-1 "generic text1")) ;this is the 1st stored value combined with a 1st generic value.
(setq [color=red][s]new2[/s] string2[/color] (strcat value-1 "generic text2")) ;this is the 1st stored value combined with a 2nd generic value.

[color=red];move function definitions here![/color]
[color=blue](defun new1()
......the commands
 (princ)
)

(defun new2()
......the commands
 (princ)
)[/color]


(defun the-sub-command()
(initget 1 "EXG PROP")
(setq exg-prop (getkword  "\nExisting or Proposed? [Existing/Proposed]: "))        ;get INFO
(COND 
 ((= exg-prop "EXG")  [color=red]([/color]new1[color=red])[/color])
 ((= exg-prop "PROP") [color=red]([/color]new2[color=red])[/color])
 (T (prompt "\nOpps there was an error!"))
)
(princ)
)

Posted

Two other comments:

When you concatenate the strings shouldn't there be a space?

(strcat value-1 [color=red]" "[/color] "generic text1")

Second, woudn't be better to use one letters keywords for options? It match AutoCAD behavior and is simpler to use:

(initget 1 "Existing Proposed")

Also, the required input isn't suggested in your prompt (the "EXG" one isn't even intuitive).

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