Author Topic: change jusifications of attribute in block  (Read 8319 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: 12914
  • 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: 12914
  • 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: 12914
  • 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)