Jump to content

Adding Prefix to ITEM_NUMBER tag only


Recommended Posts

Hi,

 

Task 1: I need help on adding prefix to an attribute tag named ITEM_NUMBER but dont want to increment. Below is a code from Lee Mac that has prefix + increment and I tried to manipulate it but was unsuccessful. Could some one help me please?

 

Also, prefix would change between different drawings. So, if its asks for prefix, would be great.

 

Task #2 The ultimate goal is that once I add prefix to item number, I will copy this and modify to add prefix to BALIN tag (which is a balloon). This way I will have same prefix+number for the ITEM_NUMBER and BALIN tags.

 

Task #3

Once this is done, and everything arranged on the drawing, I would like a utility to renumber the item numbers by removing prefix and re-incrementing it. And while doing that, It should changes at both places at once (since the prefix + number are exact both places). The tricky thing here is that multiple balloon could reference the same number since that part could be used at multiple places.

 

Not sure if this sounds feasible? But if it does, It will save a big time headache for me since some of my drawings have about 50+ items and balloon which needs to be arranged.

 

 

 

 
(defun c:incatt ( / tag pre ss1 ) (vl-load-com)

(setq tag "ADDRESS" pre "ADDRESS: ")

(if (setq *num* (cond ( (getint (strcat "\nSpecify Starting Number" (if *num* (strcat " <" (itoa *num*) "> : ") ": ")))) ( *num* )))
(while (setq ss1 (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
(if
(vl-some
(function
(lambda ( x )
(if (eq tag (vla-get-tagstring x))
(not (vla-put-textstring x (strcat pre (itoa *num*))))
)
)
)
(vlax-invoke (vlax-ename->vla-object (ssname ss1 0)) 'getattributes)
)
(setq *num* (1+ *num*))
(princ (strcat tag " Attribute not found."))
)
)
)
(princ)
)

Link to post
Share on other sites
  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

  • shailujp

    16

  • Tharwat

    7

  • cwake

    5

  • Lee Mac

    5

Top Posters In This Topic

Posted Images

I'm not sure I understand how tasks 2 and 3 are intended to work? Is "BALIN" the tag of an attribute in the same block as "ITEM_NUMBER"? I think a little more explanation may be required.

 

Task 1 is not so difficult as a task in itself.

 

(defun c:incatt2 ( / tag pre ss1 ) (vl-load-com)

 (setq tag "ITEM_NUMBER")

 (if (/= (setq pre (getstring T (strcat "\nEnter Prefix for Attribute \"" tag "\": "))) "")
   (while (setq ss1 (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
     (if
       (null
         (vl-some
           (function
             (lambda ( x )
               (if (eq tag (vla-get-tagstring x))
                 (not (vla-put-textstring x (strcat pre (vla-get-textstring x))))
                 )
               )
             )
           (vlax-invoke (vlax-ename->vla-object (ssname ss1 0)) 'getattributes)
           )
         )
       (princ (strcat "Attribute " tag " not found."))
       )
     )
   )
 (princ)
 )

Link to post
Share on other sites

Hi Clint.

 

Task 2 is what I will duplicate the task 1 routing and just change the Tag name from ITEM_NUMBER to BALIN. Item number is actually part of the Bill of Material (BOM) and BALIN is the balloon which corresponds to the item number. My work requires copying partial BOM from other drawings (may be 2 or three drawings at a time) and then restructure the target drawing BOM based on the standard (i.e all the Screws first, then all the washers etc...). So, usually I will copy the Partial BOM from other drawing and add prefix say "A" and will copy the balloon from other drawing as well with prefix "A". Similarly "B" and "C" etc.... Once I have the new items inserted in the drawing, I will then restructure the bom to group similar items together. Once I have everything done, I will then increment the Item Number of BOM using Lee's Lisp routine. At this point, while doing the increment, if the new routine can also trigger the balloon change automatically (based on the attribute match) is what I'm looking for. Actually this will also help me reduce my checking time since Lisp can reduce errors of incorrect balloon numbering.

 

Does this explanation help?

Link to post
Share on other sites

If no one else helps out I might have a look at it tomorrow. I have to say that what I'm hearing sounds like it lends itself to fields. If you replaced the ITEM_NUMBER attribute with a field that linked to the value of BALIN in the balloon, then you would only need to update the attribute value in the balloon, and the BOM would update automatically

Link to post
Share on other sites

I think in this case a sample drawing containing examples of the balloons and BOM would help as well if that's possible? Perhaps what I suggested before is back to front? If there were many balloons and one entry in the BOM then the fields would go the other way...

Link to post
Share on other sites

Unfortunately, I can not go with fields due to some technical issues. Now if its difficult via lisp and no worth the effort, I may settle with just the task 1 and do the rest manually.

Link to post
Share on other sites

Hi Shailujp

 

You are looking for a fairly specific outcome with task 3, and with the information available I do feel it isn't worth the effort.

What I have done is written a very generic routine that allows you to add a prefix, a suffix, or search and replace within a specific attribute's value.

 

If I understand what you are trying to do, you are trying to differentiate between data coming from different drawings by adding the prefix. So this function would allow you to do that; you could do that either at the beginning, the end, or both.

Then, once all of the information is collated and ordered in the target drawing you want to change the references to another code, still a unique code, but one that reflects the new collated order? The search and replace will allow you to do that.

 

It's a generic solution that will only help if I've understood the problem correctly. Hope it does.

 

(defun c:modatt ( / _Replacetext pref repl srch sscnt ss1 suff tag )
 
 (vl-load-com)
 
 (defun _Replacetext ( string pat newstr / found patlen replen strtsrch )
   (setq patlen (strlen pat)
         replen (strlen newstr)
         strtsrch 0
         )
   (while (setq found (vl-string-search pat string strtsrch))
     (setq string (strcat (substr string 1 found) newstr (substr string (+ found patlen 1)))
           strtsrch (+ found replen)
           )
     )
   string
   )
 
 (cond
   ((= (setq tag (getstring "\nEnter the Tag name of the Attribute to change: ")) "")
    (princ "\nNeed a tag name to proceed... exiting...")
    )
   ((progn
      (setq pref (getstring T (strcat "\nEnter Prefix to add to Attribute \"" tag "\" (or ENTER for none): "))
            suff (getstring T (strcat "\nEnter Suffix to add to Attribute \"" tag "\" (or ENTER for none): "))
            srch (getstring T (strcat "\nEnter String to Search for in Attribute \"" tag "\" (or ENTER for none): "))
            )
      (vl-every
        (function
          (lambda ( x )
            (= x "")
            )
          )
        (list pref suff srch)
        )
      )
    (princ "\nNothing to do... exiting...")
    )
   (T
    (and (/= srch "")
         (setq repl (getstring T (strcat "\nEnter String to Replace " srch " with in Attribute \"" tag "\" (or ENTER to remove it): ")))
         )
    (if (setq ss1 (ssget "_:L" '((0 . "INSERT") (66 . 1))))
      (repeat (setq sscnt (sslength ss1))
        (vl-some
          (function
            (lambda ( x )
              (if (eq tag (vla-get-tagstring x))
                (not
                  (vla-put-textstring x
                    ((lambda ( str )
                       (strcat pref
                               (if (= srch "") str (_Replacetext str srch repl))
                               suff
                               )
                       )
                      (vla-get-textstring x)
                      )
                    )
                  )
                )
              )
            )
          (vlax-invoke (vlax-ename->vla-object (ssname ss1 (setq sscnt (1- sscnt)))) 'getattributes)
          )
        )
      (princ "\nNothing selected."))
    )
   )
 (princ)
 )

Link to post
Share on other sites
shailujp

Hi Clint,

 

I think your first program (incatt2) works perfect for adding the prefix which solves my requirement since I'm only targetting ITEM_NUMBER. Once prefix are added and when I arrange per the desired sequence, I will use incatt function which will just renumber all the tags on the bill of materials. This is how I intend to use it. Balloons will anyways be done manual since they are everywhere on the drawing and not possible to select them in sequence.

 

When I was using incatt2, I thought it would be much better if it allows me to select multiple (either pre-selection or post but multiple) instead of single pick since I have more than few tags to prefix.

I ran into another issue with my BALIN tag. I just found that there were two types of balloons which have either BALIN or X as a tag name (must be old and new stuff getting mixed on the drawings). I wonder if all the tags (ITEM_NUMBER, BALIN or X) can be added into the incatt2 lisp and then I just type the desired prefix and keep selecting the either of these blocks. I think this one sounds logical since I have to add same prefix to Item number and balloon at the same time. Do you agree?

 

 

The MODATT programm is also a great generic tool to update any given attirbute. The only disadvantage here is that I have to know the tag name instead of automatically finding out from the selection of that attribute. Does this sound possible? This way, I just select the tag (it automatically know the tag name from the selection) and then asks me to either add/remove prefix/suffix?

 

For now, I will just stick to the incatt2 to get my job done.

 

Thanks for your help.

Link to post
Share on other sites

Hi Shailujp,

 

This is the equivalent of incatt2 written to handle a selection set of inserts instead of picking and processing them individually. To cover your problem of a range of possible attribute tag names it checks all attributes against a list of tags (which you can edit). If the tag name is in the list it will add the prefix to its attribute value.

 

(defun c:prefatts ( / pref sscnt ss1 tags )
 (vl-load-com)
 (setq tags (mapcar
              'strcase
              '([color=blue]"ITEM_NUMBER" "BALIN" "X"[/color])[b][color=red] ;<==== Put attribute TAG names here inside the list[/color][/b]
              )
       )
 (cond
   ((= (setq pref (getstring T "\nEnter Prefix to add to the selected attributes: ")) "")
    (princ "\nNothing to do... exiting...")
    )
   ((progn
      (if (null (cadr (ssgetfirst)))
        (princ "\nSelect Blocks to Modify: ")
        )
      (setq ss1 (ssget '((0 . "INSERT") (66 . 1))))
      )
    (repeat (setq sscnt (sslength ss1))
      (foreach x (vlax-invoke (vlax-ename->vla-object (ssname ss1 (setq sscnt (1- sscnt)))) 'getattributes)
        (if (member (strcase (vla-get-tagstring x)) tags)
          (vla-put-textstring x (strcat pref (vla-get-textstring x)))
          )
        )
      )
    )
   (T
    (princ "\nUnsuitable selection... Exiting...")
    )
   )
 (princ)
 )

 

The only disadvantage here is that I have to know the tag name instead of automatically finding out from the selection of that attribute. Does this sound possible?

(Almost) anything is possible. I wrote MODATT around the same concept as the other code which is controlling which attributes are modified by the tag name.

So are you describing the opposite to what you wanted with incatt2, where you would pick each attribute (the actual text inside the block) individually and modify (individually)?

Or are you describing a two step process, where you first select the attribute you want to modify, only so that the routine can identify what the tag name is, then second you create a selection set and modify the attributes that have the same tag name as the first selection? I'm unclear which you are seeking. You have to be careful that you don't request a routine that is useful to you once for a current application but never used again.

Link to post
Share on other sites
shailujp

Hi Clint,

 

I will use your updated code tomorrow and will come back to you on how it functions...I'm sure it does pretty well :)

 

As far as MODATT, I don't think my current task is in need of this. However, It sounds an interesting program and I'm sure I will be able to use it sometime in near future. I think, the code is fine as is and can be used as is. But when I think for entering the tag name manually, seems like a not-the-best-way. First a user will have to find the tag name. If the tag name is few letters long, no issues with this entering it, but if the name is long enough (say ITEM_NUMBER), it takes a bit more effort to write it and write it correctly. Just to resolve this, if a click can help capture the tag name would be great.

 

If I have to use MODATT, I would just select one tag, add prefix/suffix done.... select next tag add prefix/suffix done... I'm sure some users may have different idea about this but that would be purely depending whether multiple tags they want to prefix/suffix or just one. I will need to experiment with this though to understand the real-time scenario.

 

EDIT: I have tested it and PREFATTS works wonderfully well. Thank you for your helps. Cheers.

Edited by shailujp
Link to post
Share on other sites
  • 5 months later...

Hi all,

 

I Need help on this.

 

I modified this code which was originally created for incrementing numbers.

 

Original code:

(defun c:INCATT ( / tag pre ss1 ) (vl-load-com)

 (setq tag "ITEM_NUMBER" pre "")

 (if (setq *num* (cond ( (getint (strcat "\nSpecify Starting Number"  (if *num* (strcat " <" (itoa *num*) "> : ") ": ")))) ( *num* )))
   (while (setq ss1 (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
     (if
       (vl-some
         (function
           (lambda ( x )
             (if (eq tag (vla-get-tagstring x))
               (not (vla-put-textstring x (strcat pre (itoa *num*))))
             )
           )
         )
         (vlax-invoke (vlax-ename->vla-object (ssname ss1 0)) 'getattributes)
       )
       (setq *num* (1+ *num*))
       (princ (strcat tag " Attribute not found."))
     )
   )
 )
 (princ)
)

 

When I tried to modify this for incrementing alphabets, it gives me stringp 66 error. Could someone please help me on this?

 

I'm needing this to increment alphabets from A to Z and when that is over, the next number should be AA, AB, AC and so on. Is this sound possible?

 

Modified code:

(defun c:INCATT2 ( / tag ss1 ) (vl-load-com)

 (setq tag "X")

 (if (setq *num2* (cond ( (getstring (strcat "\nSpecify Starting num2ber"  (if *num2* (strcat " <" *num2* "> : ") ": ")))) ( *num2* )))
   (while (setq ss1 (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
     (if
       (vl-some
         (function
           (lambda ( x )
             (if (eq tag (vla-get-tagstring x))
               (not (vla-put-textstring x *num2*))
             )
           )
         )
         (vlax-invoke (vlax-ename->vla-object (ssname ss1 0)) 'getattributes)
       )
       (setq *num2* (1+ (ascii *num2*)))
       (princ (strcat tag " Attribute not found."))
     )
   )
 )
 (princ)
)

 

Thanks in advance!!

Edited by shailujp
Link to post
Share on other sites

Hi Tharwat,

 

For some reason, I cant see your reply in this post. I found in my e-mails and I tried your suggestion. It takes the first alphabet and then next one it starts giving 1,2,3.

 

Any suggestion?

Link to post
Share on other sites
Hi Tharwat,

 

For some reason, I cant see your reply in this post. I found in my e-mails and I tried your suggestion. It takes the first alphabet and then next one it starts giving 1,2,3.

 

Any suggestion?

 

Hi ,

 

Actually there was a problem with the routine that you posted before you modified your post and I just corrected the mistake of it and nothing's more than that .

 

Anyway , let work on your new request to see what I come up with .

Link to post
Share on other sites

Try this and let me know :)

 

(defun c:Test (/ ch st a s tag)
 ;;    Tharwat AL Shoufi 23.Aug.2014        ;;
 (setq tag "X")
 (if
   (and (/= (setq
              ch (getstring
                   "\n Specify first Alphabetical character <A,B,C ..>:"
                 )
            )
            ""
        )
        (setq st (substr (setq ch (strcase ch)) (strlen ch)))
        (if (< 1 (strlen ch))
          (setq a (substr ch 1 (1- (strlen ch))))
          (setq a "")
        )
        (if (< 64 (ascii st) 91)
          t
          (progn (princ "\n Wrong Alphabetical character !!") nil)
        )
   )
    (while (setq s (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1))))
      (foreach x (vlax-invoke
                   (vlax-ename->vla-object (ssname s 0))
                   'GetAttributes
                 )
        (if (eq tag (vla-get-tagstring x))
          (progn
            (vla-put-textstring
              x
              (strcat a st)
            )
            (if (= (ascii st) 90)
              (setq a (strcat a (setq st (chr 65))))
              (setq st (chr (1+ (ascii st))))
            )
          )
        )
      )
    )
 )
 (princ)
)

Edited by Tharwat
Link to post
Share on other sites

Hi Tharwat,

 

My tag name is X so I changed this line

(setq tag "4")

to

(setq tag "X")

Then it started working.

It works only when the tag is blank. If it has any existing number of alphabet, it adds it as Suffix. I wanted to remove existing aphabet or number and keep only new entry.

 

The other issue is when I reach to Z, the next number is giving is ZA and I was looking for it to be AA, AB AC.....AZ, BA, BA, BC,.,....BZ....etc...

 

Thank you.

Capture A.jpg

Link to post
Share on other sites

When the tag has no existing value...then the new alphabet input works perfectly. When there is already a value say B..and I want A, then it shows BA versus just plain B.

 

Make sense?

Link to post
Share on other sites

Now it works well. The last issue is: When it goes to AX AY AZ...next number is AAA AAB AAC instead of BA BB BC...is this even possible?

Link to post
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
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...