Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How update a block (swap with block of same name)

30 REPLIES 30
Reply
Message 1 of 31
Anonymous
499 Views, 30 Replies

How update a block (swap with block of same name)

When we revise a block in our library it would be nice to have a routine to put the new version of the block into any drawing "overwriting" the drawing's old version of the block (with the same name of course), but at the same time retaining all circumstances of each insertion (i.e. attribute values, scale, rotation etc.). This apparently works with the dialog version of the insert command, by browsing to find the new version of the block file, then you get the ". . .already exists - do you want to redefine it" alert. YES ! So how do I get around the dialog process in lisp ??? ("-insert" doesn't allow for this browsing - same name replacement - action). [Autocad are you listening - here we are fighting the dialog box interface thing AGAIN ! Please provide command line (lisp access) to ALL the dialog box functions] Thanks in advance, Scott McFarren
30 REPLIES 30
Message 2 of 31
old-cadaver
in reply to: Anonymous

They did a long time ago. When promted for the name use a tilde ~

Command: -INSERT
Block Name: PEANUT=~

and a file selection browse window will open.
Message 3 of 31
Anonymous
in reply to: Anonymous

(command ".-INSERT" "BLOCKNAME=FILENAME") (command) -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com "Scott Mcfarren" wrote in message news:41b5fb6f$1_1@newsprd01... > When we revise a block in our library it would be nice to have a routine > to put the new version of the block into any drawing "overwriting" the > drawing's old version of the block (with the same name of course), > but at the same time retaining all circumstances of each insertion > (i.e. attribute values, scale, rotation etc.). > > This apparently works with the dialog version of the insert command, > by browsing to find the new version of the block file, then you get the > ". . .already exists - do you want to redefine it" alert. YES ! So how > do I get around the dialog process in lisp ??? ("-insert" doesn't allow > for this browsing - same name replacement - action). > > [Autocad are you listening - here we are fighting the dialog box > interface thing AGAIN ! Please provide command line (lisp access) > to ALL the dialog box functions] > > Thanks in advance, > > Scott McFarren > >
Message 4 of 31
Anonymous
in reply to: Anonymous

> When we revise a block in our library it would be nice You weren't the first person to think of this. The blockname=filename method Tony mentioned is very, very old. This usage was provided for exactly the reasons you mention, because it's a near-universal scenario. I believe this has been around since my first use of Acad 2.6. Certainly it came long before dialog boxes and xrefs. This is what we did instead of xrefs before those became available. You can force a dialog interface to pop up with the "~" trick as OC noted, but assuming that the revised standard block exists somewhere on your search path, there's no reason you should need to browse to "find" it.
Message 5 of 31
Anonymous
in reply to: Anonymous

I've got my system set up so that acad.lsp loads an office wide lsp file, checks to see if there is file called Acad_prj.lsp in the same directory as the current drawing and if there is, loads it and then does a few other things. Any way, when a block for a certain project is changed, I include a call to UPDATEBLOCK in acad_prj.lsp. When someone opens a dwg file in the same directory as the acad_prj.lsp file, the block gets updated. (updateblock "northarrow") (defun UpdateBlock(name) (if (and (findfile (strcat name ".dwg"))(tblsearch "Block" name)) (command "insert" (STRCAT name "=") "y" ^c) ) ) "Scott Mcfarren" wrote in message news:41b5fb6f$1_1@newsprd01... > When we revise a block in our library it would be nice to have a routine > to put the new version of the block into any drawing "overwriting" the > drawing's old version of the block (with the same name of course), > but at the same time retaining all circumstances of each insertion > (i.e. attribute values, scale, rotation etc.). > > This apparently works with the dialog version of the insert command, > by browsing to find the new version of the block file, then you get the > ". . .already exists - do you want to redefine it" alert. YES ! So how > do I get around the dialog process in lisp ??? ("-insert" doesn't allow > for this browsing - same name replacement - action). > > [Autocad are you listening - here we are fighting the dialog box > interface thing AGAIN ! Please provide command line (lisp access) > to ALL the dialog box functions] > > Thanks in advance, > > Scott McFarren > >
Message 6 of 31
Anonymous
in reply to: Anonymous

> (command "insert" (STRCAT name "=") "y" ^c) ^c is not an Acad command, nor is it a cancel. It's a special character code used in menu macros and has no meaning in lisp. It has the effect of cancelling your command sequence only because it's meaningless to the (command) function. You could use (command %#$&) with exactly the same effect. A cleaner way to terminate a command sequence is to call (command) with no arguments as in Tony's example.
Message 7 of 31
Anonymous
in reply to: Anonymous

Thanks everbody. This is what works for me now. One pick on a block and all occurences are replaced (updated). YIPPEE ! (setq SAMPK (entsel "\nPick sample of the block type to be replaced . . .")) (setq SAMBLK (entget (car SAMPK))) (setq BLKNAME (cdr (assoc 2 SAMBLK))) (setq INSNAME (strcat BLKNAME "=" BLKNAME ".dwg")) (command "_insert" INSNAME ^c^c) I'm not dealing with the browse step (but will keep in mind the suggestions for other routines). Scott
Message 8 of 31
Anonymous
in reply to: Anonymous

> (command "_insert" INSNAME ^c^c) See Tony's response and my previous reply to RDI. Change to (command "_insert" INSNAME) (command) If you're fairly new to customization, you need to make sure you learn things Properly. A "^c" character sequence is not a command, nor is it an escape, nor is it meaningful in lisp. Essentially, you're just causing the (command) function to crash and burn. You might say this "works" in the present context, in that it does terminate the command sequence. However, you're going to be bitterly disappointed if you start believing that special menu-macro character codes work in lisp. Try issuing (command ^p) to run a plot, for instance, or any of the other control codes. They don't work. Also, this needs some bulletproofing before you hand it to anyone else. For instance, it will crash if the user doesn't pick an object, or if the object isn't a block, or if the block name doesn't match a block name on the search path. You might use it as an exercise in crash-proofing.
Message 9 of 31
Anonymous
in reply to: Anonymous

Mr Smith: Your statement about browsing to find a file "should not be required if the file is in the path somewhere" is not correct. The files listed in the dialog pulldown are only block definitions in the current drawing, not the path. The browse operation forces Acad to look outside the current drawing for the block - which is exactly what I need to be done because the block in the file is what I need to replace. As for your comment about ^c^c having no meaning in lisp I shall refrain from embarrasing you publicly. I posted the code that worked initially so those who gracoiusly contributed ideas could see what at minimum worked. Bulletproofing distracts from the guts of the real work so that version was not shown. I am sorry you are having such a bad day. Scott
Message 10 of 31
Anonymous
in reply to: Anonymous

I've used this for YEARS and have never once had a problem with it. -- Don I "Tom Smith" wrote in message news:41b61152$1_3@newsprd01... >> (command "insert" (STRCAT name "=") "y" ^c) > > ^c is not an Acad command, nor is it a cancel. It's a special character > code > used in menu macros and has no meaning in lisp. > > It has the effect of cancelling your command sequence only because it's > meaningless to the (command) function. You could use (command %#$&) with > exactly the same effect. A cleaner way to terminate a command sequence is > to > call (command) with no arguments as in Tony's example. > >
Message 11 of 31
old-cadaver
in reply to: Anonymous

<>

Then embarrass me, I'm used to it. Tell me, what does ^c^c mean in your version of AutoLISP??
Message 12 of 31
old-cadaver
in reply to: Anonymous

<>

Oh, no doubt, as long as you're looking for a bail from the routine, nearly anything can accomplish that as stated by Mr. Smith. But the more elegant method of closing a command is the (command), as previously stated.

In more complex routines that may require a clean exit from a command followed by additional steps, you'll be disappointed with the ^c^c. Let's say that after you've inserted the new block definition you wish to ATTSYNC the existing attributes to the new definition. Using ^c^c will kill the routine before it gets to ATTSYNC, while using (command) will close the insert command and allow you to move on to the ATTSYNC command.

Better yet avoid "(command" calls all together. (I know, I know, I still use it often myself, but I'm just lazy)
Message 13 of 31
Anonymous
in reply to: Anonymous

I did not say anything about the appropiate use or effects of caret characters - I just don't like it when people say things in absolute like "has no meaning . . .". Obviously they do. May not be to some's standards, sooo what ! In these endeavors I tend not to rule out any means of getting code to work for me soon as possible. Some of you guys are taking yourselves and the coding too seriously. I've got to get back to work now. Thanks again anyway, Scott
Message 14 of 31
old-cadaver
in reply to: Anonymous

< . . .".
Obviously they do. >>

Okay, what do they mean in your version of AutoLISP.

In my version, they have no meaning. There is no definition of a function in my version AutoLISP for ^c^c, just as there is no meaning for @#$%, which would have worked just as well for your use.



<>

Hmm... as far as I can tell, everybody here (except me) was attempting to be helpful in clarifying a coding error that will cause failure of your future coding. I, personally, think you owe Mr.Tanzillo and Mr. Smith an apology for your derision of their coding skills. Skills, i might add, that have been proven considerably more than competent for several years on these forums.
Message 15 of 31
Anonymous
in reply to: Anonymous

> I've got to get back to work now. Many of us are also working. If you don't want to learn why do you frequent this NG? I believe that the most important thing to learn for you are your manners. Marc'Antonio Alessi
Message 16 of 31
Anonymous
in reply to: Anonymous

> As for your comment about ^c^c having no meaning > in lisp I shall refrain from embarrasing you publicly. Ummmm. Well, while he may be a tad pedantic, Tom is nontheless correct and you're not going to embarrass him. In LISP ^C^C is just another symbol (all of which are initially assigned to the value NIL), hence: (command "._-INSERT" "BLOCKNAME" ^C^C ) Is no different than (command "._-INSERT" "BLOCKNAME" NIL) which is no different than: (command "._-INSERT" "BLOCKNAME" BURP) Because the symbols 'BURP' and '^C^C' evaluate to nil. To wit: Command: (eval ^c^c) nil Command: -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com "Scott Mcfarren" wrote in message news:41b63eed$1_1@newsprd01... > Mr Smith: > > Your statement about browsing to find a file "should not be required > if the file is in the path somewhere" is not correct. The files listed in > the > dialog pulldown are only block definitions in the current drawing, not the > path. The browse operation forces Acad to look outside the current > drawing for the block - which is exactly what I need to be done because > the block in the file is what I need to replace. > > I posted the code that worked initially so those who gracoiusly > contributed ideas could see what at minimum worked. Bulletproofing > distracts from the guts of the real work so that version was not shown. > > I am sorry you are having such a bad day. > > Scott > > >
Message 17 of 31
Anonymous
in reply to: Anonymous

Yes but as you pointed out in your first post: the form: (command "._-INSERT" "BLOCKNAME") (command) is preferable then: (command "._-INSERT" "BLOCKNAME" NIL) -- Marc'Antonio Alessi http://xoomer.virgilio.it/alessi (strcat "NOT a " (substr (ver) 8 4) " guru.") -- "Tony Tanzillo" ha scritto nel messaggio news:41b6a4aa$1_1@newsprd01... >> As for your comment about ^c^c having no meaning >> in lisp I shall refrain from embarrasing you publicly. > > Ummmm. Well, while he may be a tad pedantic, Tom is > nontheless correct and you're not going to embarrass him. > > In LISP ^C^C is just another symbol (all of which are > initially assigned to the value NIL), hence: > > (command "._-INSERT" "BLOCKNAME" ^C^C ) > > Is no different than > > (command "._-INSERT" "BLOCKNAME" NIL) > > which is no different than: > > (command "._-INSERT" "BLOCKNAME" BURP) > > Because the symbols 'BURP' and '^C^C' evaluate to nil. To wit: > > Command: (eval ^c^c) > nil > Command: > > > -- > http://www.caddzone.com > > AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 > http://www.acadxtabs.com >
Message 18 of 31
Anonymous
in reply to: Anonymous

> I've used this for YEARS and have never once had a problem with it. I explained why it "works" -- or at least gives the appearance of working properly om this particular context. Unless the language is changed, it might appear to work properly for CENTURIES. I'm simply pointing out that the menu macro control code ^c isn't doing what you appear to think it's doing. As Tony elaborates below, the ^c is just an undefined symbol in lisp, therefore it evaluates to nil. You could use absolutely any undefined symbol to do the same thing -- (command MerryChristmas) amounts to precisely the same thing as (command ^c). You could use (command *crash*and*burn*) for years with exactly the same effect. Try a few of the other menu macro control codes in lisp and see what they do, for instance (command ^B) for toggling snaps, or (command ^G) for toggling grid. You'll find that none of them do what the code implies they should..
Message 19 of 31
Anonymous
in reply to: Anonymous

> Your statement about browsing to find a file "should not be required > if the file is in the path somewhere" is not correct. Several replies pointed you to the command sequence -insert =, a the age-old method of redefining a block with respect to an external file. One suggestion gave a variant, namely -insert =~ which will bring up a dialog to browse for the external file. If the external file is on the search path, then it can be inserted by entering its name alone, as in the first syntax. Since you know the name of the block that needs to be updated, and you presumably know it's on your path if it's part of a standard block library, then manually browsing to identify the file, as in the second syntax, isn't necessary. Like I said. And like you did. I note that you didn't do this in your "initial" pass at the code, and stated "I'm not dealing with the browse step." In fact, my statement was and is correct, and your code reflects it. > As for your comment about ^c^c having no meaning in lisp I shall refrain > from embarrasing you publicly. Go ahead, I can take it! Hint: if you want to know the "meaning" of a thing in lisp, you can use the evaluation function, as in (eval ^c). It evaluates to the same thing as %#$& or any other symbol which has not been bound to a value, namely nil, which is about as close as you can come to "having no meaning" in lisp. Using an explicit nil as in (command nil) would be better coding practice than using a random series of characters which evaluates to nil, for clarity if nothing else. Calling (command) with no arguments, however, is a more conventional way of cancelling a command sequence in lisp.
Message 20 of 31
Anonymous
in reply to: Anonymous

>while he may be a tad pedantic LOL Tony you're not often so diplomatic, thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost