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

automatic numbered block attribute

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
Anonymous
23796 Views, 25 Replies

automatic numbered block attribute

hi all,

 

i wanted to see if anyone can help me do this, i know how to make attribute/dynamic block

but what i'm trying to do or wishing i could make is an attibute number block that when

i insert it i can input the number i want but then when i insert it again it will pick up from

the last number i use. anyone please?

 

thanks,

 

5spot

25 REPLIES 25
Message 2 of 26
Kent1Cooper
in reply to: Anonymous

If there's just the one Attribute, something like this, perhaps....

 

(while T
  (command "_.insert"
    "YourBlockName"
    pause ; for insertion point
    "" "" "" ; default scales/rotation
    (if (attnum)
      (itoa (setq attnum (1+ attnum)))
      (itoa (setq attnum (getint "First number value: ")))
    )
  )
)

 

That's assuming integer number values, X & Y scale factors of 1, and rotation of 0 -- adjust as required, with pauses or variable values or something.  Provide replies to any additional prompts that will appear for a dynamic Block, if any [I don't have those -- this is based on ordinary-Block Insert behavior].

That would be for inserting a bunch of them, automatically repeating until the User hits Escape.  [However, if called up again in the same editing session, it would not ask for a number again, but would continue with the next one.]  If you just want to do one at a time, doing other things in between, take the (while) wrapper off.  Just make sure the 'attnum' variable is not localized in the (defun) function definition if that's how you do it, and that it's not also used as a variable name in other routines that could override its value [if that seems at all likely, use a more routine-particular name].

 

No Layer or error controls or anything yet....


5spot wrote:

....what i'm trying to do or wishing i could make is an attibute number block that when

i insert it i can input the number i want but then when i insert it again it will pick up from

the last number i use. anyone please?

....


Kent Cooper, AIA
Message 3 of 26
Anonymous
in reply to: Anonymous

5,

 

Try this snippet. To save running the extraction code each time you could store the new tagvalue as a global variable and check for it's presence. Something to get you started...

 

S

 

 (if (null *tagvalue*)
  (progn
    (setq blockname "TEST"
   ss (ssget "X" (list (cons 0 "INSERT") (cons 2 blockname)))
   count 0
   taglist nil
   )
    (repeat (sslength ss)
      (setq ent (ssname ss count))
      (while (and ent (/= "SEQEND" (cdr (assoc 0 (entget ent)))))
 (setq cont (entget ent))
 (if (= (cdr (assoc 0 cont)) "ATTRIB")
   (setq taglist (cons (cdr (assoc 1 cont)) taglist))
   )
 (setq ent (entnext ent))
 )
      (setq count (1+ count))
      )
    (setq taglist (acad_strlsort taglist)
   *tagvalue* (itoa (1+ (atoi (last taglist))))
   )
    )
  (setq *tagvalue* (itoa (1+ (atoi *tagvalue*))))
  )
(command "-insert" "TEST" pause 1 1 0 *tagvalue*)

Message 4 of 26
stevor
in reply to: Anonymous

The autonumber is a very common use of autolisp, and you should find plenty of examples.

 

Kents' format is the better basic form, to which you will probably add features to match the attribute structure of your  BLOCKs;  and layers, etc.

 

One mod is the insert point, to exit the function, by replacing the 'T' with the getpoint:

 

(while (setq bip (getpoint "\n Pick Insert Point: ")) ; stops if a no pick
  (command "_.insert"    "YourBlockName"
                  bip ; for insertion point

.......

 

The next mod would be to set the current layer, as he said,  before and then after the while loop.

 

 

S
Message 5 of 26
Kent1Cooper
in reply to: stevor

Just for your consideration --

 

While using the picking of a point as a test in the (while) function has its advantages, it also has the small disadvantage that you can't see the Block to drag it into place dynamically, since the insertion point is specified outside the Insert command.  In either case, the User needs to do something other than pick a point to stop the loop -- with T as the test, I think it has to be Escape, while with stevor's suggestion, Enter/space will also do it.  Dragging visually, as one can with Insert generally, may not be important depending on other circumstances, but it's one possible reason to choose one approach over another.


@stevor wrote:

....

One mod is the insert point, to exit the function, by replacing the 'T' with the getpoint:

(while (setq bip (getpoint "\n Pick Insert Point: ")) ; stops if a no pick
....


Kent Cooper, AIA
Message 6 of 26
Anonymous
in reply to: Kent1Cooper

hi kent,

 

really appreciate the quick response, i just tried it and having some

error, i attached the block and your lisp, below is the error

message. the block would be as you describe, straight forward

block attribute, i have not tried scott yet but appreciate the help.

i will be learning more about lisp and vlisp.

 

5spot

 

Command: (load "d:/my documents/my lisps/tag")
_.insert Enter block name or [?] <tag>: tag.dwg
Units: Inches   Conversion:    1.0000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: Enter Y
scale factor <use X scale factor>:
Specify rotation angle <0>:
Enter attribute values
#?: ; error: no function definition: ATTNUM
#?:

Message 7 of 26
Anonymous
in reply to: Anonymous

5,

 

Change (if (attnum) to (if attnum

 

S

Message 8 of 26
Anonymous
in reply to: Anonymous

Scott,

 

i did change this and it works, and i also tried yours last night and it works too, yours and

Kent works similar, i know you know the difference, kent's can start inserting the block

with his lisp or insert the block first with the insert command and  follow up with the next

number and continuously insert unless i hit escape and that stop the lisp/command.

yours on the other hand, needs to have the block inserted first by the insert command

and follows the number one at the time but that does'nt give an error message at the

end of the strings, kent's does thou which he had mentioned it too. my question thou,

after inserting the block at the beginning, both of your lisps picks that up and inputs

the next number, however, if i do a manual insert of the block after invoking both of your

lisps, tne next time i run your lisps, it does'nt pick up the last one i inserted manually but

picks up the last block/number inputed by the lisps., what i was hoping is the lisps would

pick up the last block whether it was manually inserted or inserted with the lisps. again

i really appreciate your help and this forum, learned a lot from this forum and i actually

started reading bout visual and auto lisp. the layers i can do that later when i learn how

to lisps, for now i would make my block on the layer i wanted it to come out.

 

5spot

Message 9 of 26
Anonymous
in reply to: Anonymous

5,

 

You have two options:

 

1 - Only ever insert your block using your lisp routine. I do this by using anonymous blocks (they don't appear in the drop-down list in the Insert screen), so users have to use the lisp routine to insert them.

 

2 - Remove the  (if (null *tagvalue*) (progn and associated closing brackets. This means that everytime the lisp is used to insert the block all instances of the block will be checked, listed, sorted and the number determined. If you were to time this action you'd be looking at milliseconds for most cases so this would be the best (and quickest) option.

 

S (aturday night - time for tequila!)

Message 10 of 26
Anonymous
in reply to: Anonymous

Scott,

 

your right, sat is for tequilla, i'm actually at a friends house right now

having tequilla, but i will try that suggestion early tomorrow, i also found

out about our lisp, i created the same block with a different name and change

the lisp with the new block name, so i have 2 the same block with different name

and two lisp with different name, whichever lisp i run, i picked up the last block

inserted and continued the last number even though a different block being inserted.

now, enjoy you tequilla sat. thanks again.

 

5spot

Message 11 of 26
3wood
in reply to: Anonymous

Message 12 of 26
Anonymous
in reply to: 3wood

3wood,

 

hi,

 

i tried this, it works but its a trial for now co'z i have to

register? how does this works? thanks

 

5spot

Message 13 of 26
Anonymous
in reply to: Kent1Cooper

would you be so kind to explain how this works for dummies?
i apploaded the lisp to the autocad, and now, how do i use the auto number lisp? with the -insert command i inserted the prepared attributed block, but it still asks me to enter the value manually. i'm using the autocad for mac, does that make a difference in the code?

thank you for the patience,
D

Message 14 of 26
pendean
in reply to: Anonymous

Friend, here a freebie in the Autodesk App Store that does autonumbering, install it and use it as you wish with text or blocks or anything else you want https://apps.autodesk.com/ACD/en/Detail/Index?id=8051485828049059617&appLang=en&os=Win32_64
Message 15 of 26
Anonymous
in reply to: Anonymous

hi,

this is a while back, I'm not using this block anymore co'z our program does it
for our purpose now but I suggest going to 3wood site, he is an expert on this attribute
and you will find a variety of tools that will help you a lot. you can email him at 3wood.cadkits@gmail.com3wood.cadkits>.
or follow this link.. https://sites.google.com/site/cadkits/home , you can join his it's free. I believe
what you are looking for is the INNB, you can download it for free and try it if that's what you need.

good luck

Rolly Hao


This e-mail and all attachments to it are for the sole use of the intended recipients and may contain proprietary information and trade secrets of Deltasheetmetal and its affiliates. This e-mail may also contain information which is confidential or which is protected from disclosure by privilege. Any unauthorized use, disclosure or distribution of this e-mail and its attachments is prohibited. If you are not the intended recipient, let us know by reply e-mail and then erase and destroy all electronic or other copies of this message3wood.cadkits>
Message 16 of 26
Anonymous
in reply to: Anonymous

Dean, Rolly, thank you for your prompt answers and suggestions.
But the .MSI and .VLX files don't work with the OS X Autocad version i'm using. I coudn't find the autonumber function as a .LISP anywhere, so i figured i create the lisp myself using the codes provided above, but it's not quite working. 

Message 17 of 26
Anonymous
in reply to: Anonymous

hi,

then I suggest trying Dean Saadallah suggestion, try and see if anything works with
the OS you have. I have not been working with lisp for a while now co'z we have
3rd party program that we use for autocad. my company does ductworks.

Rolly Hao


This e-mail and all attachments to it are for the sole use of the intended recipients and may contain proprietary information and trade secrets of Deltasheetmetal and its affiliates. This e-mail may also contain information which is confidential or which is protected from disclosure by privilege. Any unauthorized use, disclosure or distribution of this e-mail and its attachments is prohibited. If you are not the intended recipient, let us know by reply e-mail and then erase and destroy all electronic or other copies of this message
Message 18 of 26
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

would you be so kind to explain how this works for dummies?
i apploaded the lisp to the autocad, and now, how do i use the auto number lisp? with the -insert command i inserted the prepared attributed block, but it still asks me to enter the value manually.....


Turn ATTDIA off [set the System Variable to 0] to have it not ask you, but take the value that the routine feeds in.

 

If you haven't done this already, it would need to be either included in some larger routine [which could, for example, set the appropriate Layer, and various other things, in addition to this part], or at least defined into a command, such as [in simplest terms]:

 

(defun C:IBINA (); = Insert Block w/ Incremented Number Attribute
  (while T
    (command "_.insert"
      "YourBlockName"
      pause ; for insertion point
      "" "" "" ; default scales/rotation
      (if attnum
        (itoa (setq attnum (1+ attnum)))
        (itoa (setq attnum (getint "First number value: ")))
      ); if
    ); command
  ); while
); defun

Then after saving that into a .lsp file and APPLOADing it, you would use the command name IBINA [change that to anything you prefer] to use it.

 

 

It could also ask for a Block name, rather than have it built in, and could use assorted other improvements/enhancements.

 

It's for a Block that's not defined for uniform scaling -- if yours is, remove one of the three "" Enters in that one line.

 

NOTE:  There was a mistake in the original -- it had:

      (if (attnum)

but the attnum should not have been in parentheses [corrected above].

Kent Cooper, AIA
Message 19 of 26
Anonymous
in reply to: Anonymous

hi, it is possible to make a program that auto number atributes  from one dynamic block based on block lenght for example?  

i have 200 copy of one dynamic block with differit lengths, all of them are caller "M1" but i want to number them acording to their lenght 

if the lenght is between 1000 and 1001 give that attribut M2, if lenght is between 500-501 name it m2, or not necesarly between more likely around 

if lenght is around 1000 (999-1001) rename atribut m1 to m22 and so on.

Message 20 of 26
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

... it is possible to make a program that auto number atributes  from one dynamic block based on block lenght for example?  

....


Welcome to these Forums!

 

That is a different enough thing from the subject of this thread that I suggest you start a new one.  But when you do, fill in some more information, such as:

 

Are these Blocks already inserted and dynamically adjusted in length, and you want to edit an Attribute on that basis, after the fact rather than in the process of inserting as on this thread?

 

Is the "M1" the name of the Block [as suggested by your ' all of them are calle[d] "M1" ', or the value in an Attribute in it [as suggested by the changes you want to make]?

Kent Cooper, AIA

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report