Jump to content

Change attributes


woodman78

Recommended Posts

Can someone help me with this? I have a block with an attribute. The attribute contains one word and is set to justification Middle Centre. I want to be able to change the block attribute but the new attribute will hve a lot more text and I want to be able to set it up that the text will run onto 2 or 3 lines. This can be set within the lisp as i add a new att definition to the lisp.

Link to comment
Share on other sites

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    19

  • woodman78

    18

  • alanjt

    1

  • BearDyugin

    1

Top Posters In This Topic

Posted Images

For multiple lines you would have to use a Multiline Attribute - do all your blocks use these?

Well same it is easy to correct, if Vla-get-MTextAttribute :vla-false , then Vla-put-MTextAttribute :vla-true

Link to comment
Share on other sites

I want to create a lisp and dialog that would allow the user to select an option from the dialog and that would be put into the attribute. Depending on the length it would be split into a number of lines. Presumably this would need to be setup in the lisp or is there a way to limit the width of the multi-line attribute so it runs onto the next line.

 

I would appreciate help with this.

Link to comment
Share on other sites

It depends how you want to approach it -

 

You could use a list_box, popup_list, etc... think about how you want the dialog to look.

 

Would it be used to replace existing text in attributes? or entered into blocks that are being inserted (you could even use a reactor in this case)...

 

You could even read your attribute information from a text file, so that it is easier to edit..

 

Just offering a few suggestions,

 

Lee

Link to comment
Share on other sites

I want to do it with a popup list and I really like the idea of using a txt file to store the data. The block name is "project_names".

Link to comment
Share on other sites

Ok, so now you can think about the step by step process of how the LISP would work... call it pseudo-code.

 

I would think something like:

  • Prompt the user to select an attribute to update. The code could be set to either get the attribute directly (using nentsel perhaps), or for a selection of a block(s) and prompt the user for which tag to update... the code would need to check that the user is selecting the right objects, or if they are selecting anything at all.

  • If the location of the txt file from which data will be read is not known, prompt for the selection of this file. (Think about how you might go about storing the location of this file - you could hard code it into the LISP, store it as a global variable [in which case it would only last for the time spent in one drawing], or even write a config file to the support path, storing the location of the data file. Or you could write a registry key storing the information.

  • Load the dialog, populate the popup_list with strings read from the txt file (perhaps think about the format of how the data would be stored in the txt file, what would be used to separate each data item, how would you signify where the new line should be etc. Also, would the items need to be shortened to fit in the popup_list, if so, by how much? Also, would a list_box be perhaps clearer, as all options are laid open for the user to see...

  • When the item is selected, its easy from here on, the code just needs to replace the textstring for the new one - the code would also need to watch out for trying to put data with multiple lines into an attribute that only allows a single line - so the attribute may need to be converted - should this be allowed? As it goes against the block definition in the block table, and the action could be overwritten with a single "attsync"...

Those are just some things to think about - the bare bones of what needs to be considered when thinking about writing such a function.

 

Lee

Link to comment
Share on other sites

Prompt the user to select an attribute to update. The code could be set to either get the attribute directly (using nentsel perhaps), or for a selection of a block(s) and prompt the user for which tag to update... the code would need to check that the user is selecting the right objects, or if they are selecting anything at all.

 

Lee, I was thinking to take the user selection out of the lisp altogether. Only adds another layer of confusion that will mean more time that the lads come to me with questions. I want the lisp to be coded to select a block of a specific name and a specific attribute within that block. No options.

 

 

If the location of the txt file from which data will be read is not known, prompt for the selection of this file. (Think about how you might go about storing the location of this file - you could hard code it into the LISP, store it as a global variable [in which case it would only last for the time spent in one drawing], or even write a config file to the support path, storing the location of the data file. Or you could write a registry key storing the information.

 

Again I was thinking for writing the location of the text file into the lisp and not messing around with other options.

 

Load the dialog, populate the popup_list with strings read from the txt file (perhaps think about the format of how the data would be stored in the txt file, what would be used to separate each data item, how would you signify where the new line should be etc. Also, would the items need to be shortened to fit in the popup_list, if so, by how much? Also, would a list_box be perhaps clearer, as all options are laid open for the user to see....

 

I was thinking that the data will be stored in the text file per line. Each entry will be on a new line. Items would need to be shortened to fit the popup_list as they can be quite lengthy. I prefer a popup_list as this list will keep growing and so a list box would become too big. It isn't something that will be used many times every day so I don't see the popup_list being too much of an inconvenience.

 

When the item is selected, its easy from here on, the code just needs to replace the textstring for the new one - the code would also need to watch out for trying to put data with multiple lines into an attribute that only allows a single line - so the attribute may need to be converted - should this be allowed? As it goes against the block definition in the block table, and the action could be overwritten with a single "attsync"....

 

I see the block being created before and not on the fly so the attirbute can be set as above for a multiline with a width set so that should deal with that no???

Link to comment
Share on other sites

Lee, I was thinking to take the user selection out of the lisp altogether. Only adds another layer of confusion that will mean more time that the lads come to me with questions. I want the lisp to be coded to select a block of a specific name and a specific attribute within that block. No options.

 

Ok, so in this case, would the block and tag always be coded into the LISP?

 

I prefer a popup_list as this list will keep growing and so a list box would become too big. It isn't something that will be used many times every day so I don't see the popup_list being too much of an inconvenience.

 

Just as a suggestion, you can easily limit the size of a list_box, so that it will have a scroll bar.

 

I see the block being created before and not on the fly so the attirbute can be set as above for a multiline with a width set so that should deal with that no???

 

I'm just offering my thoughts - if the block you wanted to update did have a single line attribute, and you wanted to update it with multiple lines, this would mean changing the block outside of the definition, unless the block was redefined.

Link to comment
Share on other sites

Thanks for the suggestions Lee, I like the idea of the List_box with the scroll bar is much better.

I was thinking the block and the tag would be coded into the lisp. Is there a benefit in doing it a different way?

Link to comment
Share on other sites

Shall I get us going off the mark...

 

Hows this for a DCL?

 

attchange : dialog { key = "dctitle";
 spacer;  
 : list_box { label = "Attribute Strings:"; key = "lst"; alignment = centered;
              fixed_height = true; fixed_width = true; width = 50; height = 20; }
 spacer;
 ok_cancel;
}

Link to comment
Share on other sites

Lee,

 

I'm goona try to get some time over the weekend on afralisp.net and see how far I get with this one. Thanks for the head start.

Link to comment
Share on other sites

This should help you along the way, it will read a file and return a list of each line:

 

(defun _read (file / ofile lst nl)

 (cond (  (setq ofile (open file "r"))
        
          (while (setq nl (read-line ofile))
            (setq lst (cons nl lst)))

          (close ofile)))
 
 (reverse lst))

 

You need to supply it with a valid filename.

Link to comment
Share on other sites

Lee,

 

I didn't get much time at lisp over the weekend but I hope I will get some time in the next few days.

 

 

Thanks.

Link to comment
Share on other sites

I couldn't resist the urge to write this one - it isn't too difficult. But I would recommend that you study the code so that you can write similar programs in the future.

 

LISP code:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:Change_Att [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] *error* _read

                      BLOCKNAME DCFILENAME DCFLAG DCTAG
                      ELST ENT I PTR SS STR STRFILENAME
                      STRLST TAGSTRING[b][color=RED])[/color][/b]

 [i][color=#990099];; Lee Mac  ~  01.03.10[/color][/i]
 

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dcfilename  [b][color=#a52a2a]"Change_Att.dcl"[/color][/b]   [i][color=#990099];; DCL Filename[/color][/i]

       Strfilename [b][color=#a52a2a]"Change_Att.txt"[/color][/b]   [i][color=#990099];; Data Filename[/color][/i]

       BlockName   [b][color=#a52a2a]"project_names"[/color][/b]    [i][color=#990099];; Block Name[/color][/i]

       TagString   [b][color=#a52a2a]"Tag_String"[/color][/b]       [i][color=#990099];; Tag String[/color][/i]

  [b][color=RED])[/color][/b]


 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] *error* [b][color=RED]([/color][/b]msg[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] dcTag [b][color=RED]([/color][/b][b][color=BLUE]unload_dialog[/color][/b] dcTag[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]wcmatch[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcase[/color][/b] msg[b][color=RED])[/color][/b] [b][color=#a52a2a]"*BREAK,*CANCEL*,*EXIT*"[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\n** Error: "[/color][/b] msg [b][color=#a52a2a]" **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]


 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] _read [b][color=RED]([/color][/b]file [b][color=BLUE]/[/color][/b] ofile lst nl[b][color=RED])[/color][/b]

   [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ofile [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] file [b][color=#a52a2a]"r"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
        
            [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] nl [b][color=RED]([/color][/b][b][color=BLUE]read-line[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
              [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] nl lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

            [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 
   [b][color=RED]([/color][/b][b][color=BLUE]reverse[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b]


 [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=#009900]-1[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_X"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#a52a2a]"INSERT"[/color][/b][b][color=RED])[/color][/b]
                                               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]2[/color][/b] BlockName[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]66[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\n** No Blocks with Name: "[/color][/b] BlockName [b][color=#a52a2a]" Found **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

       [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] Strfilename [b][color=RED]([/color][/b][b][color=BLUE]findfile[/color][/b] Strfilename[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n** Data File not Found **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

       [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] StrLst [b][color=RED]([/color][/b]_read Strfilename[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n** Data File Empty **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

       [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]<=[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dcTag [b][color=RED]([/color][/b][b][color=BLUE]load_dialog[/color][/b] dcfilename[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n** Dialog Definition Not Found **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

       [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]new_dialog[/color][/b] [b][color=#a52a2a]"attchange"[/color][/b] dcTag[b][color=RED])[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n** Dialog Could not be Loaded **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

       [b][color=RED]([/color][/b]t
          [b][color=RED]([/color][/b][b][color=BLUE]start_list[/color][/b] [b][color=#a52a2a]"lst"[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] add_list[b][color=RED])[/color][/b] StrLst[b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]end_list[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ptr [b][color=RED]([/color][/b][b][color=BLUE]set_tile[/color][/b] [b][color=#a52a2a]"lst"[/color][/b] [b][color=#a52a2a]"0"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
        
          [b][color=RED]([/color][/b][b][color=BLUE]action_tile[/color][/b]  [b][color=#a52a2a]"lst"[/color][/b] [b][color=#a52a2a]"(setq ptr $value)"[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dcFlag [b][color=RED]([/color][/b][b][color=BLUE]start_dialog[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dcTag [b][color=RED]([/color][/b][b][color=BLUE]unload_dialog[/color][/b] dcTag[b][color=RED])[/color][/b] TagString [b][color=RED]([/color][/b][b][color=BLUE]strcase[/color][/b] TagString[b][color=RED])[/color][/b]

                Str   [b][color=RED]([/color][/b][b][color=BLUE]nth[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]atoi[/color][/b] ptr[b][color=RED])[/color][/b] StrLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b]

          [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]=[/color][/b] [b][color=#009900]1[/color][/b] dcFlag[b][color=RED])[/color][/b]

            [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

              [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#a52a2a]"SEQEND"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] eLst [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]entnext[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

                [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] TagString [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]2[/color][/b] eLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]entupd[/color][/b]
                    [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]-1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]1[/color][/b] Str[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] eLst[b][color=RED])[/color][/b] eLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

            [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n*Cancel*"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]


DCL Code:

 

attchange : dialog { key = "dctitle";
 spacer;  
 : list_box { label = "Attribute Strings:"; key = "lst";
              alignment = centered; fixed_height = true;
              fixed_width = true; width = 50; height = 20; }
 spacer;
 ok_cancel;
}

Lee

Link to comment
Share on other sites

Lee,

 

I tried to run the lisp but nothing updated. I didn't get any errors but nothing happened either. I am also trying to include another tag within the same block that the first word of the line in the text file will update the second attribute.

 

e.g.

Text file line: R600 Blah de Blah de Blah

Attribute 1: R600 Blah de Blah de Blah

Attribute 2: R600

 

I can do this using the str car function yeah??

Link to comment
Share on other sites

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