Help - Routine from another lisp routine.

Help - Routine from another lisp routine.

arperezinf
Advocate Advocate
5,639 Views
34 Replies
Message 1 of 35

Help - Routine from another lisp routine.

arperezinf
Advocate
Advocate

Hi everyone! 👋

I have a lisp routine called "CD", I use this routine to insert multiple blocks. When I call it the "CD" routine in autoCAD, it asks me to enter a text, for example "AB", which corresponds to a certain block, finally it asks me the point where I want to insert the block.

 

I need to call the "CD" routine from another lisp routine.

I've been looking on the internet and with "COMMAND", it's done.

I want to insert several blocks at the same time, without having to call the lisp routine "CD" again and write the text that corresponds to the other block.

(command "._CD" "AB" ""); Block 1
(command "._CD" "AC" ""); Block 2
(command "._CD" "AD" ""); Block 3

But it doesn't work for me, I can only insert the first block.

Could you tell me or explain how I could do this.
Thank you very much for reading my message.
Greetings.

0 Likes
Accepted solutions (4)
5,640 Views
34 Replies
Replies (34)
Message 21 of 35

john.uhden
Mentor
Mentor
Accepted solution

@arperezinf 

Maybe the CD command doesn't need that pause, so try this instead...

(defun c:CD5 ()
  (foreach alias '("AB" "AC" "AD" "AE" "AF")
    (princ (strcat "\nBlock '" alias "' insertion point: "))
    (command "_.CD" alias)
  )
  (princ)
)
;; or maybe it needs that double quote you originally showed...
(defun c:CD5A ()
  (foreach alias '("AB" "AC" "AD" "AE" "AF")
    (princ (strcat "\nBlock '" alias "' insertion point: "))
    (command "_.CD" alias "")
  )
  (princ)
)

Try them both and let us know if either works correctly.

John F. Uhden

Message 22 of 35

Kent1Cooper
Consultant
Consultant

@arperezinf wrote:

....

If the CD command handles scaling and rotation.

The CD5 lisp function works!!! 😀🙏👍

But I get this message after I insert each block.

 

Unknown command "CD5". Press F1 for help.

....


If you're talking about my version from Message 18, that sounds like the Blocks are defined for uniform scaling, meaning it needs one fewer Enter at the end of the command function.  So the extra Enter would be "recalling the last command," which not being an AutoCAD command, it doesn't recognize in that context.  Try this change, with just one Enter for the single scale factor and one for the default 0 rotation:

    (command "_.insert" block pause "" "")

 

Kent Cooper, AIA
Message 23 of 35

arperezinf
Advocate
Advocate

Hello @john.uhden 

 

Something had happened does not work, I get this message:

Invalid point. Function canceled.

I solved it by putting this.

 

 

(command "_.CD" alias pause)

 

 

Now I don't get the message anymore 😀👍🙏
Unknown command "CD5". Press F1 for help.

 

Now the lisp function is like this

 

 

(defun c:CD5D ()
  (foreach alias '("AB" "AC" "AD" "AE" "AF")
    (princ (strcat "\nBlock '" alias "' insertion point: "))
    (command "_.CD" alias pause)
  )
  (princ)
)

 

 

You are a genious!!!! 😀👨‍🎓👍👏🙏💪

Thank you very much for all your work!

I already got one lisp routine to work inside another!

 

Thank you very much for reading my message.

Have a nice weekend
Greetings.

0 Likes
Message 24 of 35

arperezinf
Advocate
Advocate

Hello @john.uhden @Sea-Haven @Kent1Cooper 

 

Sorry if I don't open another topic and continue on this topic, but I have a problem related to the same, executing a lisp routine within another lisp routine.

 

For example:

 

 

(defun c: RQ (/ symbol snumber)
(setq symbol (getstring "\ nInsert symbol: [1/2]"))
(cond
((= symbol 1)
(command "_.CD" symbol pause)
(setq snumber (getint "\ nInsert number:"))
(command "_.PP" snumber pause)
)
((= symbol 2)
(command "_.CD" symbol pause)
(setq stext (getstring "\ nInsert text:"))
(command "_.PP" stext pause)
)
)

 

 

It happens that when I run the routine, the second (2) command executes without the first (1) command finishing inserting the block for me, so it won't let me continue. Setq is executed before the first command completes.

 

How can I make the first command finish and then start the second command.

 

Thank you very much for reading my message.
Greetings.

0 Likes
Message 25 of 35

john.uhden
Mentor
Mentor

@arperezinf 

I am not familiar with the "SIM" command, so I don't know what it is expecting for input, but usually you have to finish a command function with "" to let the command know you are done with your input.

John F. Uhden

0 Likes
Message 26 of 35

arperezinf
Advocate
Advocate
Sorry I got confused command is _.CD, not _.SIM, now change it.
0 Likes
Message 27 of 35

arperezinf
Advocate
Advocate
So you say I should put it like this

(command "_.CD" pause "")
0 Likes
Message 28 of 35

john.uhden
Mentor
Mentor
@arperezinf
I am at home now, with only AutoCAD 2002 working.
I don't recognize the "CD" command either.

John F. Uhden

0 Likes
Message 29 of 35

arperezinf
Advocate
Advocate

Hello @john.uhden @Sea-Haven @Kent1Cooper 

 

How are you?

Sorry about the delay in responding.

Let me explain, the commands that I publish are all from a gis system, for that reason you will not find any command in any version of AutoCAD.

 

I do not have access to the code of the gis system commands and I suppose it works with a database, but I don't know, I can only explain what the commands do for which the commands are used, I can also give an example, like me I have put before because they are the things that I want to do to speed up my work, that is why it does not matter what name I put in the command, what matters is what the command does and what the command is used for.

 

I know that it is very difficult to find a solution like this, if you think that you cannot give me a solution there is no problem, but the code that I publish are real are the code that reading and searching the internet I have been able to put together to try to make my own lisp routines for streamline my work and the main thing that can work with the commands that the gis system brings.

 

And excuse me but now getting back to my problem.

 

The "CD" command asks you to enter an "alias or symbol", it is a text that is entered into the command and that text has a certain block associated with it.

 

I am trying to insert an "X block" which has a name, but for better understanding I put "symbol 1" and "symbol 2", it happens that when I execute the routine that I published before when it reaches the part where the command is called " CD ", the (setq snumber) is executed before and it does not let me insert the block and I need to insert the block first and then enter the number to the block that I have selected.

 

I hope you understand me.

 

Thank you very much for reading my message.
Greetings.

0 Likes
Message 30 of 35

john.uhden
Mentor
Mentor
Accepted solution

@arperezinf 

After revisiting your c:RQ function, you are setting symbol to a string, either "1" or "2", but your condition is treating symbol as an integer, which it is not.  So it should look like:

(cond

  ((= symbol "1") ... )

 

As to the CD command, it would be helpful if we (and you) knew what the prompts are so that we can figure out what to feed it.  Without knowing, sometimes this works:

(command ".FOO")(while (> (getvar "cmdactive") 0)(command pause))

John F. Uhden

Message 31 of 35

arperezinf
Advocate
Advocate

Hello @john.uhden 😀👋

When I tried to use this.
(command ".CD") (while (> (getvar "cmdactive") 0) (command pause))

I get this window with this message. Symbol not found in current library.

arperezinf_windows.png

And in the command input console I get this message.

arperezinf_console.png

The <BLOCK 1> symbol is the last block name I used, before passing the code you gave me, the CD command saves the last value I entered.

 

Thank you very much for reading my message
Greetings.

0 Likes
Message 32 of 35

john.uhden
Mentor
Mentor
@arperezinf
Well then, your custom command does not behave as a normal command does.
I'm sorry but I guess you're just going to have to play with it.

John F. Uhden

0 Likes
Message 33 of 35

arperezinf
Advocate
Advocate
Accepted solution

Hello @john.uhden 😀👋

Sorry for the delay in responding but I was researching in the forum and the internet, something similar to your previous code and I found some lines of codes in another forum.

 

External forum
Ending Command and starting new Command 

 

Internal forum

Finishing a Command before Moving on 

 

(while (= (logand (getvar "cmdactive") 1) 1) 
(command pause)
)

 

I tried those lines of code and it worked perfectly!🙏
I am a genius !!! LOL.🤣😂😎👨‍🎓

 

Thank you very much for reading my message
Greetings.

0 Likes
Message 34 of 35

john.uhden
Mentor
Mentor
YAY!!
We love people like you who refuse to give up AND find a way to solve their
own problem.

John F. Uhden

Message 35 of 35

arperezinf
Advocate
Advocate
But without your line of code I could never have solved my problem! You are the expert! But thanks to your experience, a simple member of the community was able to resolve his own question.

Thank you very much for your help!
Have a nice weekend.
Greetings.
0 Likes