Author Topic: Lwpolyline Area Reactor Help!  (Read 3781 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Lwpolyline Area Reactor Help!
« on: August 30, 2005, 05:18:49 PM »
Ok, I found this lisp and I was wondering if anyone can help me change this to work with an attibuted block.

Basically, this routine will ask the user to select a lwpolyline, then ask the user to select a point for the label, it will then create a text abject and change it to reflect the lwpolylines square footage with the use of reactors so that if the shape of the lwpolyline changes then the text auto-updates itself.

I would like this to do the same but with a attributed block. Any idears....

See code below:
Code: [Select]

(vl-load-com)
   (Setq acadApp    (vlax-get-acad-object)
            acadDoc    (vla-get-ActiveDocument acadApp)
            mSpace     (vla-get-ModelSpace acadDoc)
   )
(defun esq_xdlist (ename rname / data elist)
     (setq elist (entget ename (list rname)))
     (setq data (cdr (car (cddr (cadr (assoc -3 elist))))))
)
(defun esq_xdata (ename rname l_code l_valeur / xd_list elist xd_type input)
     (setq elist (entget ename))
     (regapp rname)
     (setq xd_list (list '(1002 . "}")))
     (repeat (length l_code)
       (setq xd_type  (car l_code)
             l_code   (cdr l_code)
             input    (car l_valeur)
             l_valeur (cdr l_valeur)
             xd_list  (cons (cons xd_type input) xd_list)
       )
      )
      (setq xd_list (cons '(1002 . "{") xd_list))
      (setq xd_list (cons rname xd_list))
      (setq xd_list (list -3 xd_list))
      (setq elist (cons xd_list elist))
      (entmod elist)
      (prin1)
)
(defun c:mksurf()
   (if (setq curEnt   (car (entsel)))
       (setq curObj   (vlax-ename->vla-object curEnt)
               curArea  (vla-get-area curObj)
     )
   )
  (setq curpoint (getpoint"\npick label insertion point : "))
  (setq curArea (rtos curArea 2 2))
  (setq ObjText (vla-addtext mspace curArea  (vlax-3d-point curpoint) 0.25))
  (setq entext (entlast))
  (esq_xdata curEnt "ESQ2001-1" (list '1005) (list (cdr (assoc 5 (entget entext)))))
(setq SurfReactor (vlr-object-reactor (list CurObj) "Surface Reactor" '((:vlr-modified . modif-texte))))
(vlr-pers SurfReactor)
)
(defun modif-texte (notifier-object reactor-object parameter-list)
   (cond
     (
      (vlax-property-available-p
        notifier-object
        "Area"
      )
      (setq newarea (strcat (rtos (/ (vla-get-area notifier-object) 144) 2 2)" Sq. Ft."))
      (setq handle (esq_xdlist (vlax-vla-object->ename notifier-object) "ESQ2001-1"))
      (vlax-put-property (vlax-ename->vla-object (handent handle)) "TextString" newarea)
     )
   )
)


I use Autocad 2002 for now.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Lwpolyline Area Reactor Help!
« Reply #1 on: August 31, 2005, 10:37:22 AM »
Ok, After playing around with this, I finally got this to work with a attributed block. But this still needs some more tweeking.

This routine seems to work initially when running it in the drawing. Once you save and get out of the drawing and then re-open the drawing the reactor is "inactive" ?? I need it to be running so that if someone manipulates a lwpolyline by stretching, then the attributed block will update the square footage.

Code: [Select]

(defun c:NRTEST ()
(setq curEnt (car (entsel "\npick space to label: ")))
(setq curObj   (vlax-ename->vla-object curEnt)
        curArea  (vla-get-area curObj))
  (setq curpoint (getpoint "\npick label insertion point: "))  
  (setvar "attdia" 0)
(command "-insert" "test" curpoint "" "" "")
  (setq entext (entlast))
  (esq_xdata curEnt "ESQ2001-1" (list '1005) (list (cdr (assoc 5 (entget entext)))))
  (setq label_object (vla-get-handle (vlax-ename->vla-object (ssname (ssget "l") 0))))
  (setq plinereactor (vlr-object-reactor (list curObj) label_object '((:vlr-modified . print-area))))
)
(defun print-area (pline reactor null_list / attributes square_feet_attribute square_feet block_reference)
  (setq block_reference (vlr-data reactor) block_reference (handent block_reference)
          block_reference
  (vlax-ename->vla-object block_reference)
  )
  (setq attributes (vla-getattributes block_reference) attributes (vlax-variant-value attributes)
          attributes (vlax-safearray->list attributes)
  )
(setq square_feet_attribute (cadr attributes))
(setq square_feet (strcat (rtos (/ (vla-get-area pline) 144) 2 3 ) " Sq. Ft. "))
  (vla-put-textstring square_feet_attribute square_feet)
)
(defun esq_xdata (ename rname l_code l_valeur / xd_list elist xd_type input)
     (setq elist (entget ename))
     (regapp rname)
     (setq xd_list (list '(1002 . "}")))
     (repeat (length l_code)
       (setq xd_type  (car l_code)
             l_code   (cdr l_code)
             input    (car l_valeur)
             l_valeur (cdr l_valeur)
             xd_list  (cons (cons xd_type input) xd_list)
       )
      )
      (setq xd_list (cons '(1002 . "{") xd_list))
      (setq xd_list (cons rname xd_list))
      (setq xd_list (list -3 xd_list))
      (setq elist (cons xd_list elist))
      (entmod elist)
      (prin1)
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

deegeecees

  • Guest
Lwpolyline Area Reactor Help!
« Reply #2 on: August 31, 2005, 11:00:46 AM »
I believe you need to create some kind of event driven startup:

- Drawing is opened
- DVB file checks for reactor in dwg
- Reactor found
- Reactor updated

Or something similar. I've been out of the code writing scene for a while, and am kinda rusty (doing alot of drafting grunt work), hence the vagueness of my response.