I need a LISP solution to sequentially number attributes

I need a LISP solution to sequentially number attributes

Anonymous
Not applicable
3,694 Views
9 Replies
Message 1 of 10

I need a LISP solution to sequentially number attributes

Anonymous
Not applicable

I have a real problem here.  I need a LISP solution to sequentially change attributes in blocks.  I know there are several excellent solutions out there...but my blocks are coming from Inventor/Factory Design Suite.  AutoDesk made an extremely short-sighted, ill-advised change in the 2017 program versions, and now the attributes don't behave correctly.  You can click on one of the blocks in the attached file, and the Enhanced attribute editor pops up....but try running BATTMAN and you'll get the insane message "this drawing contains no attributed blocks." (attached image) 

 

If I remember correctly, someone recently told me that now they're "dictionary extension objects" or something like that. 

I still say if it opens in the attribute editor, then it's an attribute, but AutoDesk doesn't agree with me.

 

In the attached example dwg, I need all the "attributes" that default as "W" to be renumbered to say: -W101, -W102, -W103, etc, based on the order that the blocks are selected.  The way we usually do this is click on all the blocks in order, then LISP changes all the defined "attributes" in the order that the blocks were clicked on.

 

I really need a way to fix this problem.  My layouts can have several hundred of these blocks at a time, and it worked PERFECTLY in 2016 where I could number everything sequentially very rapidly.  2017 has utterly destroyed that functionality, and I really need it back!  AutoDesk refuses to restore the original functionality that actually WORKED.

 

I'll even pay someone to write the code for me...feel free to PM me on that.  There's a few more minor things that go into this, etc... Thanks in advance for any help!

Accepted solutions (2)
3,695 Views
9 Replies
Replies (9)
Message 2 of 10

Shneuph
Collaborator
Collaborator

This seems to work for me.. You can build on it w/ error checking input verification whatever you want.  But it's a start.  If you get any "No function definition VLA....) put (vl-load-com) after the defun line.

 

(Defun C:Number_Atts ( / startnum b1 atts attstring)
  (setq startnum (getint "\nEnter Starting Number: "))
  (setq n startnum)
  (while (setq b1 (vlax-ename->vla-object (car (entsel))))
    (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes b1))))
    (foreach att atts
      (if (= (vla-get-tagstring att) "ADSKFACTORY:Custom.ASSET_TAG")
	(vla-put-textstring att (strcat "W" (itoa n)))
	);if
      );foreach
    (setq n (1+ n))
    );while
  (princ)
  );Defuns
---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 3 of 10

Ranjit_Singh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

.......... someone recently told me that now they're "dictionary extension objects" or something like that. 

I still say if it opens in the attribute editor, then it's an attribute, but AutoDesk doesn't agree with me.

.....

 

That was me who told you that I believe over here.

Try below for example. No error trap and minimal checking.
(defun c:somefunc  (/ dat ent etdata found post pre ss1)
 (setq pre  (getstring "\nEnter new attrib prefix: ")
       post (1- (getint "\nEnter new attrib suffix: ")))
 (while (setq ss1 (ssget ":s" '((0 . "insert") (66 . 1))))
  (setq found ()
        dat   (strcat pre (itoa (setq post (1+ post))))
        ent   (ssname ss1 0))
  (while (and (setq ent (entnext ent)) (null found))
   (setq etdata (entget ent))
   (and (= (cdr (assoc 0 etdata)) "ATTRIB")
        (= (cdr (assoc 2 etdata)) "ADSKFACTORY:Custom.ASSET_TAG")
        (setq found t)
        (entmod (subst (cons 1 dat) (assoc 1 etdata) etdata))))))

attrib_change.gif

Message 4 of 10

Anonymous
Not applicable

Thanks much to you both!  AWESOME! Smiley Very HappySmiley HappySmiley Very Happy

0 Likes
Message 5 of 10

Anonymous
Not applicable

Ranjit  (or anyone else) : 

 

I showed this to my electrical group, and they are thrilled, so thank you again...

 

...they have one more request (of course).  Could you add one more prompt for an additional letter suffix that they can designate?  So that the beds would read, for example: 

 

-W101A

-W102A

-W103A

 

or

 

-W101B

-W102B

-W103B

 

etc etc etc...

 

This would seal the deal with them and be just ultimately utter awesome.  Thanks again!

0 Likes
Message 6 of 10

Ranjit_Singh
Advisor
Advisor
Accepted solution

Try below

(defun c:somefunc  (/ ent etdata found post post2 pre ss1)
 (setq pre   (getstring "\nEnter new attrib prefix: ")
       post2 (getstring "\nEnter new attrib suffix: ")
       post  (1- (getint "\nEnter starting integer: ")))
 (while (setq ss1 (ssget ":s" '((0 . "insert") (66 . 1))))
  (setq found ()
        ent   (ssname ss1 0))
  (while (and (setq ent (entnext ent)) (null found))
   (setq etdata (entget ent))
   (and (= (cdr (assoc 0 etdata)) "ATTRIB")
        (= (cdr (assoc 2 etdata)) "ADSKFACTORY:Custom.ASSET_TAG")
        (setq found t)
        (entmod (subst (cons 1 (strcat pre (itoa (setq post (1+ post))) post2)) (assoc 1 etdata) etdata))))))

attrib_change_2.gif

Message 7 of 10

Anonymous
Not applicable

Man Very HappyMan Very HappySmiley Very HappySmiley Very Happy

Message 8 of 10

Anonymous
Not applicable

I like the above solution. It works

0 Likes
Message 9 of 10

Anonymous
Not applicable

NiceSmiley Happy

0 Likes
Message 10 of 10

lsokutan
Enthusiast
Enthusiast

This time, when we tabulate with the table command, the order is mixed. Do you have a solution for this?
Or can it be initially shown as digit 01?

0 Likes