Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 11 of 16 (341 Views)

Re: Find and replace multileader text with LISP

10-09-2012 07:20 AM in reply to: bbarkman.jedson

Sounds simple enough, before anything elseI notice the program name is Revup, Does that mean if i change all 4 to 5, the existing 5 will remain as 5 or be bump-up to 6 and so on?

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 12 of 16 (334 Views)

Re: Find and replace multileader text with LISP

10-09-2012 07:58 AM in reply to: pbejse

Well, cant wait for you to reply. its getting pretty late here.

but if its just changing one value to another

 

(defun c:Revup ( / aDoc source SVal Mle MleD AT2Edit)
(defun _CheckMl (Tag ent / a)
      (vlax-for  itm  ent
            (if (and (eq (vla-get-Objectname itm)
                         "AcDbAttributeDefinition")
                     (eq (vla-get-TagString
                               itm) Tag))
                  (setq a (vla-get-ObjectID itm))))
      		a
      	)
       (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(if (and
		(setq ssmldrs (ssget "X" '((0 . "MULTILEADER"))))
		(setq oldval (strcase (getstring "\nEnter current value: ")))
		(setq newval (strcase (getstring "\nEnter new value: ")))
	  	)
	  (repeat (setq i (sslength ssmldrs))
		(if (and (= (vla-get-ContentType
	                  (setq Mle  (vlax-ename->vla-object (ssname ssmldrs (setq i (1- i))))))  1)
                          (setq MleD (vla-item (vla-get-blocks  Adoc)
                                                (vla-get-ContentBlockName Mle)))
                          (setq AT2Edit (_CheckMl "REVNUM" MleD))
			  (eq (vla-GetBlockAttributeValue  Mle AT2Edit) oldval)
			 ) 
			  (vla-SetBlockAttributeValue  Mle  AT2Edit newval)
                         )
                   )(vla-regen aDoc acActiveViewport )
             )
        (princ)
       )
(vl-load-com)
(princ)

 HTH

 

 

Active Member
bbarkman.jedson
Posts: 9
Registered: ‎05-04-2011
Message 13 of 16 (331 Views)

Re: Find and replace multileader text with LISP

10-09-2012 08:10 AM in reply to: pbejse
RevUp is just what I chose to call the command. When run, the first prompt is "Enter Current Value:" Second prompt is "Enter New Value:" Example: User enters "A" for current value and "0" for new value. Command will look at blocks and multileaders for the attribute named REVNUM. If it finds that attribute, it looks at its value. If the current value in the attribute is A, it is changed to 0. (That way other revisions the user does not wish to change will be left alone.) This works fine for blocks. For multileaders, it works if the value exists (in this case "A"), but if the value does not exist it gets changed anyway. I only want to change attribute values if there is a match between what's currently in the attribute and what the user enters for "current value." It's too bad that the usual functions can't reach inside a multileader containing a block without bending over backwards in the code. Does that help?
Active Member
bbarkman.jedson
Posts: 9
Registered: ‎05-04-2011
Message 14 of 16 (325 Views)

Re: Find and replace multileader text with LISP

10-09-2012 08:23 AM in reply to: pbejse
Thanks, gave it a quick run. Unfortunately, it changed all mleaders regardless.
*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 15 of 16 (320 Views)

Re: Find and replace multileader text with LISP

10-09-2012 08:31 AM in reply to: bbarkman.jedson

Works fine here. post a sample drawing with the mleader.

 

Make sure you run the code i posted [post # 12]

Better yet rename the defun to something else

 

Anyhoo. try this 

 

(defun c:RevOne ( / aDoc source SVal Mle MleD AT2Edit)
(defun _CheckMl (Tag ent / a)
      (vlax-for  itm  ent
            (if (and (eq (vla-get-Objectname itm)
                         "AcDbAttributeDefinition")
                     (eq (vla-get-TagString
                               itm) Tag))
                  (setq a (vla-get-ObjectID itm))))
      		a
      	)
       (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(if (and
		(setq ssmldrs (ssget "X" '((0 . "MULTILEADER"))))
		(setq oldval (strcase (getstring "\nEnter current value: ")))
		(setq newval (strcase (getstring "\nEnter new value: ")))
	  	)
	  (repeat (setq i (sslength ssmldrs))
		(if (and (= (vla-get-ContentType
	                  (setq Mle  (vlax-ename->vla-object (ssname ssmldrs (setq i (1- i))))))  1)
                          (setq MleD (vla-item (vla-get-blocks  Adoc)
                                                (vla-get-ContentBlockName Mle)))
                          (setq AT2Edit (_CheckMl "REVNUM" MleD))
			  (eq (strcase (vla-GetBlockAttributeValue  Mle AT2Edit)) oldval)
			 ) 
			  (vla-SetBlockAttributeValue  Mle  AT2Edit newval)
                         )
                   )(vla-regen aDoc acActiveViewport )
             )
        (princ)
       )
(vl-load-com)
(princ)

 

command:RevOne

BTW: are you using a 64bit OS?

Member
urix
Posts: 3
Registered: ‎04-15-2014
Message 16 of 16 (57 Views)

Re: Find and replace multileader text with LISP

04-15-2014 11:56 PM in reply to: bbarkman.jedson
Hi- Could anyone tell me how to FIND and REPLACE texts contents of Multileader.
I am trying to change key notes for “M-A” to “M-1”.
The usual “_find” command does not pick up these attributes.
Tried using Revup.lsp but says it is invalid as it needs to be inserted.
Please advice!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community