Jump to content

Can a lisp be used to force a value change of a specific tag?


Recommended Posts

Posted

Hi guys,

I don't have a clue if this can be done since I know exactly squat about writing lisp routines, but I've been writing and running scripts all day in an attempt to "clean up" a huge mess at the end of a project that was split up between several divisions in different countries with little or no coordination for consistency between any of the divisions involved.:reallymad:@#$@$#@

 

Anyway, I've covered a lot of ground with scripts using find and replace, but I've come to a point that the information that I need to replace is to generic to use the find and replace feature. The tag is common to all the drawings and I would like to be able to execute a lisp with a script that finds that tag and changes the value of the tag to the value I need.

 

I hope my ramblings haven't ended in mass confusion for anyone who may be able to assist me with this situation. If so, BLAME IT ON THE PROJECT MIS-MANAGER. :P

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

  • Cat

    20

  • David Bethel

    12

  • BlackBox

    12

  • Lee Mac

    5

Top Posters In This Topic

Posted Images

Posted

Lets see if I understand:

to change 1 ATTRIBute value in all INSERTs that has a specified Tagname in a single call

 

If so:

 

[b][color=BLACK]([/color][/b]defun c:chg1att [b][color=FUCHSIA]([/color][/b]/ tagname new_val i ss en ch an ad[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq tagname [b][color=NAVY]([/color][/b]strcase [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nATTRIB TagName:  "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq new_val [b][color=NAVY]([/color][/b]getstring t [color=#2f4f4f]"\nNew ATTRIB Value:  "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq i -1 ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ch nil
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 2 ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] tagname[b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 1 new_val[b][color=PURPLE])[/color][/b]
                                        [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b] ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]setq ch T[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if ch [b][color=GREEN]([/color][/b]entupd en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

-David

Posted

Thank you David. Can you clarify where in the lisp I would put the tag name and the new value? Do I have to put the old value and then the new value?

For example:

The tag name is something like: Code_4

The value I need to replace is: 48

The new value will be: an actual description....lets say.....See Spot Run

Sorry, I'm lisp illiterate.

Posted

This change the attribute value regardless of the old value. Is that an issue?

 

[b][color=BLACK]([/color][/b]defun c:chg1att [b][color=FUCHSIA]([/color][/b]/ tagname new_val i ss en ch an ad[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq tagname [color=#2f4f4f]"CODE_4"[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq new_val [color=#2f4f4f]"See Spot Run"[/color][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq i -1 ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ch nil
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]strcase [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ad[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b]strcase tagname[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 1 new_val[b][color=PURPLE])[/color][/b]
                                        [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b] ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]setq ch T[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if ch [b][color=GREEN]([/color][/b]entupd en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

Posted

No David, that should work perfectly. I'm off for the weekend, but I will give it a try first thing Monday morning. Just so I know for future applications, can I copy the code several times to replace multiple tag values?

Posted

Yes, you can copy it multiple times.

 

If you have 1,000s of inserts to deal with, the routine could be made more efficient, but with todays hardware, it should only take seconds to complete. -David

Posted

Thank you again David. I really appreciate it. I'll let you know how it goes.

Posted

David,

I just wanted to let you know that the lisp worked great. I really appreciate your help.

How difficult would it be to modify the lisp to work as a find and replace for present attribute value to new attribute value?

Posted

Pretty easy:

 

[color=#8b4513];;;Change 1 Known ATTRIBute Value With a New Value[/color]
[b][color=BLACK]([/color][/b]defun c:chg1kat [b][color=FUCHSIA]([/color][/b]/ tagname old_val new_val i ss en ch an ad[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq tagname [color=#2f4f4f]"CODE_4"[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq old_val [color=#2f4f4f]"See Jane Run"[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq new_val [color=#2f4f4f]"See Spot Run"[/color][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq i -1 ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ch nil
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]strcase [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ad[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b]strcase tagname[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]strcase old_val[b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b]strcase [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 1 ad[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 1 new_val[b][color=PURPLE])[/color][/b]
                                        [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b] ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]setq ch T[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if ch [b][color=GREEN]([/color][/b]entupd en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

The values are NOT case sensitive

 

Jane and JANE are equal as far as the comparisons go.

 

-David

Posted

David, you rock.:D

One more question. If I wanted to do multiple values within the lisp, would I need to duplicate the entire code per value?

Posted

To revise multiples, I'd go with a list format.

 

Maintaining the format of the list is very important

 

each atom must be :

("tagname" "old_val" "new_val")

 

 

[color=#8b4513];;;Change Multiple Known ATTRIBute Value With a New Value[/color]
[b][color=BLACK]([/color][/b]defun c:chgmkat [b][color=FUCHSIA]([/color][/b]/ al i ss en ch an ad[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq al '[b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b][color=#2f4f4f]"CODE_4"[/color] [color=#2f4f4f]"See Jane Run"[/color] [color=#2f4f4f]"See Spot Run"[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b][color=#2f4f4f]"CODE_4"[/color] [color=#2f4f4f]"See Dick Run"[/color] [color=#2f4f4f]"See Spot Run"[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b][color=#2f4f4f]"CODE_5"[/color] [color=#2f4f4f]"See Spot Run"[/color] [color=#2f4f4f]"See Spot Drop"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]


 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq i -1 ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ch nil
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]foreach a al
                      [b][color=BLUE]([/color][/b]and [b][color=RED]([/color][/b]= [b][color=PURPLE]([/color][/b]strcase [b][color=TEAL]([/color][/b]cdr [b][color=OLIVE]([/color][/b]assoc 2 ad[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                              [b][color=PURPLE]([/color][/b]strcase [b][color=TEAL]([/color][/b]nth 0 a[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]= [b][color=PURPLE]([/color][/b]strcase [b][color=TEAL]([/color][/b]cdr [b][color=OLIVE]([/color][/b]assoc 1 ad[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                              [b][color=PURPLE]([/color][/b]strcase [b][color=TEAL]([/color][/b]nth 1 a[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]setq ad [b][color=PURPLE]([/color][/b]subst [b][color=TEAL]([/color][/b]cons 1 [b][color=OLIVE]([/color][/b]nth 2 a[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b]
                                           [b][color=TEAL]([/color][/b]assoc 1 ad[b][color=TEAL])[/color][/b] ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]entmod ad[b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]setq ch T[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if ch [b][color=GREEN]([/color][/b]entupd en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

This gives you multiple possibilities.

 

Not tested. -David

Posted

 [b][color=BLACK]([/color][/b]setq al '[b][color=FUCHSIA]([/color][/b][b][color=NAVY]([/color][/b][color=#2f4f4f]"CODE_4"[/color] [color=#2f4f4f]"See Jane Run"[/color] [color=#2f4f4f]"See Spot Die"[/color][b][color=NAVY])[/color][/b]
            [b][color=NAVY]([/color][/b][color=#2f4f4f]"CODE_4"[/color] [color=#2f4f4f]"See Dick Run"[/color] [color=#2f4f4f]"See Jane Run"[/color][b][color=NAVY])[/color][/b]
            [b][color=NAVY]([/color][/b][color=#2f4f4f]"CODE_4"[/color] [color=#2f4f4f]"See Jane Run"[/color] [color=#2f4f4f]"See Dick Die"[/color][b][color=NAVY])[/color][/b]
            [b][color=NAVY]([/color][/b][color=#2f4f4f]"CODE_5"[/color] [color=#2f4f4f]"See Spot Run"[/color] [color=#2f4f4f]"See Spot Drop"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

I like this approach for the logical chain can be quite deep.

 

If Dick's running before Jane then Spot gets to stay around for a while and out live Dick.

 

-David

 

 

The moral to the story is that it doesn't pay to be a Dick or a dog

Posted

Just curious, David...

 

Why do you prefer the list method over using cond?

Posted
Just curious, David...

 

Why do you prefer the list method over using cond?

Easier for novice to edit/add to.

 

 

You could also use a dotted pair and assoc.

Posted
Easier for novice to edit/add to.

 

Exactly!

 

And for my uses, I could write the list in an external file, ( load ) the data, and roll. -David

Posted

I've used dotted pairs in the past (and obviously cond, hence the question) with some of my command reactors, sysvar store/set functions.

 

Alan / David, thanks for the prompt responses! :stein:

Posted
The moral to the story is that it doesn't pay to be a Dick or a dog

 

Evidently it doesn't pay to be a Cat either. :lol:

 

Just when I thought I had all the bases covered, they threw me a curve.

The titleblock has a multitude of attributes with the same tag, different values, evidently utilizing handles. Any suggestions?

Other than using the special explode feature. If all else fails, I'm not beyond using it. :P

Posted

That's ugly....

 

Is there any logic to the scenario? 1st tag is always the name, 2nd the date, 3rd the city etc?

 

Do you have the handle values? and their respective descriptions?

 

-David

Posted
The titleblock has a multitude of attributes with the same tag...

 

Rather you than me David :wink:

Posted
Rather you than me David :wink:

 

gee thanks!

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