Jump to content

Multiple block, attribute tag value change needed


Recommended Posts

Hello:

 

In an ACAD 2007 drawing, I have one block with a single text-attribute line copied hundreds of times. It is a furniture tag, so that the same block is used to refer to all of the furniture in the drawing and the value of the tag is changed according to what is needed. Example: Chair is tagged as 101, Table is tagged as 201, etc.

 

The problem is that the numbering format has changed and now chairs need to be tagged as 1101, Tables 2101, etc.

 

So far, as superficially as I have searched this site, I have found scripts that modify the Tag. But that is not what I need.

 

I can't qselect by block name because all blocks are the same. Neither can I select by Tag, because the tag is -and needs- to remain the same.

 

What I need is a way to filter and select by the value of the attribute tag.

 

Thanks in advance.

Link to comment
Share on other sites

Yeah easy done, your mixing 2 things in your question a block has tags which are a description and then you have an attribute which is a value. what you want is a lisp or vba that searches all common named blocks reads 1 attribute and adds the 1 to the value then updates the block etc

 

Give this a try its in VBA found it good for block attribute handling just paste it into the vba editor its cut out of another program but should work.

 

Public Sub issued_for_construction()
' This Updates the Issued for construction and sets rev 0

Dim SS As AcadSelectionSet
Dim mynewans as string
Dim Count As Integer
Dim FilterDXFCode(1) As Integer
Dim FilterDXFVal(1) As Variant
Dim attribs As Variant
Dim BLOCK_NAME As String
On Error Resume Next
FilterDXFCode(0) = 0
FilterDXFVal(0) = "INSERT"
FilterDXFCode(1) = 2
FilterDXFVal(1) = "Your blockname"
BLOCK_NAME = "Your blockname"
Set SS = ThisDrawing.SelectionSets.Add("issued")
SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal

For Cntr = 0 To SS.Count - 1
  attribs = SS.Item(Cntr).GetAttributes
myoldans = attribs(0)    ' attribs(0) is first attribute next attribute is attribs(1) and so on
' needs your code here
' also may need some form of test to check actual number returned so add correct 1000 2000 3000 etc  
' also again the attribute can be a number or a string      
mynewans = "1" & myoldans     ' this should work as a test   
       attribs(0).TextString = mynewans
       
       attribs(0).Update
       
Next Cntr
ThisDrawing.SelectionSets.Item("issued").Delete

MsgBox "Drawing blocks now changed to 1000 +"
End Sub
     

Link to comment
Share on other sites

Hello Bigal:

 

I should have have post this on the beginners forum.

 

Sorry, but I don't know how to do this. I have never worked with VBA before.

 

I've reached as far as the Visual Basic Editor, but I don't see where I can paste your script.

 

Thanks, again

Link to comment
Share on other sites

Your post does not say what version you are using, hopefully you have express tools available. (You can install in from the full version install disks, I don't think it is available with LT.)

 

Select all your blocks and click Express - Blocks - Export Attribute (or type attout on the command line) give it a file name and then open the text file in Excel. Change the attributes to the new value and save it as a text file. Go back to AutoCAD and click Express - Blocks - Import Attribute (or type attin at the command line). All your blocks now have updated values.

 

Hope this helps.

Glen

Link to comment
Share on other sites

Hello Glen:

 

My apologies for not responding sooner.

 

Your solution did work perfectly. Having the data all grouped in Excel allowed me to avoid wasting time looking for each tag (with a high probability of missing many), while allowing me to use Excel's find/replace tool.

 

Many thanks

Link to comment
Share on other sites

  • 5 years later...

I tried your way and its gr8 altough I have small issue :

I export the block attributs and values I need to excel and did excatly what you wrote but when I go back to cad and try importing ( I need to write the file path) not the whole values are showing , some are missing like it didnt took them from the file ( cause in the text file they showen)

any solution?

Thanks and sorry for bringin this up from then

Link to comment
Share on other sites

try this may be useful..............this script selects only particular attributes in block...........load this command is "TT" it will select and keeps in previous selection then apply P and make changes..........I got this from cadtutor only.

 
;__________________________________________________________
(defun C:TT ()

 
  (RT1) 
;  (setq e1 (nentsel "\nSelect attribute to filter: "))
  (setvar "cmdecho" 0)
  (setq eget (entget (car e1))) 
  (setq EX_STR (cdr (assoc 1 EGET)))   ;EXISTING TEXTSTRING
  (setq ex_tag (cdr (assoc 2 EGET)))   ;EXISTING tag

 (SETQ PT1 (CADR E1))
 (SETQ SS0 (SSGET PT1))
 (SETQ BLKNAME (CDR (ASSOC 2 (ENTGET (SSNAME SS0 0)))))

 (prompt (strcat "\n Block: " blkname "   Attribute tag: " ex_tag "   >: " ex_str))
 
 
;______________ SELECTING BLOCKS "BLKNAME" _________________

 (SETQ LST1 (LIST '(0 . "INSERT") (CONS 2 BLKNAME)) )
 (SETQ SS1 (SSGET "X" LST1))
; (SETQ SS1 (SSGET LST1))
; (IF (NULL SS1) (SETQ SS1 (SSGET "X" LST1)) )

 (setq SSM (SSADD))
 (setq len1 (sslength ss1) n1 0 ssx (ssadd))


 (WHILE (< n1 len1) ;WHILE 1
   (setq ename1 (ssname ss1 n1) eget1 (entget ename1) CTRL1 nil COUNTER 0 str1 "") 
   (SETQ en1 ename1)
   ;____ Find Tag Level
   (while (and (null ctrl1) (/= (CDR (ASSOC 0 (ENTGET (setq en1 (ENTNEXT en1))))) "SEQEND"))
          (setq tag1 (CDR (ASSOC 2 (ENTGET en1))))
          (if (= tag1 ex_tag) (setq str1 (CDR (ASSOC 1 (ENTGET en1))) ctrl1 T))
          (setq counter (1+ counter))
   ) ;end while2
   ;_____

   ;(if (= str1 ex_str) (princ str1))
   (if (= (STRCASE str1) (STRCASE ex_str)) (setq ssx (ssadd ename1 ssx)))
   (setq n1 (1+ n1))
 ) ; end WHILE1
             

 (setq lenx (sslength ssx))  
 (command "select" ssx "") 
 (PROMPT (strcat "\n Match found : [" (itoa lenx) "].   Selected objects are stored in Previous Selection."))
 (setvar "cmdecho" 1) 
 (princ)
)
;_____________________________________________________________

(prompt "\n Start command with  - by Raymond Rizkallah -  April 06. ")
(PRINC)

 

http://www.xtracad.com/forum/index.php?topic=8458.0

Edited by SLW210
Code Tags
Link to comment
Share on other sites

What about using the Select similar command (which will select all blocks that are the same). Then go into the properties panel and you should be able to change the attributes there, all in one shot.

Link to comment
Share on other sites

Not to mention OP was 5 years ago and he already said that he got a solution... ;D

 

/facepalm

 

lol Whos dragging up old threads! :P

 

Rob, qselect isn't the same as select similar is it? It sounded like he needed to select all the same block to me and change an attribute, which you could very well do as the technique I stated. I could be wrong, was just trying to provide an possible alternate solution

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