Author Topic: Retrieving a Mtext Value inside a Xref  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

jaydee

  • Guest
Retrieving a Mtext Value inside a Xref
« on: July 03, 2011, 02:19:44 AM »
Hi.
Would someone able to to be a head start or the lisp codes how to extract the Mtext value inside a xref (drawing sheet) without user input,
given that i already know:-

xref name
its a MTEXT, color GREEN, height is 6.5mm, layer TITLE-TEXT.

What i would like is to use the extracted the mtext value to propulate it into drawing properties which i already have a lisp for it.

Thankyou

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Retrieving a Mtext Value inside a Xref
« Reply #1 on: July 03, 2011, 04:45:13 AM »
Check this out buddy . :-)

I did not include the name of the layer because layer names would be changed while being attached  as Xref .

Code: [Select]
(defun c:test (/ ss lst xref all str)
  ;; Tharwat 03. 07. 2011
  (if
    (and
      (setq ss (ssget "_+.:S" '((0 . "INSERT"))))
      (vlax-property-available-p
        (vlax-ename->vla-object (ssname ss 0))
        'Path
      )
    )
     (progn (setq lst '())
            (vlax-for x
                        (setq xref
                               (vla-item
                                 (vla-get-blocks
                                   (vla-get-activedocument
                                     (vlax-get-acad-object)
                                   )
                                 )
                                 (cdr (assoc 2 (entget (ssname ss 0))))
                               )
                        )
              (vlax-for all xref
                (if
                  (and
                    (eq (vla-get-objectname all) "AcDbMText")
                    (eq (vla-get-color all) acgreen)
                    (eq (vla-get-height all) 6.5)
                  )
                   (progn
                     (setq str (vla-get-textstring all))
                     (if
                       (not
                         (member str lst)
                       )
                        (setq lst (cons str lst))
                     )
                   )
                )
              )
            )
            (print lst)
     )
     (princ)
  )
  (princ)
)

Tharwat

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Retrieving a Mtext Value inside a Xref
« Reply #2 on: July 03, 2011, 07:37:17 AM »
Here's another way:

Code: [Select]
(defun _getmtextstring ( blk / ent enx txt )
  (if (setq ent (tblobjname "BLOCK" blk))
    (while (and (setq ent (entnext ent)) (not txt))
      (setq enx (entget ent))
      (if
        (and
          (eq "MTEXT" (cdr (assoc  0 enx)))
          (= 6.5      (cdr (assoc 40 enx)))
          (= 3        (cdr (assoc 62 enx)))
          (eq
            (strcase (strcat blk "|TITLE-TEXT"))
            (strcase (cdr (assoc 8 enx)))
          )
        )
        (setq txt (cdr (assoc 1 enx)))
      )
    )
  )
  txt
)

To be called with XRef name:

Code: [Select]
(_getmtextstring "YourXRef")
Or, for more generic use perhaps:

Code: [Select]
(defun _getblockentities ( block / lst )
  (if (setq block (tblobjname "BLOCK" block))
    (while (setq block (entnext block))
      (setq lst (cons block lst))
    )
  )
  (reverse lst)
)

Which will return a list of all entities present in a block definition with the supplied block name.

jaydee

  • Guest
Re: Retrieving a Mtext Value inside a Xref
« Reply #3 on: July 03, 2011, 10:34:43 PM »
Thankyou Tharwat and Lee Mac for your generosity

Both codes works exactly what im after.

Cheers

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Retrieving a Mtext Value inside a Xref
« Reply #4 on: July 04, 2011, 12:12:15 AM »
You're welcome jaydee  :-)

Tharwat

jaydee

  • Guest
Re: Retrieving a Mtext Value inside a Xref
« Reply #5 on: July 04, 2011, 03:23:37 AM »
I would like to ask one more thing.
Because the codes to extract this mtext value is to specific to its size, color etc. very often that we have to used the style given to us to put on our drawing sheet. therefore difficult to control.

Im thinking that the location of the mtext is more stable.

Is it possible to check if any text/mtext regardless of it properties are located within a certain area.
Say i got an A1 sheet (0,0 @ bottom left), the text is located within xy coord of 600,20 to 700,50mm.
If a piece text fall within this area then read its value.

thankyou in advance.


ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Retrieving a Mtext Value inside a Xref
« Reply #6 on: July 04, 2011, 07:37:20 AM »
I have disabled conditions for your type of MTEXT, but put condition of coordinates... You can experiment by your own and make set of conditions that best fit your needs...

Code: [Select]
(defun _getmtinarea ( blk / ent enx txt )
  (if (setq ent (tblobjname "BLOCK" blk))
    (while (and (setq ent (entnext ent)) (not txt))
      (setq enx (entget ent))
      (if
        (and
          (eq "MTEXT" (cdr (assoc  0 enx)))
;          (= 6.5      (cdr (assoc 40 enx)))
;          (= 3        (cdr (assoc 62 enx)))
;          (eq
;            (strcase (strcat blk "|TITLE-TEXT"))
;            (strcase (cdr (assoc 8 enx)))
;          )
          (< 0.0 (car (cdr (assoc 10 enx))) 600.20)
          (< 0.0 (cadr (cdr (assoc 10 enx))) 700.50)
        )
        (setq txt (cdr (assoc 1 enx)))
      )
    )
  )
  txt
)

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

jaydee

  • Guest
Re: Retrieving a Mtext Value inside a Xref
« Reply #7 on: July 04, 2011, 08:43:44 AM »
Thankyou Ribarm.
This will give me another option to retrieve the text and might be more flexible.