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

Rename Layout according to attributes in Titleblock

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
johan.detx
775 Views, 5 Replies

Rename Layout according to attributes in Titleblock

Hello,

 

I use this command which works very well.

 

Except when there is no data in AT_DATA_DESC6_S_F


I would like him to use only the AT_DATA_DESC4_S_F if there is nothing in the DESC6

 

I would also like to automatically replace the "/" contained in my block by "-" when renaming my layout because you can't put "/" in the layout name but my "/" must remain in my block.

 

(defun c:ren1 ()
    (vl-load-com)
    (foreach lay (layoutlist)
        (setq obj (vlax-EName->vla-Object
                      (ssname (ssget "_x" (list (cons 0 "INSERT") (cons 2 "TBM_DATA09_S_F") (cons 410 lay))) 0)
                  )
        )
        (if
            (setq lstatts (vlax-SafeArray->list (variant-Value (vla-GetAttributes obj))))
               (progn;<<<<
                   (foreach atts lstatts
                       (cond
                           ((= (vla-Get-TagString atts) "AT_DATA_DESC4_S_F") (setq a (vla-Get-TextString atts)))
                           ((= (vla-Get-TagString atts) "AT_DATA_DESC6_S_F") (setq b (vla-Get-TextString atts)))
                       )
                   )
                   (if
                       (not (member (strcat a "_" b) (layoutlist)))
                          (command "_Layout" "r" lay (strcat a "_" b))
                          (alert "Done !!!")
                   )
               );<<<<
        )
    )
)

Thank you all

 

Joe

 

Tags (1)
5 REPLIES 5
Message 2 of 6
Moshe-A
in reply to: johan.detx

Joe,

 

here is a (string-subst) function to substitute any old-str with new-str

usage:

(string-subst "/"  "-"  "abcd/efg/hijk/lmnop/qrst/uvw/xyz")

returns:  "abcd-efg-hijk/lmnop-qrst-uvw-xyz"

it will returns nil if no change is made

 

call this function before layout rename.

 

enjoy

moshe

 

; substitute old-str with new-str, return the changed string or nil if no change made
(defun string-subst (old-str new-str string / flag)
 (if (vl-string-search old-str string)
  (progn
   (setq flag t)
   ; recursion call
   (setq string (string-subst old-str new-str (vl-string-subst new-str old-str string)))
  )
 ); if

 (if flag
  string
 )
)
Message 3 of 6
johan.detx
in reply to: Moshe-A

Hello,

I solved all my problems with this

thank you for your help

 

For those who would like to use the code

the XXXX correspond to the block to choose
the YYYY correspond to the attributes of the block to choose

 

(defun c:TEST ()
    (vl-load-com)
    (foreach lay (layoutlist)
                        (setq obj (vlax-EName->vla-Object
                                      (ssname (ssget "_x" (list (cons 0 "INSERT") (cons 2 "XXXXXXX") (cons 410 lay))) 0)
                                  )
                        )
(if obj
        (if
                  
            (setq lstatts (vlax-SafeArray->list (variant-Value (vla-GetAttributes obj))))
               (progn;<<<<
                   (foreach atts lstatts
                       (cond
                           ((= (vla-Get-TagString atts) "YYYYYYYY") (setq a (vl-string-subst "-" "/" (vla-Get-TextString atts))))
                           ((= (vla-Get-TagString atts) "YYYYYYYY") (setq b (vla-Get-TextString atts)))
                       )
                   )
                   (if
                       (not (member (strcat a "_" b) (layoutlist)))
                          (command "_Layout" "r" lay (strcat a (if (not (equal b "")) (strcat "  " b)"")))
                   )
               );<<<<
        )
);end if obj
    )

)

 

Message 4 of 6
Moshe-A
in reply to: johan.detx

Joe

 

the fix you gave is good only for the first occurrence of "/" whereas the function i gave you will ensure all occurrences.

 

(setq a (vl-string-subst "-" "/" (vla-Get-TextString atts)))

 

 

Message 5 of 6
johan.detx
in reply to: Moshe-A

Moshe,

 

There can only be one "/" in this case it is forbidden for me to use several of them per layout title which does not justify managing several of them.

 

However, thank you, I still copied your code to keep it just in case.

 

Again, thank you.

Message 6 of 6
ВeekeeCZ
in reply to: Moshe-A


@Moshe-A wrote:

Joe

 

the fix you gave is good only for the first occurrence of "/" whereas the function i gave you will ensure all occurrences.

 

(setq a (vl-string-subst "-" "/" (vla-Get-TextString atts)))

 

You can also use the vl-string-translate function to cover all instances.

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

Post to forums  

Autodesk Design & Make Report

”Boost