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

make changes to the current lisp

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
mruPRQUJ
637 Views, 18 Replies

make changes to the current lisp

Hi,

 

I wonder if the below changes can be made to the current lisp?
1. The current lisp remove letter from the attribute of the blocks, for example, "1A", it will be changed to "1".
I want to add "1" to current attribute value, for example, if the current value is "2", the new value will be "3". The following blocks and respectively tag will be changed.
block names are BCH-X-BORD-DXXX, BCH-X-BORD-BXXX, BCH-X-BORD-AXXX, BCH-X-BORD-REVI, BCH-X-BORD-REVI-TRIA, BCH-X-ANNO-STMP-OBSO
attribute tag is REV_`#, R_NO, R_NO_D&E, R_NO_A&B, REV_NO

2. add one layer to the DWG, layer name: $X-ANNO-REVC-ELEC, color: 220

 

Please see the lisp below, the lisp file and one DWG file with blocks were attached as well, thank you very much in advance. 🙂

 

(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 "" "A" string)
)
(
(= (car (reverse (vl-string->list string))) 97)
(vl-string-subst "" "a" string)
)
)
)
 
  ;********************************************************************************************
 
(setq data_assoc_list '(
("DATE" . "2023AUG25")
)
)
(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-AXXX,BCH-X-BORD-REVI-TRIA,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,R_NO_D&E,R_NO_A&B,REV_NO")
 
      (cond
       ((wcmatch attribute_string "#[AaAa]")
        (setq attribute_string (substr attribute_string 1 1)) ; keep only #
        (vla-put-textString attribute attribute_string)
       )
       ((wcmatch attribute_string "##[AaAa]")
        (setq attribute_string (substr attribute_string 1 2))  ; keep only ##
        (vla-put-textString attribute attribute_string)
       )       
      ) ; cond
)
)
)
)
(
(= "BCH-ST-DYN-DWG-ISSUE" (vla-get-effectivename block_reference))
(setpropertyvalue (vlax-vla-object->ename block_reference) "AcDbDynBlockPropertyVisibility" "IRD - ISSUE RECORD DRAWING")
)
(
t
)
)
(vlax-release-object block_reference)
)
)
(vl-cmdf "_.Layer" "_F" "$X-ANNO-REVC" "") ; freeze layer "$X-ANNO-REVC"
 (princ)
)
Labels (1)
18 REPLIES 18
Message 2 of 19
paullimapa
in reply to: mruPRQUJ

so since current attrib is 0A you want it changed to 1A or just 1

paullimapa_0-1692819708101.png

 


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

Sorry I did not say it clearly. The current one will remove the letter. For example, "1A", "2A" will be changed to "1", "2". I wish to increase value by "1". For instance, "1", "5" will be changed to "2", "6", thanks a lot!

Message 4 of 19
paullimapa
in reply to: mruPRQUJ

so since your current example shows "0A", then you want it to be "1" right?


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

maybe there are mistakes in the lisp. I just run the lisp, "1A", "2A" attributes in the DWG were changed to "1", "2"

Maybe the below part did the job.

mruPRQUJ_0-1692821034928.png

 

Message 6 of 19
paullimapa
in reply to: mruPRQUJ

Then you must have posted the wrong sample dwg.

That one contains a Rev_# of 0A like I posted earlier:

paullimapa_3-1692821690808.png

When the current lisp you posted runs it changes Rev_# to 0:

paullimapa_0-1692821588780.png

For me either way works because the lisp can be revised so that:

If it sees a "0A", it'll be changed to "1"

If it sees a "1A", it'll be changed to "2"

I assume this is what you want, right?

 


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

yes, you are right. The dwg have some blocks, but it did not match the lisp. Sorry about it. What I wish: 

1. the current value plus "1". "1" will be changed to "2", "5" will be changed to "6"

2. add one layer to the DWG, layer name: $X-ANNO-REVC-ELEC, color: 220

 

Thanks.

Message 8 of 19
paullimapa
in reply to: mruPRQUJ

Ok, then I have another question.

What if REV_# only shows a single digit like "1" and no letters following?

Do you still want the "1" to become "2" or do you think there would NOT be a situation where you only have a single digit value for Rev_#?


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

all the attributes without letter, "1" becomes "2", "5" becomes "6", the value is added "1". sorry about it, thanks

Message 10 of 19
paullimapa
in reply to: mruPRQUJ

Ok, give this revised ASet.lsp version a try.

Keep in my that every time it is run the Rev_# value will increment by 1

So don't run it again on the same dwg if you don't want it to change again.


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

I am little busy; I will test it later. Could you please advise me if the new layer was added as well? many thanks.

Message 12 of 19
paullimapa
in reply to: mruPRQUJ

of course that's an easy add towards the end of the code like before.

Even you can do this:

 (vl-cmdf "_.Layer" "_M" "$X-ANNO-REVC-ELEC" "_Co" 220 "" "") ; add layer name: $X-ANNO-REVC-ELEC, color: 220 

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

 I am a little busy, I will test it later, thanks a lot, 🙂

Message 14 of 19
mruPRQUJ
in reply to: paullimapa

Hi,

 

Great job! I wonder if the layer "$X-ANNO-REVC" can be freezed, I can't thank you enough. 🙂

Message 15 of 19
paullimapa
in reply to: mruPRQUJ

Sure replace this line of code:

 

(vl-cmdf "_.Layer" "_M" "$X-ANNO-REVC-ELEC" "_Co" 220 "" "") ; add layer name: $X-ANNO-REVC-ELEC, color: 220 

 

With these 2 lines:

 

  (vl-cmdf "_.Layer" "_M" "$X-ANNO-REVC-ELEC" "_Co" 220 "" "") ; add layer name: $X-ANNO-REVC-ELEC, color: 220 
  (vl-cmdf "_.Layer" "_F" "$X-ANNO-REVC" "") ; freeze layer name: $$X-ANNO-REVC

 

 


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

Perfect job, it works very well, thanks a million! 🙂

Message 17 of 19
paullimapa
in reply to: mruPRQUJ

make it look like this:

(vl-cmdf "_.Layer" "_M" "$X-ANNO-REVC-ELEC" "_Co" 220 "" "") ; add layer name: $X-ANNO-REVC-ELEC, color: 220 
(vl-cmdf "_.Layer" "_F" "$X-ANNO-REVC" "") ; freeze layer name: $$X-ANNO-REVC

 


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

Thank you very much from the bottom of my heart! 🙂

Message 19 of 19
paullimapa
in reply to: mruPRQUJ

Glad to help … cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos

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

Post to forums  

Autodesk Customer Advisory Groups


Autodesk Design & Make Report