Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

modify one existing lisp

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
mruPRQUJ
486 Views, 12 Replies

modify one existing lisp

Hi there,

One existing lisp can change title block attribute from "0A" to "0B". Could you please advise me how to change it from "0B" to "0C"? Please see the screenshot and the lisp files below, the lisp and DWG file were attached as well. Thank you very much in advance.

mruPRQUJ_1-1727305473595.png

the lisp file is below, 

(vl-load-com)
 
(defun c:ASet (/ format_date chgtxt adoc data_assoc_list ss attribute_tag attribute_string)
  
;********************************************************************************************
  
(defun format_date (/ mon date)
(setq mon '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC"))
(setq date (rtos (fix (getvar "cdate")) 2 0))
(strcat (substr date 1 4) (nth (1- (atoi (substr date 5 2))) mon) (substr date 7 2))
)
 
  ;********************************************************************************************
 
(defun chgtxt (string)
(cond
(
(= (car (reverse (vl-string->list string))) 65)
(vl-string-subst "B" "A" string)
)
(
(= (car (reverse (vl-string->list string))) 97)
(vl-string-subst "b" "a" string)
)
)
)
 
  ;********************************************************************************************
 
(setq data_assoc_list '(
; ("TITLE_LINE_1" . "DMR SUBSTATION")
("DATE" . "2024SEP")
; ("DESIGNED_BY" . "K. BAINS")
; ("INDEPENDENT_CHK" . "R. CLELLAND")
; ("DRAFTED_BY" . "M. RU")
; ("DRAFTING_CHECK" . "K. BAINS")
; ("INSPECTED_BY" . "")
; ("REVIEWED_BY" . "")
; ("ACCEPTED_BY" . "")
)
)
(if (ssget "_X" (list '(0 . "insert")))
(vlax-for block_reference (vla-get-activeSelectionSet (vla-get-activedocument (vlax-get-acad-object)))
(cond 
(
(wcmatch (strcase (vla-get-effectiveName block_reference)) "BCH-X-BORD-DXXX,BCH-X-BORD-BXXX,BCH-X-BORD-BXXXC,BCH-X-BORD-AXXX,BCH-X-BORD-REVI,BCH-X-ANNO-STMP-OBSO")
(foreach attribute (vlax-invoke block_reference 'getAttributes)
(setq attribute_tag (strcase (vla-get-tagString attribute)))
(setq attribute_string (vla-get-textString attribute))
(cond
(
(setq item (assoc attribute_tag data_assoc_list))
  (vla-put-textString attribute (format_date))
  (vla-put-textString attribute (cdr item))
)
(
(wcmatch attribute_tag "REV_`#,R_NO_D&E,R_NO_A&B,REV_NO")
(if
(and
     (or
        (wcmatch attribute_string "#[AaBb]")
(wcmatch attribute_string "##[AaBb]")
     )
     (setq attribute_string (chgtxt attribute_string))
)
(vla-put-textString attribute attribute_string)
)
)
)
)
)
(
(= "BCH-ST-DYN-DWG-ISSUE" (vla-get-effectivename block_reference))
(setpropertyvalue (vlax-vla-object->ename block_reference) "AcDbDynBlockPropertyVisibility" "IFR - ISSUE FOR REVIEW")
)
(
t
)
)
(vlax-release-object block_reference)
)
)
(princ)
)
Labels (1)
12 REPLIES 12
Message 2 of 13
paullimapa
in reply to: mruPRQUJ

Just simply modify this function from:

	(defun chgtxt (string)
		(cond
			(
			 	(= (car (reverse (vl-string->list string))) 65)
					(vl-string-subst "B" "A" string)
			)
			(
				(= (car (reverse (vl-string->list string))) 97)
					(vl-string-subst "b" "a" string)
			)
		)
	)

To this:

	(defun chgtxt (string)
		(cond
			(
			 	(= (car (reverse (vl-string->list string))) 65)
					(vl-string-subst "B" "A" string)
			)
			(
			 	(= (car (reverse (vl-string->list string))) 66)
					(vl-string-subst "C" "B" string)
			)
			(
				(= (car (reverse (vl-string->list string))) 97)
					(vl-string-subst "b" "a" string)
			)
		)
	)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 13
mruPRQUJ
in reply to: mruPRQUJ

If I need to change it from "C" to "D", is the change below correct? Many thanks. 🙂

 

(defun chgtxt (string)
(cond
(
(= (car (reverse (vl-string->list string))) 65)
(vl-string-subst "C" "A" string)
)
(
(= (car (reverse (vl-string->list string))) 66)
(vl-string-subst "D" "C" string)
)
(
(= (car (reverse (vl-string->list string))) 97)
(vl-string-subst "C" "a" string)
)
)
)
Message 4 of 13
paullimapa
in reply to: mruPRQUJ

66 needs to be 67:

(= (car (reverse (vl-string->list string))) 67)
(vl-string-subst "D" "C" string)
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 13
mruPRQUJ
in reply to: paullimapa

"B" to "C" works well, but "C" to "D" did not work. Please see the portion of the lisp below, 

(defun chgtxt (string)
(cond
(
(= (car (reverse (vl-string->list string))) 65)
(vl-string-subst "B" "A" string)
)
(
(= (car (reverse (vl-string->list string))) 67)
(vl-string-subst "D" "C" string)
)
(
(= (car (reverse (vl-string->list string))) 97)
(vl-string-subst "b" "a" string)
)
)
)
 
Is the below part needed to change as well?
(wcmatch attribute_tag "REV_`#,R_NO_D&E,R_NO_A&B,REV_NO")
(if
(and
     (or
        (wcmatch attribute_string "#[AaBb]")
(wcmatch attribute_string "##[AaBb]")
     )
     (setq attribute_string (chgtxt attribute_string))
)
(vla-put-textString attribute attribute_string)
 
Many thanks!
Message 6 of 13
paullimapa
in reply to: mruPRQUJ

One more place that needs to change from this:

 

     (or
        (wcmatch attribute_string "#[AaBb]")
        (wcmatch attribute_string "##[AaBb]")
     )

 

To this:

 

(or
 (wcmatch attribute_string "#[AaBbCc]")
 (wcmatch attribute_string "##[AaBbCc]")
)

 

But question:

1. Do you only want "0C" to change to "0D" or do you want any # in front as long as there's a C at the end to change to D ie: "0C" change to "0D" ; "1C" change to "1D" and "#C" change to "#D"?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 13
mruPRQUJ
in reply to: paullimapa

Hello,

 

I want any # in front as long as there's a C at the end to change to D ie: "0C" change to "0D" ; "1C" change to "1D" .

In some cases, "D" needs to be changed "E", many thanks. 🙂

Message 8 of 13
paullimapa
in reply to: mruPRQUJ

To make it easier for you to change on your own in the future, make the following changes.

Replace:

 

(defun chgtxt (string)
(cond
(
(= (car (reverse (vl-string->list string))) 65)
(vl-string-subst "B" "A" string)
)
(
(= (car (reverse (vl-string->list string))) 67)
(vl-string-subst "D" "C" string)
)
(
(= (car (reverse (vl-string->list string))) 97)
(vl-string-subst "b" "a" string)
)
)
)
 

 

with:

 

	(defun chgtxt (string / num)
		(cond
			(
			 	(= (chr (setq num (car (reverse (vl-string->list string))))) "C")
          (vl-string-subst (chr (1+ num)) (chr num) string)
			)
			(
			 	(= (chr (setq num (car (reverse (vl-string->list string))))) "c")
          (vl-string-subst (chr (1+ num)) (chr num) string)
			)
		)
	)

 

And replace this:

 

(or
 (wcmatch attribute_string "#[AaBbCc]")
 (wcmatch attribute_string "##[AaBbCc]")
)

 

With this:

 

											     (or
											       	 (wcmatch attribute_string "#[A-Z]")
												       (wcmatch attribute_string "##[A-Z]")
											       	 (wcmatch attribute_string "#[a-z]")
												       (wcmatch attribute_string "##[a-z]")
											     )

 

Now all you have to do when you want to change "C" or "c" to "D" or "d" is replace that character in that one location above

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 13
mruPRQUJ
in reply to: paullimapa

Hi there,

 

It looks like it did not work. I may make a mistake. Could you please look at it when you have chance? Thank you very much for your great support! 🙂

Message 10 of 13
paullimapa
in reply to: mruPRQUJ

Did you try the Aset.lsp I attached in my previous post which should let you change 0C to 0D


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 13
mruPRQUJ
in reply to: paullimapa

I made a mistake, it works perfect! Huge thanks!!! 🙂

Message 12 of 13
paullimapa
in reply to: mruPRQUJ

once again glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 13 of 13
mruPRQUJ
in reply to: paullimapa

Cheers! Thanks again! 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report