Jump to content

Change a specific TAG within a block of a drawing


noslenac

Recommended Posts

I've been trying to find existing lisp routines to do the following for a while now (off and on). While I have found some that will change values of Attributes or the text width for every piece of text in a drawing, that is not what I need done.

 

I need a lisp routine that will be manually modified with the current Attribute TAG and Block name based on client titleblock. It can't require manual selection (user input) as this will be used in a script to batch run the lisp routine.

 

To kind of summarize, I would like the ability to specify a block name and attribute tag name (in the specified block) and be able to set the text width factor in the drawing to account for longer filenames per client requests. This is only for the 1 attribute in all drawings.

 

Any help will be greatly appreciated.

 

Here is an example:

 

Titleblock has:

 

Attribute: File name

TAG: DRAWINGNO

Value: Linked to actual filename with a field

 

Current text width factor is .8 and it needs to be .7 to fit within the titleblock space.

Link to comment
Share on other sites

This may help

 

(setq ss1 (ssget)) ; pick a block
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
(if (= tagname (strcase (vla-get-tagstring att)))
(vla-put-scalefactor att X) ; x is new scale factor
)
)

Link to comment
Share on other sites

Thanks for the quick reply; however, that still requires me to manually select the attribute. I really need a way to pass a TAG to the function. Everything I've found and/or pieced together uses nentsel, but I have yet to find a way to automate selection of a attribute tag that is nested in a block without using nenetsel.

Link to comment
Share on other sites

Maybe the command: BATTMAN would work?

 

That won't allow me to utilize a script to automate text width changes to one attribute.

Link to comment
Share on other sites

This is a routine I recently found and modified slightly; however, I still cannot figure out an alternative to line #6 with NENTSEL to pass an Attribute tag into the function instead of require user input.

 

(defun widedit (/ aDoc x attent uwd option tag blk bn)
(vl-load-com)

(setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))

(if (and (setq x (car (nentsel "\nSelect attribute: ")))
	(eq "ATTRIB" (cdr (assoc 0 (entget x))))
	(setq attent (vlax-ename->vla-object x))
	
	;; Display Current Text Width Factor
	(princ (strcat "\nCurrent Width is <" (rtos (vla-get-scalefactor attent) 2)"> "))
	
	;; Set width to 0.7
	(setq uwd 0.7)) ;(getreal "\nEnter new width: ")))
	
	(progn
		(initget "Y N")
		(setq option "N")
			;(cond ((getkword "\nApply width to all Attribute of the same block? [Yes/no] <N>: "))( "N" )))
		(if (eq option "N")
			(vla-put-scalefactor attent uwd)
			(progn
			(setq tag (vla-get-tagstring attent))
			(setq Blk 
				(vla-ObjectIdToObject aDoc
					(vla-get-OwnerId attent)
				)
				
				Bn (vla-get-effectivename blk)
			)

			(vlax-for itm (vla-item (vla-get-blocks aDoc) bn)
				(if 
					(and (eq (vla-get-objectname itm) "AcDbAttributeDefinition")
						(eq (vla-get-tagstring itm) tag)
					)
				(vla-put-scalefactor itm uwd)
				)
			)

			(vlax-for layout (vla-get-layouts aDoc)
				(vlax-for i (vla-get-block layout)
					(if (and
							(eq (vla-get-objectname i) "AcDbBlockReference")
							(eq (Vla-get-hasAttributes i) :Vlax-true)
							(eq (vla-get-effectivename i) bn))
		
						(foreach itm (vlax-invoke i 'GetAttributes)
							(if (eq (vla-get-tagstring itm) tag)
								(vla-put-scalefactor itm uwd))))))
			)
		) ;; end if
	) ;; end progn
	(vl-some
	'(lambda (j) (if (null (eval (car j))) (princ (cadr j))
	))
	'((x "\n<<None Selected>>")
	(attent "\n<<Selected object not an Attribute>>")
	(uwd "\n<<No Width value>>"))
	)
)
(princ)
) ;; end defun

Link to comment
Share on other sites

Try the following:

(defun changeattributewidth ( tag wid / typ )
   (setq tag (strcase tag))
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if (= :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (cond
                   (   (= "AcDbBlockReference" (setq typ (vla-get-objectname obj)))
                       (foreach att (vlax-invoke obj 'getattributes)
                           (if (and (= tag (strcase (vla-get-tagstring att))) (vlax-write-enabled-p att))
                               (vla-put-scalefactor att wid)
                           )
                       )
                   )
                   (   (and (= "AcDbAttributeDefinition" typ)
                            (= tag (vla-get-tagstring obj))
                            (vlax-write-enabled-p obj)
                       )
                       (vla-put-scalefactor obj wid)
                   )
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Evaluate with tag name (case-insensitive) and new attribute width factor, e.g.:

(changeattributewidth "tag" 0.7)

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