Author Topic: embed text into a block or xref?  (Read 3233 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
embed text into a block or xref?
« on: December 18, 2003, 12:37:01 PM »
I'm working on a routine that will calcualte the area of an object and return that value in the form of a text string. The text string can be an existing text or can be added text. The more I use the nentsel function, the more really cool things I find about it. I have found that nentsel will find the actual area of a blocked or xref'd object no matter what the scale of the object is. That is so cool. No extra math involved. When I realized this, I wanted to be able to add the text to the block. So that's where I'm at. Has anybody done, or does anybody know of a way, without exploding and redefining the selected block, to embed text into a block? I'll post what I have so far.
Code: [Select]
;;select object
;;create object list
;;create object check list
;;select next object
;;check object against object list
(defun Mobj-selection ()
     (while (setq nent
     (nentsel
  "\nSelect object to check the area of: "
     )
   )
 (if (= alist nil)
      (setq alist (append alist (list (car nent))))
      (progn
   (setq tlist alist)
   (if (not (member (car nent) alist))
(setq alist
  (append alist
  (list (car nent))
  )
)
(progn
     (prompt
  "\nObject selected previously, will not be added to selection."
     )
     (setq alist tlist)
)
   )
      )
 )
     )
)
(defun obj-list-creater ()
     (foreach item alist
 (setq nlist
   (append nlist
   (list (vlax-ename->vla-object item))
   )
 )
     )
     (foreach obj nlist
 (setq area (vla-get-area obj))
 (setq oarea (+ oarea area))
 (setq sqft (/ oarea 144))
     )
)
(defun Str-selected-obj ()
     (setq sqfttext (strcat (rtos sqft 2 0) " SQ. FT."))
     (initget "Newtext")
     (setq tent
      (nentsel
   "\nSelect text object to add area to or [New text]: "
      )
     )
)
(defun Str-CmdLine-PassBack ()
     (princ (strcat
"\nArea of selected objects are:\n"
(rtos oarea 2 2)
" square inches.\n"
(rtos sqft 2 2)
" square feet."
   )
     )
)
(defun Str-obj->String ()
     (defun TextAdd ()
 (vla-addText Model sqfttext (vlax-3d-point (cadr tent)) 3.0)
     )
     (defun typeobj (val ent)
 (cdr (assoc val (entget (car ent))))
     )
     (cond ((and (= (type tent) 'LIST)
(= (length tent) 2)
(or (= (typeobj 0 tent) "TEXT")
    (= (typeobj 0 tent) "MTEXT")
    (= (typeobj 0 tent) "ATTRIB")
)
   )
   (vla-put-textString
(vlax-ename->vla-object (car tent))
sqfttext
   )
   (if (= (length tent) 4)
(vla-regen $acad acAllViewports)
   )
  )
  ((= tent nil)
   (setq tent (grread (getvar 'lastpoint)))
   (TextAdd)
  )
  ((= tent "Newtext")
   (setq tent
     (getpoint "\nSelect point for placement of text: ")
   )
   (TextAdd)
  )
     )
)
;;;-----------------------------------------------------------------------------;
;;; Add Text to Selected Area Object ;
;;;-----------------------------------------------------------------------------;
;;; ver. 1.0 ;
;;; Routine calculates area by objects and places or replaces text object info  ;
;;;-----------------------------------------------------------------------------;
;;; todo: Get layer information of object and put text on that layer. ;
;;;  Separate single object selection and multiple object selection ;
;;; and make repeatable single selection. ;
;;;       Find a way to embed text into a block or xref. ;
;;;_____________________________________________________________________________;
(defun c:ara (/ alist tlist nlist oarea nent area sqft tent Model)
     (setq alist nil
  tlist nil
  nlist nil
  oarea 0
  Model (vla-get-modelspace
     (vla-get-activedocument
  (vlax-get-acad-object)
     )
)
     )
     (Mobj-selection)
     (obj-list-creater)
     (Str-selected-obj)
     (Str-obj->String)
     (Str-CmdLine-PassBack)
     (princ)
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16867
  • Superior Stupidity at its best
embed text into a block or xref?
« Reply #1 on: December 18, 2003, 01:48:31 PM »
Redefining the block would seem like the only solution to me. In an XRef though you would have a bit of problem because it would likely have to be updated in the referenced drawing.
A solution would be to use a specifically named block or table in the drawing that the proggie will update based on the selection, rather than have it update the block itself, particularly if the block is inserted as a scaled block. If it is inserted into another drawing, then the block will be incorrect if the scale is different.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
embed text into a block or xref?
« Reply #2 on: December 18, 2003, 02:01:58 PM »
Quote
If it is inserted into another drawing, then the block will be incorrect if the scale is different.
I'm not sure what you mean. I have found that even if the block is scaled up the area always reads the same. I think the nentsel function accounts for scale size. I have an xref of a block insertion. I run the command in both drawings and all cases I get the same area results at different scales.

Anyway, as far as the embeddment goes, it was just a thought. It's not necessary.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16867
  • Superior Stupidity at its best
embed text into a block or xref?
« Reply #3 on: December 18, 2003, 03:29:45 PM »
What I was referring to was the scale of the area being written to an xref drawing, when that xref is attached to another drawing, if the scale is not the same the embedded test will not represent the correct area.
EX:
dwg-a has an xref dwg-b in dwg-a the xref is an even scale of 2x. If you embed a bit of text into xref dwg-b and then subsequently insert or xref dwg-b into dwg-c at say a scale of 3x the embedded text would not read correctly. It would read as though the xref was scaled 2x.

Unless I missed the point all together
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
embed text into a block or xref?
« Reply #4 on: December 18, 2003, 04:39:16 PM »
I'm not sure. I haven't tried nor think I'll ever take it that far. I took dwg-a into dwg-b, copied it and enlarged it, then xrefed it into dwg-c and tested it in b and c. Both answers were the same and correct. Maybe I'm missing the point. If I ever do encounter your issue, I guess I'll have so tinkering to do, huh. Oh well, now it's off the clean it up and error trap it. Thanks Keith.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16867
  • Superior Stupidity at its best
embed text into a block or xref?
« Reply #5 on: December 18, 2003, 04:57:58 PM »
Ok Daron, here is a little routine I put together just for you..it should make it a cinch to add text to any block as long as you know the block name, the text you want to add, the point at where you want to add it, and the text size.

Code: [Select]

;;; ADDTEXT2BLK
;;; Written by K.E. Blackie
;;; 18 December 2003
;;; Version 1.0
;;; This code may be copied modified and included in any subsequent
;;; works that are not sold, tranferred or otherwise bartered for profit
;;;
;;; Note that the variable BLK is defined GLOBALLY so that the user
;;; can later manipulate this block if they need to without having to
;;; go through the hoops of obtaining it again.
;;; If you want to make it local simply add it to the localized list in the
;;; function definition
(defun addtext2blk (blockname textstring 3dpoint textheight / thisdrawing)
  (vl-load-com) ;in compliance with "TheAct"
;;;get the block in the active drawing
;;;by the way I hate using variables
  (setq blk (vla-item (vla-get-blocks (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))))blockname))
;;;add the text to the block
  (vla-addtext blk textstring (vlax-3d-point 3dpoint) textheight)
;;;force a regen to see the new addition
  (vla-regen thisdrawing 1)
;;;release the drawing object
  (vlax-release-object thisdrawing)
)


This could prove to be a decent little routine now that I have messed around with it a bit...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
embed text into a block or xref?
« Reply #6 on: December 18, 2003, 05:31:55 PM »
Keith, that's a beaut. Thanks a whole lot. I haven't tried it on an xref yet, but wow. That was exactly what I was thinking to do.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16867
  • Superior Stupidity at its best
embed text into a block or xref?
« Reply #7 on: December 18, 2003, 05:38:40 PM »
I am glad you like...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
embed text into a block or xref?
« Reply #8 on: December 18, 2003, 05:48:40 PM »
Yes. I'll let you know when I finish it.