Author Topic: change jusifications of attribute in block  (Read 8276 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
change jusifications of attribute in block
« on: August 06, 2014, 09:22:35 AM »
hello guys .

I write this lisp to change justifications of attribute string "aa" to Top Center , but the string goes to zero coordinates , anyone can help please ?

Code: [Select]
(defun c:test (/ ss vla-obj ss-name atts-obj n)
  (vl-load-com)
  (setq n 0)
  (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  (while (setq ss-name (ssname ss n))
    (setq vla-obj (vlax-ename->vla-object ss-name))
    (setq atts-obj (vlax-invoke vla-obj 'getattributes))
    (foreach att atts-obj
      (if (eq (vla-get-textstring att) "1")
        (vla-put-alignment att acAlignmentTopCenter)
      )
    )
    (setq n (1+ n))
  )
  (princ)
)

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #1 on: August 06, 2014, 02:57:33 PM »
maybe I need to use another function to reset the attribute back ?

I have no idea .  :embarrassed:

Anyone can help please  ?

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #2 on: August 06, 2014, 03:07:45 PM »
After changing Alignment porperty you have to change InsertionPoint to correct value.
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #3 on: August 06, 2014, 03:35:04 PM »
After changing Alignment porperty you have to change InsertionPoint to correct value.
Thank you for your reply .

I added the insertion point but it still the same  :embarrassed:

Code: [Select]
(defun c:test (/ ss vla-obj ss-name atts-obj n p)
  (vl-load-com)
  (setq n 0)
  (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  (while (setq ss-name (ssname ss n))
    (setq vla-obj (vlax-ename->vla-object ss-name))
    (setq atts-obj (vlax-invoke vla-obj 'getattributes))
    (foreach att atts-obj
      (if (eq (vla-get-textstring att) "1")
        (progn
          (setq p (vla-get-insertionpoint att))
          (vla-put-alignment att acAlignmentTopCenter)
          (vla-put-insertionpoint att p))
      )
    )
    (setq n (1+ n))
  )
  (princ)
)

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #4 on: August 06, 2014, 03:57:10 PM »
Maybe this will work (i tested it only at one-string attributes):
Code: [Select]
(vl-load-com)

(defun test1 (/ _kpblc-conv-vla-to-list selset att_lst pt)

  (defun _kpblc-conv-vla-to-list (value / res)
    (cond
      ((listp value)
       (mapcar (function _kpblc-conv-vla-to-list) value)
       )
      ((= (type value) 'variant)
       (_kpblc-conv-vla-to-list (vlax-variant-value value))
       )
      ((= (type value) 'safearray)
       (if (>= (vlax-safearray-get-u-bound value 1) 0)
         (_kpblc-conv-vla-to-list (vlax-safearray->list value))
         ) ;_ end of if
       )
      ((and (= (type value) 'vla-object)
            (vlax-property-available-p value 'count)
            ) ;_ end of and
       (vlax-for sub value
         (setq res (cons sub res))
         ) ;_ end of vlax-for
       )
      (t value)
      ) ;_ end of cond
    ) ;_ end of defun

  (if (= (type (setq selset (vl-catch-all-apply
                              (function
                                (lambda () (ssget '((0 . "INSERT") (66 . 1))))
                                ) ;_ end of function
                              ) ;_ end of VL-CATCH-ALL-APPLY
                     ) ;_ end of setq
               ) ;_ end of type
         'pickset
         ) ;_ end of =
    (progn
      (foreach obj (mapcar (function vlax-ename->vla-object)
                           ((lambda (/ tab item)
                              (repeat (setq tab  nil
                                            item (sslength selset)
                                            ) ;_ end setq
                                (setq tab (cons (ssname selset (setq item (1- item))) tab))
                                ) ;_ end of repeat
                              ) ;_ end of LAMBDA
                            )
                           ) ;_ end of mapcar
        (foreach att (vl-remove-if-not
                       (function
                         (lambda (x)
                           (= (vla-get-textstring x) "1")
                           ) ;_ end of lambda
                         ) ;_ end of function
                       (apply (function append)
                              (mapcar (function _kpblc-conv-vla-to-list)
                                      (list
                                        (vla-getattributes obj)
                                        (vla-getconstantattributes obj)
                                        ) ;_ end of list
                                      ) ;_ end of mapcar
                              ) ;_ end of apply
                       ) ;_ end of vl-remove-if-not
          (setq pt (vl-remove nil
                              (mapcar
                                (function
                                  (lambda (x)
                                    (if (vlax-property-available-p att x)
                                      (cons x (vlax-get-property att x))
                                      ) ;_ end of if
                                    ) ;_ end of lambda
                                  ) ;_ end of function
                                '("insertionpoint" "textalignmentpoint")
                                ) ;_ end of mapcar
                              ) ;_ end of vl-remove
                ) ;_ end of setq
          (vla-put-alignment att acalignmenttopcenter)
          (foreach item pt
            (vlax-put-property att (car item) (cdr item))
            ) ;_ end of foreach
          ) ;_ end of foreach
        ) ;_ end of foreach
      ) ;_ end of progn
    ) ;_ end of if
  ) ;_ end of defun
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #5 on: August 06, 2014, 04:07:22 PM »
I am sorry , it does not work .

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #6 on: August 06, 2014, 04:10:09 PM »
Could you provide your block? I tested code only at standard blocks...
Sorry for my English.

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: change jusifications of attribute in block
« Reply #7 on: August 06, 2014, 06:26:14 PM »
After changing Alignment porperty you have to change InsertionPoint TextAlignmentPoint to correct value.

Fixed that for you  :-)

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #8 on: August 07, 2014, 01:21:54 AM »
Thank you. :)
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #9 on: August 07, 2014, 01:43:19 AM »
Hi .
Thank you for your guys .

I modified the codes a little and it still does not work .  :-(

Code: [Select]
(foreach att atts-obj
      (if (eq (vla-get-textstring att) "1")
        (progn
          (setq pnt (vla-get-TextAlignmentPoint att))
          (vla-put-alignment att acAlignmentTopCenter)
          (vla-put-TextAlignmentPoint att pnt)
        )
      )
    )

Attached file below .

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #10 on: August 07, 2014, 02:30:52 PM »
Please , anyone can give a solution or modify my codes ?

Thank you all .

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: change jusifications of attribute in block
« Reply #11 on: August 07, 2014, 03:51:24 PM »
The InsertionPoint property controls the text position when the Alignment property is set to Left, the TextAlignmentPoint controls the text position for all other values of the Alignment property.

Hence, the code should be:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / i p s )
  2.     (if (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  3.         (repeat (setq i (sslength s))
  4.             (foreach a (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes)
  5.                 (if (= "1" (vla-get-textstring a))
  6.                     (progn
  7.                         (if (= acalignmentleft (vla-get-alignment a))
  8.                             (setq p (vla-get-insertionpoint a))
  9.                             (setq p (vla-get-textalignmentpoint a))
  10.                         )
  11.                         (vla-put-alignment a acalignmenttopcenter)
  12.                         (vla-put-textalignmentpoint a p)
  13.                     )
  14.                 )
  15.             )
  16.         )
  17.     )
  18.     (princ)
  19. )

Note that the attribute will still change position, as the alignment of the attribute changes relative to the InsertionPoint / TextAlignmentPoint - the coordinates of this point remain unchanged.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #12 on: August 07, 2014, 04:54:44 PM »
Thank you Lee for your help and for the explanations .

the routine works great , many thanks .  :-)

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: change jusifications of attribute in block
« Reply #13 on: August 07, 2014, 06:48:47 PM »
You're welcome Coder  :-)

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #14 on: August 20, 2014, 07:04:36 AM »
Hello lee
I have error message after I modified your codes to make it left alignment  :embarrassed:

Quote
; error: Automation Error. Not applicable
Can you please help ?

Code: [Select]
(defun c:test (/ i p s)
  (if (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
    (repeat (setq i (sslength s))
      (foreach a (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes)
        (if (= "1" (vla-get-textstring a))
          (progn (if (= acalignmentleft (vla-get-alignment a))
                   (setq p (vla-get-insertionpoint a))
                   (setq p (vla-get-textalignmentpoint a))
                 )
                 (vla-put-alignment a acalignmentleft) ;;; I want to make left , it makes but the position of the attribute is not changed correctly .
                 (vla-put-textalignmentpoint a p) ;;; I think this code make the error message
          )
        )
      )
    )
  )
  (princ)
)
(vl-load-com)
(princ)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #15 on: August 20, 2014, 07:41:05 AM »
In vanilla - maybe:
Code - Auto/Visual Lisp: [Select]
  1. ;;;Change ATTRIBute Justification To Top Center
  2. (defun c:att-tc (/ ss i en an ad)
  3.   (and (setq ss (ssget '((0 . "INSERT")(66 . 1))))
  4.        (setq i 0)
  5.        (while (setq en (ssname ss i))
  6.               (setq an (entnext en)
  7.                     ad (entget an))
  8.               (while (= "ATTRIB" (cdr (assoc 0 ad)))
  9.                      (setq ad (subst '(72 . 1) (assoc 72 ad) ad)
  10.                            ad (subst '(74 . 3) (assoc 74 ad) ad)
  11.                            ad (subst (cons 11 (cdr (assoc 10 ad))) (assoc 11 ad) ad))
  12.                      (entmod ad)
  13.                      (setq an (entnext an)
  14.                            ad (entget an)))
  15.               (entupd en)
  16.               (setq i (1+ i))))
  17.   (prin1))

-David
« Last Edit: August 22, 2014, 06:57:18 AM by David Bethel »
R12 Dos - A2K

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #16 on: August 20, 2014, 09:23:59 AM »
If an attribute is multistring, it has no property TextAlignmentPoint (only InsertionPoint and AttachmentPoint properties).
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #17 on: August 20, 2014, 11:43:20 AM »
In vanilla - maybe:
Code: [Select]
;;;Change ATTRIBute Justification To Top Center
(defun c:att-tc (ss i en an ad)
  (and (setq ss (ssget '((0 . "INSERT")(66 . 1))))
       (setq i 0)
       (while (setq en (ssname ss i))
              (setq an (entnext en)
                    ad (entget an))
              (while (= "ATTRIB" (cdr (assoc 0 ad)))
                     (setq ad (subst '(72 . 1) (assoc 72 ad) ad)
                           ad (subst '(74 . 3) (assoc 74 ad) ad))
                     (entmod ad)
                     (setq an (entnext an)
                           ad (entget an)))
              (entupd en)
              (setq i (1+ i))))
  (prin1))

-David

I am sorry David , your codes did not work for me . and did not make any change to blocks  :embarrassed:
I added the back slash at the top of the routine .

Can you modify it again please ?

many thanks

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #18 on: August 20, 2014, 11:49:31 AM »
If an attribute is multistring, it has no property TextAlignmentPoint (only InsertionPoint and AttachmentPoint properties).

Thank you for your reply  :-)

If I removed the function TextAlignmentPoint  , it change to left but the position of the attribute will be irregular  :-o

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #19 on: August 20, 2014, 12:58:37 PM »
Try to use this:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun test1 (tag / _kpblc-conv-vla-to-list selset att_lst pt)
  3.  
  4.   (defun _kpblc-conv-vla-to-list (value / res)
  5.     (cond
  6.       ((listp value)
  7.        (mapcar (function _kpblc-conv-vla-to-list) value)
  8.        )
  9.       ((= (type value) 'variant)
  10.        (_kpblc-conv-vla-to-list (vlax-variant-value value))
  11.        )
  12.       ((= (type value) 'safearray)
  13.        (if (>= (vlax-safearray-get-u-bound value 1) 0)
  14.          (_kpblc-conv-vla-to-list (vlax-safearray->list value))
  15.          ) ;_ end of if
  16.        )
  17.       ((and (= (type value) 'vla-object)
  18.             (vlax-property-available-p value 'count)
  19.             ) ;_ end of and
  20.        (vlax-for sub value
  21.          (setq res (cons sub res))
  22.          ) ;_ end of vlax-for
  23.        )
  24.       (t value)
  25.       ) ;_ end of cond
  26.     ) ;_ end of defun
  27.  
  28.   (if (= (type (setq selset (vl-catch-all-apply
  29.                               (function
  30.                                 (lambda () (ssget '((0 . "INSERT") (66 . 1))))
  31.                                 ) ;_ end of function
  32.                               ) ;_ end of vl-catch-all-apply
  33.                      ) ;_ end of setq
  34.                ) ;_ end of type
  35.          'pickset
  36.          ) ;_ end of =
  37.     (progn
  38.       (foreach obj (mapcar (function vlax-ename->vla-object)
  39.                            ((lambda (/ tab item)
  40.                               (repeat (setq tab  nil
  41.                                             item (sslength selset)
  42.                                             ) ;_ end setq
  43.                                 (setq tab (cons (ssname selset (setq item (1- item))) tab))
  44.                                 ) ;_ end of repeat
  45.                               ) ;_ end of lambda
  46.                             )
  47.                            ) ;_ end of mapcar
  48.         (foreach att (vl-remove-if-not
  49.                        (function
  50.                          (lambda (x)
  51.                            (= (strcase (vla-get-textstring x)) (strcase tag))
  52.                            ) ;_ end of lambda
  53.                          ) ;_ end of function
  54.                        (apply (function append)
  55.                               (mapcar (function _kpblc-conv-vla-to-list)
  56.                                       (list
  57.                                         (vla-getattributes obj)
  58.                                         (vla-getconstantattributes obj)
  59.                                         ) ;_ end of list
  60.                                       ) ;_ end of mapcar
  61.                               ) ;_ end of apply
  62.                        ) ;_ end of vl-remove-if-not
  63.           (setq pt (vl-remove nil
  64.                               (mapcar
  65.                                 (function
  66.                                   (lambda (x)
  67.                                     (if (vlax-property-available-p att x)
  68.                                       (cons x (vlax-get-property att x))
  69.                                       ) ;_ end of if
  70.                                     ) ;_ end of lambda
  71.                                   ) ;_ end of function
  72.                                 '("insertionpoint" "textalignmentpoint")
  73.                                 ) ;_ end of mapcar
  74.                               ) ;_ end of vl-remove
  75.                 ) ;_ end of setq
  76.           (vla-put-alignment att acalignmenttopcenter)
  77.           (foreach item pt
  78.             (vlax-put-property att (car item) (cdr item))
  79.             ) ;_ end of foreach
  80.           ;; added only this string:
  81.           (vla-put-textalignmentpoint att (cdr (assoc "insertionpoint" pt)))
  82.           ) ;_ end of foreach
  83.         ) ;_ end of foreach
  84.       ) ;_ end of progn
  85.     ) ;_ end of if
  86.   ) ;_ end of defun
Sample of use:
Code - Auto/Visual Lisp: [Select]
  1. (test1 "1")
Sorry for my English.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #20 on: August 20, 2014, 02:14:18 PM »

I am sorry David , your codes did not work for me . and did not make any change to blocks  :embarrassed:
I added the back slash at the top of the routine .

Can you modify it again please ?

many thanks

I fixed the local variables. Can you post an example of 1 of your blocks?  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: change jusifications of attribute in block
« Reply #21 on: August 20, 2014, 02:25:31 PM »
I have error message after I modified your codes to make it left alignment  :embarrassed:

Quote
; error: Automation Error. Not applicable
Can you please help ?

Hint:

The InsertionPoint property controls the text position when the Alignment property is set to Left, the TextAlignmentPoint controls the text position for all other values of the Alignment property.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #22 on: August 21, 2014, 01:41:23 AM »
I fixed the local variables. Can you post an example of 1 of your blocks?  -David

You routine make changes to attribute string but it moves the attributes to '(0.0 0.0 0.0)  :-(

Thank you .

[/quote]
Try to use this:

Your codes make the attribute to top center and I am looking for left alignment .  :-(

Thank you .

I have error message after I modified your codes to make it left alignment  :embarrassed:

Quote
; error: Automation Error. Not applicable
Can you please help ?

Hint:

The InsertionPoint property controls the text position when the Alignment property is set to Left, the TextAlignmentPoint controls the text position for all other values of the Alignment property.
I got that lee , but I see the changes to left alignment does not affect the same thing as the attribute editor .

For example , if you change attribute from top center to left with the command eattedit , the attribute goes back to its original position and this is correct and perfect , but with
codes the attributes moves to left but its position keeps the attribute in its current position and this is my CONFUSION.  :-o

Thank you .


kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #23 on: August 21, 2014, 01:55:25 AM »
<...>
Your codes make the attribute to top center and I am looking for left alignment .  :-(<...>
Change acalignmenttopcenter to any value you like :)
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #24 on: August 21, 2014, 08:19:40 AM »
<...>
Your codes make the attribute to top center and I am looking for left alignment .  :-(<...>
Change acalignmenttopcenter to any value you like :)

I changed this from your routine and it give me error message .

Code: [Select]
          ) ;_ end of setq
          (vla-put-alignment att acalignmentleft) ;;; <<< to left alignment
          (foreach item pt (vlax-put-property att (car item) (cdr item))) ;_ end of foreach

; error: Automation Error. Not applicable

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #25 on: August 21, 2014, 08:29:46 AM »
The problem is determining the existing justification values including dxf groups 10 & 11.  Do you want the attribute to retain its original location and only change the group 72 & 74 values? 

The initial default is group 10 baseline left and group 11 '(0 0 0)  flags 72 & 74 0

I changed the code so that it exchanges group 11 from group 10.  -David
R12 Dos - A2K

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #26 on: August 21, 2014, 09:01:59 AM »
David , Did you try your codes by any chance ?

Your codes still do the same  :-( all attributes go to origin .

Thank you

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #27 on: August 21, 2014, 09:58:46 AM »
David , Did you try your codes by any chance ?

Your codes still do the same  :-( all attributes go to origin .

It works on my test blocks.  That's why it is important to provide samples as there are lots and lots of scenarios that can lead to unintended errors   -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: change jusifications of attribute in block
« Reply #28 on: August 21, 2014, 10:31:44 AM »
David , Did you try your codes by any chance ?

Your codes still do the same  :-( all attributes go to origin .

It works on my test blocks.  That's why it is important to provide samples as there are lots and lots of scenarios that can lead to unintended errors   -David

David,

I believe this:
Code - Auto/Visual Lisp: [Select]
  1. (subst (assoc 10 ad) (assoc 11 ad) ad))

Needs to be:
Code - Auto/Visual Lisp: [Select]
  1. (subst (cons 11 (cdr (assoc 10 ad))) (assoc 11 ad) ad))

The existing code would move the attributes to the origin if the current attribute alignment is set to Left.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #29 on: August 22, 2014, 06:59:47 AM »
Lee,

Yes, you are correct.  My bad for editing on the fly.  The end result could still be unintended if the OP wants the text to retain it's original position and only change the justifacation flags.   -Thanks!  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: change jusifications of attribute in block
« Reply #30 on: August 22, 2014, 11:51:12 AM »
The end result could still be unintended if the OP wants the text to retain it's original position and only change the justifacation flags.

Agreed - no worries David.