Increment single block attribute value in multiple drawings. Value is a letter.

Increment single block attribute value in multiple drawings. Value is a letter.

fatherof3
Advocate Advocate
1,136 Views
7 Replies
Message 1 of 8

Increment single block attribute value in multiple drawings. Value is a letter.

fatherof3
Advocate
Advocate

Hi

We have hundreds of drawings with same title block inserted as an attributed block. The title block contains multiple attributes, one of which defines the revision. The revision value is a letter. I'm looking, (all over, with no luck so far), for a lisp routine that will increment this value to the next letter. Example: Revision value is "C", needs to increment to "D". The existing revision value can be any single letter from "A" to "Z", (although nothing will approach "Z"). Existing value and new value will always be a single letter. 

I've found "lee-mac.com" 's BATTE routine, it does everything I need except it lacks the ability to automatically increment the text value.

I want to run this as a batch file to process these hundreds of drawings without any user input.

Does anyone know where I could find a program to do this?

Thanks for your help

 

0 Likes
1,137 Views
7 Replies
Replies (7)
Message 2 of 8

dbhunia
Advisor
Advisor

Hi,

 

Try this........

 

First put all the drawings in a single folder & run the code it will ask to select the Folder Containing the drawings you just select the folder & move forward......Code will work itself on all the drawings in side that folder.....

 

But before running the Lisp make sure about two things-

       1. There is only one Drawing is open (other than any drawing which one you want to edit), otherwise SDI Variable can not be reset.

       2. Wait for complete execution of the command, otherwise SDI Variable will not restored back.

 

(defun c:CAV ( / sh folder folderobject result)
   (vl-load-com)
   (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
   (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
   (vlax-release-object sh)
   (setq SDI_Val (getvar "SDI"))
   (setq LISPI_Val (getvar "LISPINIT"))
   (vl-cmdf "SDI" 1)
   (vl-cmdf "LISPINIT" 0)
   (if folder
      (progn
         (setq folderobject (vlax-get-property folder 'Self))
         (setq result (vlax-get-property FolderObject 'Path))
         (vlax-release-object folder)
         (vlax-release-object FolderObject)

	(setq Files_Folder (vl-directory-files result "*.dwg"))
	(setq blk_name (getstring "\nEnter Block Name: "))
	(setq tag_str (getstring "\nEnter ATT Tag Name: "))
	(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
	(setq n 0)

	(while (< n (length Files_Folder))

	(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
	(vl-load-com)
  	(setq Att_Value "")
  	(setq	adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq ss (ssget "X" (list '(0 . "INSERT")(cons 2 blk_name))))
	(cond ((/= ss nil)
		(progn
			(repeat (setq NOS (sslength ss))

  				  (vlax-for blk (vla-get-blocks adoc)
				    (if (= (vla-get-Name blk) blk_name)
					(progn
						(setq Data (ssname SS (setq NOS (- NOS 1))))
						(setq obj (vlax-ename->vla-object Data))
							(foreach att (vlax-invoke Obj 'GetAttributes)
							  (if (= (vla-get-Tagstring att) tag_str)
							      (progn
								(setq Att_Value (chr (+ (ascii (vla-get-Textstring att)) 1)))
								(vla-put-textstring att Att_Value)
							      )
							  );if
							);foreach
					   ;);repeat
					);progn
				     );if
				   );vlax-for
			)
		)
      	       )
	)
	(vl-cmdf "purge" "B" blk_name "N")
	(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
	(setq n (+ 1 n))
        )
     )
   )
   (vl-cmdf "SDI" SDI_Val)
   (vl-cmdf "LISPINIT" LISPI_Val)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 8

fatherof3
Advocate
Advocate

Hello dbhunia,

The name of the block contains several blank spaces, so whenever I try to enter the name of the block, the program sees that input as a "return", and skips to the next step whenever I hit the space bar.

So I can't get past that part of the lsp routine.

 

Thanks for your response, though! If I knew how to correct this myself, I would give it a shot.

 

Before you spend anytime changing your program, we are considering replacing the revision from incremented letters to the number "1", for which I can use the "lee-mac" routine I mentioned above.

 

Thanks again for your help.

0 Likes
Message 4 of 8

dbhunia
Advisor
Advisor

Try this......

 

(defun c:CAV ( / sh folder folderobject result)
   (vl-load-com)
   (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
   (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
   (vlax-release-object sh)
   (setq SDI_Val (getvar "SDI"))
   (setq LISPI_Val (getvar "LISPINIT"))
   (vl-cmdf "SDI" 1)
   (vl-cmdf "LISPINIT" 0)
   (if folder
      (progn
         (setq folderobject (vlax-get-property folder 'Self))
         (setq result (vlax-get-property FolderObject 'Path))
         (vlax-release-object folder)
         (vlax-release-object FolderObject)

	(setq Files_Folder (vl-directory-files result "*.dwg"))
	;(setq blk_name (getstring "\nEnter Block Name: "))
	(setq blk_name "BB BB BB");;Put Block Name as required in place of "BB BB BB" like "XX XX_XX" etc...If you do not want manual input
	;(setq tag_str (getstring "\nEnter ATT Tag Name: "))
	(setq tag_str "BB");;Put ATT TAG Name as required in place of "BB" like "YYYY" etc...If you do not want manual input
	(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
	(setq n 0)

	(while (< n (length Files_Folder))

	(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
	(vl-load-com)
  	(setq Att_Value "")
  	(setq	adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq ss (ssget "X" (list '(0 . "INSERT")(cons 2 blk_name))))
	(cond ((/= ss nil)
		(progn
			(repeat (setq NOS (sslength ss))

  				  (vlax-for blk (vla-get-blocks adoc)
				    (if (= (vla-get-Name blk) blk_name)
					(progn
						(setq Data (ssname SS (setq NOS (- NOS 1))))
						(setq obj (vlax-ename->vla-object Data))
							(foreach att (vlax-invoke Obj 'GetAttributes)
							  (if (= (vla-get-Tagstring att) tag_str)
							      (progn
								(setq Att_Value (chr (+ (ascii (vla-get-Textstring att)) 1)))
								(vla-put-textstring att Att_Value)
							      )
							  );if
							);foreach
					   ;);repeat
					);progn
				     );if
				   );vlax-for
			)
		)
      	       )
	)
	(vl-cmdf "purge" "B" blk_name "N")
	(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
	(setq n (+ 1 n))
        )
     )
   )
   (vl-cmdf "SDI" SDI_Val)
   (vl-cmdf "LISPINIT" LISPI_Val)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 8

dlanorh
Advisor
Advisor

@fatherof3 wrote:

Hello dbhunia,

The name of the block contains several blank spaces, so whenever I try to enter the name of the block, the program sees that input as a "return", and skips to the next step whenever I hit the space bar.

So I can't get past that part of the lsp routine.

 

Thanks for your response, though! If I knew how to correct this myself, I would give it a shot.

 

Before you spend anytime changing your program, we are considering replacing the revision from incremented letters to the number "1", for which I can use the "lee-mac" routine I mentioned above.

 

Thanks again for your help.


Try changing the red lines of @dbhunia original code as indicated and try again. Basically insert a T between the getstring and the prompt.

 

(defun c:CAV ( / sh folder folderobject result)
   (vl-load-com)
   (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
   (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
   (vlax-release-object sh)
   (setq SDI_Val (getvar "SDI"))
   (setq LISPI_Val (getvar "LISPINIT"))
   (vl-cmdf "SDI" 1)
   (vl-cmdf "LISPINIT" 0)
   (if folder
      (progn
         (setq folderobject (vlax-get-property folder 'Self))
         (setq result (vlax-get-property FolderObject 'Path))
         (vlax-release-object folder)
         (vlax-release-object FolderObject)

	(setq Files_Folder (vl-directory-files result "*.dwg"))
	(setq blk_name (getstring T "\nEnter Block Name: "))
	(setq tag_str (getstring T "\nEnter ATT Tag Name: "))
	(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
	(setq n 0)

	(while (< n (length Files_Folder))

	(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
	(vl-load-com)
  	(setq Att_Value "")
  	(setq	adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq ss (ssget "X" (list '(0 . "INSERT")(cons 2 blk_name))))
	(cond ((/= ss nil)
		(progn
			(repeat (setq NOS (sslength ss))

  				  (vlax-for blk (vla-get-blocks adoc)
				    (if (= (vla-get-Name blk) blk_name)
					(progn
						(setq Data (ssname SS (setq NOS (- NOS 1))))
						(setq obj (vlax-ename->vla-object Data))
							(foreach att (vlax-invoke Obj 'GetAttributes)
							  (if (= (vla-get-Tagstring att) tag_str)
							      (progn
								(setq Att_Value (chr (+ (ascii (vla-get-Textstring att)) 1)))
								(vla-put-textstring att Att_Value)
							      )
							  );if
							);foreach
					   ;);repeat
					);progn
				     );if
				   );vlax-for
			)
		)
      	       )
	)
	(vl-cmdf "purge" "B" blk_name "N")
	(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
	(setq n (+ 1 n))
        )
     )
   )
   (vl-cmdf "SDI" SDI_Val)
   (vl-cmdf "LISPINIT" LISPI_Val)
)

 

I am not one of the robots you're looking for

0 Likes
Message 6 of 8

dbhunia
Advisor
Advisor

Hi

 

First thing I thought @fatherof3 wants to hard coded the Lisp Code so I give that resolution .......... to hard code the "Block Name" and "Att Tag Name".......

 

If that is not the case then the code will be like the attached one.......

 

Because "Block Name" may contain "Spaces" in between but "Att Tag Name" Never contain "Spaces" .......

So for getting the input of "Att Tag Name" we never allow to input "Spaces" within "Att Tag Name".....

 

(defun c:CAV ( / sh folder folderobject result)
   (vl-load-com)
   (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
   (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
   (vlax-release-object sh)
   (setq SDI_Val (getvar "SDI"))
   (setq LISPI_Val (getvar "LISPINIT"))
   (vl-cmdf "SDI" 1)
   (vl-cmdf "LISPINIT" 0)
   (if folder
      (progn
         (setq folderobject (vlax-get-property folder 'Self))
         (setq result (vlax-get-property FolderObject 'Path))
         (vlax-release-object folder)
         (vlax-release-object FolderObject)

	(setq Files_Folder (vl-directory-files result "*.dwg"))
	(setq blk_name (getstring T "\nEnter Block Name: "))
	(setq tag_str (getstring "\nEnter ATT Tag Name: "))
	(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
	(setq n 0)

	(while (< n (length Files_Folder))

	(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
	(vl-load-com)
  	(setq Att_Value "")
  	(setq	adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq ss (ssget "X" (list '(0 . "INSERT")(cons 2 blk_name))))
	(cond ((/= ss nil)
		(progn
			(repeat (setq NOS (sslength ss))

  				  (vlax-for blk (vla-get-blocks adoc)
				    (if (= (vla-get-Name blk) blk_name)
					(progn
						(setq Data (ssname SS (setq NOS (- NOS 1))))
						(setq obj (vlax-ename->vla-object Data))
							(foreach att (vlax-invoke Obj 'GetAttributes)
							  (if (= (vla-get-Tagstring att) tag_str)
							      (progn
								(setq Att_Value (chr (+ (ascii (vla-get-Textstring att)) 1)))
								(vla-put-textstring att Att_Value)
							      )
							  );if
							);foreach
					   ;);repeat
					);progn
				     );if
				   );vlax-for
			)
		)
      	       )
	)
	(vl-cmdf "purge" "B" blk_name "N")
	(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
	(setq n (+ 1 n))
        )
     )
   )
   (vl-cmdf "SDI" SDI_Val)
   (vl-cmdf "LISPINIT" LISPI_Val)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 7 of 8

fatherof3
Advocate
Advocate

Hi

 

First, thanks for the help.

Having the "Block Name" and the "Att Tag Name" hard-coded would work better for us, since these are fairly consistent. There are a few outliers, which we can deal with individually.

As I mentioned earlier, we ended up changing the revision from any letter to the number "1", which I was able to do using a routine from "lee-mac.com" called "BATTE".

The second problem we run into is, after running the script, finding which drawings changed correctly, and which ones still need work. Boring task when there are a couple thousand drawings involved.

 

In addition, I was not able to get your lisp code to process more than a single file at a time, it would quit with an error code.

 

I'm on to another related task with these files at the moment, when I get a chance, I'll try and let you know what exactly that error was.

 

0 Likes
Message 8 of 8

maratovich
Advisor
Advisor

Attach an example of your file with the title block.

What does the folder structure for files look like?

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes