Old dog is overthinking something simple or has just plain forgot. I need help with the following Lisp.
1) I want to search the drawing for the pre-define block names given in the proram.
2) If the are there, I want to replace them with the new version.
3) Program replaces the firest block it finds, then tries to insert that block.
What am I missing?
Is ther a easier way to do this?
All help is greatly appreciated.
Code is attached.
@RockyBrown4134 wrote:....
1) I want to search the drawing for the pre-define block names given in the proram.
2) If the are there, I want to replace them with the new version.
3) Program replaces the firest block it finds, then tries to insert that block.
What am I missing?
Is ther a easier way to do this?
....
As for the incorrect operation, I tried your typical (progn) insertion series using a Block here that I had redefined, and it worked. A possibility that occurs to me is that you may be working with a redefined Insert command. Try prefixing it with a period/decimal point to force it to use the native AutoCAD command instead. [I also added the prefixed underscore character in the suggestion below for language-independent operation.]
As for easier ways, yes there are several things you can do. Mostly you can eliminate all that duplication by stepping through a list of Block names with (foreach), processing each in the same way, rather than spelling it all out separately for each. Also, if the Block name is the same as the drawing file you want to use to replace its definition in the current drawing, you can omit repeating the name after the = sign.
Give this a try:
(foreach blk
'("carbis" "CORE_TB" "Alco-Lite-ind" "Calico" "Detail"
"Carbis-Loadtec" "COPYRIGHT" "Alco-Lite-ind_COPYRIGHT"
"COPYRIGHT_ALCO" "COPYRIGHT_CALICO" "CORE_COPYRIGHT"
); end quoted list
(if (tblsearch "block" blk)
(progn (command "_.insert" (strcat blk "=") "_yes") (command) (command))
); end if
); end foreach
[In addition, it may be that you don't need both those no-argument (command) functions to close the Insert command without actually Inserting something, but I'll let you experiment with that.]
Kent;
Thanks for the help. Especially the "Education".
That streamlines it alot.
"[In addition, it may be that you don't need both those no-argument (command) functions to close the Insert command without actually Inserting something, but I'll let you experiment with that.]"
I tried it and it with and without the (command) (command) no-argument. I get a block that still wants me to insert it. I would like it cancel or escape out, but I can live with the frustration for now. Eventually, I want to put this in as a startup command and change the blocks out automatically.
FYI......
After going back and reading one of your post
I tried some of the suggestions listed in the last couple of post. The result is still the same. Haven't given up yet. I'll continue to try ideas as I get them.
@RockyBrown4134 wrote:....
I tried some of the suggestions listed in the last couple of post. The result is still the same. ....
Three (command)-with-no-argument entries, perhaps? [Grabbing at straws here....]
After several mnths, I have re-written this routine, tried very sugeestion, and then some.
The routine worked in AutoCAD 2008, but does not in AutoCAD 2012. It will not stop/cancel the command when (command) (command) is put in the code.
Anybody else come across this problem? If so, any solutions?
I did a couple of test to check if each line of the code work. In AutoCAD 2012, I entered the following on the command line:
(COMMAND "-insert" "carbis=carbis" "Y")
I get the following in the AutoCAD Text Window.
Command: (COMMAND "-insert" "carbis=carbis" "Y")
-insert Enter block name or [?]: carbis=carbis Duplicate definition of block
_OBLIQUE ignored.
Duplicate definition of block COPYRIGHT ignored.
Block "carbis" redefined
Units: Inches Conversion: 0'-1"
Specify insertion point or [Basepoint/Scale/Rotate]: Y
Point or option keyword required.
; error: Function cancelled
Specify insertion point or [Basepoint/Scale/Rotate]:
What is confusing me is the "; error: Function cancelled" response by AutoCAD. The code line dose not have anything canceling the command at this point. in the program I had the (command)(command) to cancel at this point, however, I have not entered that line in the command line in the test, I have removed all the white spaces and re-wriiten the line of code manually, nothing works.
I even entered the cod in AutoCAD step by step, to see if the order worked.
-insert <Return>
carbis=carbis <Return>
y <return>
(Command) <Return>
Step by step woks, block redefined and command is canceled. Could whatever is causing the "; error: Function cancelled" be the problem?
Any Suggestions?
FYI....I had tested the program in AutoCAD 2008 and it worked without any problems.
@RockyBrown4134 wrote:
I did a couple of test to check if each line of the code work. In AutoCAD 2012, I entered the following on the command line:
(COMMAND "-insert" "carbis=carbis" "Y")
I get the following in the AutoCAD Text Window.
Command: (COMMAND "-insert" "carbis=carbis" "Y")
-insert Enter block name or [?]: carbis=carbis Duplicate definition of block
_OBLIQUE ignored.
Duplicate definition of block COPYRIGHT ignored.
Block "carbis" redefinedUnits: Inches Conversion: 0'-1"
Specify insertion point or [Basepoint/Scale/Rotate]: Y
Point or option keyword required.
; error: Function cancelled
Specify insertion point or [Basepoint/Scale/Rotate]:....
It is not asking whether you want to replace the definition of the Block, so the "Yes" answer to that question is being fed in to answer the insertion-point prompt. That could be because: A) you have the EXPERT System Variable set so that it won't ask, or B) the operation of Insert in a (command) function is different in newer versions, or C) you're using a redefined Insert command, or D) you're using this when that Block name is not already defined in the drawing.
I think the "Function cancelled" message is about the Lisp (command) function, but it's still leaving you in the not-yet-completed Insert command that it started.
I checked for what you indicated and listed below:
A) EXPERT System Variable set to 0
B) Order of operation of insert command "appears" to be the same. (I tested the order and it works in AutoCAD 2012)
C) Redefined Insert command - Command has not been redefined. I checked acad.pgp, acaddoc.lsp, acad.cuix and any other program loaded during startup.
D) Block is in drawing. There is a statement in the program to check for the block.
I first thought it acted like there was an extra Return in the code, due a ";" or "White space" or a misplaced parenthesis. I checked all three cases and even removed all of the white spaces.
With Logos and title block format having changed for the next fiscal year, I need to finalize a way to change the blocks out without having to manually do it in each drawing. There are Way to Many drawings to do this to.
@Kent1Cooper wrote:It is not asking whether you want to replace the definition of the Block, so the "Yes" answer to that question is being fed in to answer the insertion-point prompt. That could be because: A) you have the EXPERT System Variable set so that it won't ask, or B) the operation of Insert in a (command) function is different in newer versions, or C) you're using a redefined Insert command, or D) you're using this when that Block name is not already defined in the drawing.
I think the "Function cancelled" message is about the Lisp (command) function, but it's still leaving you in the not-yet-completed Insert command that it started.
Sorry that it has taken me so long to get back to this.
Answer to your questions:
A) EXPERT is set to "0", Issues all prompts normally.
B) I'm not sure but See below.
C) "Insert" command, to my knowledge, is not redefined. It is OTB.
D) Using "(foreach BLK" statment and "(if (tblsearch "block" blk)" tosearch drawing for the block before starting the insert command.
Here is what I recently did and for some reason it works.
The code that was giing me the problem was: (command "_.insert" (strcat blk "=") "_yes")(command)(command), hanging up on the "Redefine" prompt with a "Y" or "Yes" answer.I decided to step through the command and see if each step worked. When I removed the "_yes" from the stament, the code worked as expected. I don't know why, but it works.I thought it was the "EXPERT" setting was changed at first, but I ruled that out when I checked it and it was set to "0".
Here is what is a mystery. I tried the code as originally written on a system that has AutoCAD 2010 and it works. But it did not work on a system with AutoCAD 2012 until i removed the "_yes" from the statment.
Can't find what you're looking for? Ask the community or share your knowledge.