A script for incrementing a block attribute - n00b to CAD scripting!

A script for incrementing a block attribute - n00b to CAD scripting!

Anonymous
Not applicable
1,557 Views
12 Replies
Message 1 of 13

A script for incrementing a block attribute - n00b to CAD scripting!

Anonymous
Not applicable
hi everyone. I want to write a script for a problem, but I'm not sure how to begin. I'm hoping someone will talk to me; see problem below: I have a dwg (2014) which contains many attributal blocks. Each block has an attribute called "crs number", which is a vertical location tracker, and this needs to be incremented after each row of blocks is completed. So, for example, I place a row of, say, 16 blocks all set to at "crs1", then start a new row, at "crs2" and place, another 16-block row, then start a new row of blocks all on "crs3"....etc.... What I would like is a way to easily increment the "crs #" attribute quickly and simply for edits. I don't know if I need LISP to do this. I can run -attedit_N_N at the command line, enter the block name and attribute tag name. What I want is for a way to tell CAD, "OK, increment c1 to c2, find the next 16 blocks of "block name" and change them to c2, and after 16 instances, increment to c3, and place this attribute in the next 16 blocks of "block name", and continue moving up until crs30. Exit." Not sure how to get started with translating this to a cad script. If anyone can even just point me in the right direction, I'd appreciate it. Thanks ***edit*** I don't want to explode the blocks, because each block has a unique part# that I want to keep.
0 Likes
1,558 Views
12 Replies
Replies (12)
Message 2 of 13

Ajilal.Vijayan
Advisor
Advisor

Can you post a sample drawing as well ?

0 Likes
Message 3 of 13

Anonymous
Not applicable

sure.  Example attached.

 

This shows the first 3 rows of the block objects, which have 3 attributes: BRICK ID (unique for every block), CRSID (the one I want to increment after every row, and REPORTID (stays the same for the blocks that have it, and will be different on new blocks in new revisions.)

 

Does that make sense?  Ask me if not.

0 Likes
Message 4 of 13

dbroad
Mentor
Mentor

As I noted in the AutoCAD 2016 forum, you don't need a program for this task.  The properties palette works fine here.  Reversing your numbering scheme can be done in 30 seconds as shown.

Architect, Registered NC, VA, SC, & GA.
Message 5 of 13

Anonymous
Not applicable

 

Thank you for point this out, as it'll be useful down the road (I just didn't realize, since I use only cammand line and have a blank screen) that you control the attributes 1 by 1 that way.  Well, it's how we learn.)  Kudos to you for that!

 

However, it's not the full solution, because each block has a unique attribute (called BRICKID) that orients the brick in space, and one of the numbers in it's name starts with B and increments from 1 to 16....I can change the CRS number with your method, but I still have to change every block for BRICKID now.

 

Is there a simple way for this too???

0 Likes
Message 6 of 13

Anonymous
Not applicable

Another question (which might lead me on my way), if anyone knows:

 

What commands does Autocad run in the backround when "Properties" is invoked? Even when I underscore or dash it, i.e. -Properties, _properties, acad stills brings up a graphical interface, and I can't "see behind" it.  If I knew the commands, I could write my own script or routine exploiting the command line options of the properties changes.

 

Just an Idea. 

0 Likes
Message 7 of 13

Anonymous
Not applicable

Also, for anyone interested in adding it to a script, the suggestion above with the properties panel is equal to the following on command line:

 

-attedit

no

no

<enter block name> "block name"

<enter attribute tag> "tag" (in my case, CRS)

<enter attribute value> "value of what currently is associated with "tag"

<enter string> "value" (as in above)

<enter new string> "new value"

regen

0 Likes
Message 8 of 13

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

 

However, it's not the full solution, because each block has a unique attribute (called BRICKID) that orients the brick in space, and one of the numbers in it's name starts with B and increments from 1 to 16....I can change the CRS number with your method, but I still have to change every block for BRICKID now.

 

Is there a simple way for this too???


You can try this routine

http://www.cadstudio.cz/en/download.asp?file=insertc&sort=

 

or read this older thread 

http://forums.autodesk.com/t5/autocad-2013-2014-2015-2016/block-numbering-script/m-p/5709030#M86345

 

0 Likes
Message 9 of 13

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Another question (which might lead me on my way), if anyone knows:

 

What commands does Autocad run in the backround when "Properties" is invoked? Even when I underscore or dash it, i.e. -Properties, _properties, acad stills brings up a graphical interface, and I can't "see behind" it.  If I knew the commands, I could write my own script or routine exploiting the command line options of the properties changes.

 

Just an Idea. 


Dash - Not all command are have it's command line version (properties, seach...)... so these you cannot use in scripts.

 

underscore has nothing to do with that - in foreign language versions of AutoCAD is undersore prefix used to run original english named command.

There is also dot prefix .command to run non-redefined versions of commands.

0 Likes
Message 10 of 13

dbroad
Mentor
Mentor

You cannot do what you want with command scripting!  Forget about it, if you think you can tackle this without programming experience.

 

If you want to do it yourself, which I think is admirable, first take a class on AutoLISP, VBA, or a .NET language.  Then learn about the way AutoCAD stores data.  If you fancy AutoLISP, then start with (entget(car(entsel))) and look at the structure of the returned list.

 

To get to attributes you will need:

(setq entity (car(entsel))) and select a block insert.

 

Then 

(setq info (entget (setq entity (entnext entity))))

 

This will allow you to step through the attributes to discover the structure of the block and the attributes when using legacy methods.

 

 

To change values you must use the sequence:

 

(entmod (subst '(code# . <newvalue>) (assoc code# info) info))

 

You will need to loop through your objects and come up with a strategy for how to label each block based on your criteria.  You have made the task slightly more difficult by using different block names and different attribute sequences.

 

IMO, your task is too specific for general programmatic approaches.  Therefore if this automation will be worth something for you, you should find someone who already knows programming and AutoCAD and hire him to create the program for you.  There are many on this newsgroup that are worth their hire. (Lee Mac, HMSilva, Kent1Cooper, etc.)

 

Good luck either way.

Architect, Registered NC, VA, SC, & GA.
Message 11 of 13

Anonymous
Not applicable

Thanks for the start.

 

I think I'm gonna read, "The Little Lisper."

 

I would like to put an interface on this, becaues the person I'm making it to help doesn't know any cad.

0 Likes
Message 12 of 13

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

 

 

However, it's not the full solution, because each block has a unique attribute (called BRICKID) that orients the brick in space, and one of the numbers in it's name starts with B and increments from 1 to 16....I can change the CRS number with your method, but I still have to change every block for BRICKID now.

 

Is there a simple way for this too???


I dare to make one more suggestion because lately I found this app which looks very good!

0 Likes
Message 13 of 13

dbroad
Mentor
Mentor

The Little Lisper was the first LISP text I read.  It's a classic.  Be sure to read about AutoLISP though.  There are differences.

Architect, Registered NC, VA, SC, & GA.
0 Likes