Author Topic: Help needed fixing area reactor  (Read 7110 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Help needed fixing area reactor
« on: October 18, 2005, 06:24:57 PM »
Attached is a my feeble attempt of making a area reactor. I need a little assistance with this plz.

It no worky!!
 :-)



Changed Subject Title: CAB
« Last Edit: March 24, 2006, 05:00:22 PM by CAB »
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

LE

  • Guest
Re: Reactor Help
« Reply #1 on: October 18, 2005, 06:45:30 PM »
Don,

I have not tested your routine, something that I see in your code:

It is no way that you can do any update to the owner objects even if you tried with the attribute.

You need to have two types of reactors, the object one and the command reactor and use a commandended event and in there you can manipulate the owner/notifier object and do there the updates.

Have a look into my reactors samples on my web site in particular the auto xyz.... you may want to adapt it to suit your needs, it even has the copied event applied.....

Have fun.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Reactor Help
« Reply #2 on: October 19, 2005, 07:12:56 AM »

Thanks, I will check it out
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!
Re: Reactor Help
« Reply #3 on: October 20, 2005, 08:54:38 AM »

Ok, after further tweaking I have finally got this to produce the results that I want. It may not be pretty and I'm sure that there are many ways to accomplish the same results a different way but , Hey, it works. This routine will allow the user to select a lwpolyline and insert a attributed block and have it keep track of the square footage even if the lwployline is altered. Just place in a "mnl" file and walla.... Now I know that I still have a lot to learn but you have to start somewhere.

Code: [Select]
(defun c:AreaTag ( / curEnt curObj curPoint square_feet2 label_object plinereactor)
(vl-load-com)
  (setq curEnt (car (entsel "\npick space to label: ")))
  (setq curObj (vlax-ename->vla-object curEnt)
          curArea  (vla-get-area curObj)
  )
  (setq square_feet2 (strcat (rtos (/ (vla-get-area curObj) 144) 2 2 ) " Sq. Ft. "))
  (setq curPoint (getpoint "\npick label insertion point: "))
  (setvar "attdia" 0)
  (setvar "attreq" 0)
  (command "-insert" "test" curpoint "" "" "")
  (setq entext (entlast))
  (chgsqft)
  (setq label_object (vla-get-handle (vlax-ename->vla-object (ssname (ssget "l") 0))))
  (esq_xdata curEnt "SSA_XDATA" (list '1005) (list (cdr (assoc 5 (entget entext)))))
  (setq plinereactor  (vlr-object-reactor (list curObj) label_object '((:vlr-modified . print-area))))
  (vlr-pers plinereactor)
  )
(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 (vlax-invoke block_reference 'getattributes));;not necessary to change this, but it's easier to read,
(foreach att attributes
  (if (eq (vla-get-tagstring att) "SQUARE_FEET");;<<<---change to value your attribute uses
    (progn
      (setq square_feet (strcat (rtos (/ (vla-get-area pline) 144) 2 2 )))
      (setq remove (atof square_feet))
      (setq square_feet (strcat (@rtoc remove 2) " Sq. Ft. "))
      (vla-put-textstring att square_feet)
      )
    )
  )
)
(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 @rtoc (N Prec / Sign Str i j);This section places a "," in the number if applicable
   (setq Prec (max 0 Prec)
         Sign (if (minusp N) "-" "")
         Str  (rtos (abs N) 2 Prec)
         i    (vl-string-search "." Str)
   )
   (if (not i)(setq i (strlen Str))) ; <-- Here
   (setq j i)
   (if (zerop (setq i (rem i 3)))(setq i 3))
   (while (< i j)
      (setq Str (strcat (substr Str 1 i) "," (substr Str (1+ i)))
           i (+ i 4)
           j (1+ j)
      )
   )
   (strcat Sign Str)
)
(defun changeAtt (ent tag val / entl ins)
  (setq ins ent)
  (while (and ent
           (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (if (and (= (cdr (assoc 0 entl)) "ATTRIB")
             (= (cdr (assoc 2 entl)) tag))
      (entmod (subst (cons 1 val) (assoc 1 entl) entl)))
    (setq ent (entnext ent)))
  (entupd ins)
)
(defun chgsqft ()
  (cond ((setq sset (ssget "X" '((2 . "TEST") (66 . 1))))
         (setq a 0)
         (repeat (sslength sset)
           (setq ent (ssname sset a)
                 a   (1+ a)
           )
           (setq remove1 (atof square_feet2))
           (setq square_feet2 (strcat (@rtoc remove1 2) " Sq. Ft. "))
           (changeAtt ent "SQUARE_FEET" square_feet2) ;<- change value
         )
        )
  )
  (princ)
)

AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CADwoman

  • Guest
Re: Reactor Help
« Reply #4 on: January 25, 2006, 06:01:19 PM »
Wow, this is great! I've been trying to write a lisp to just that. What is the difference between this one an your older version? Also, I think it would be good to display Sq Meter when inserted into a Metric file. I have been using a lisp written by Leonid Nemirovsky. I've updated it to add a square meter conversion. So it will give you m2 in a metric file and SF in a Architectural file. Let me know if this makes sense to you.

Code: [Select]
;;;Link Area Text to Boundary   (c) 2004 Leonid Nemirovsky
;;;
;;;Updated 01/11/06 by Vincent Poon
;;;---Added Square Meter conversion for metric units
;;;
(defun ufa (notifier-object reactor-object parameter-list)
  (vl-load-com)
  (cond
    ((vlax-property-available-p notifier-object "Area")
     (setq actDoc
     (vla-get-ActiveDocument (vlax-get-acad-object)))
     (vla-SAVE actDoc)
    )
  )
)


(defun plar(/ pt pt1 pt2)
(setq pt (getpoint"\nStarting Point: "))
(setq pt1 (getpoint pt "\nNext Point: "))
(command "Pline" pt pt1 "")
   (while
       (setq pt2 (getpoint pt1"\nNext Point: "))
      (command "pline" "" pt2 "")
      (command "pedit" pt "j" pt pt2 "" "")
      (setq pt1 pt2)
   )
(command "pedit" pt "c" "")
(princ)
)

(defun ar5 ()
(SETQ A NIL)
(vl-load-com)

  (setq cm (getvar "cmdecho"))
  (setvar"cmdecho" 0)
  (setq fd (getvar "fielddisplay"))
  (if (/= fd 0)(setvar"fielddisplay" 0))

    (setq ar1 (entsel "\nSelect Area Boundary: "))
    (setq ar2 (car ar1))
    (setq tab (vlax-ename->vla-object ar2))
    (setq oba (vla-get-objectid tab))

(setq lu (getvar "lunits"))
(setq tpt (getpoint"\nSelect Area Text Point: "))
(cond
;;;  lu 1 = Scientific      1.55E+01
;;;  lu 2 = Decimal         15.50
;;;  lu 3 = Engineering     1'-3.50"
;;;  lu 4 = Architectural   1'-3 1/2"
;;;  lu 5 = Fractional      15 1/2 
((= lu 2) (setq lin (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu2%qf1%ps[, m\\u+00b2]%ct8[1e-006]\">%")))
((= lu 4) (setq lin (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu2%ct4%qf1 SQ.FT.\">%")))
((= lu 3) (setq lin (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu2%qf1 sq.in.\">%")))
((= lu 5) (setq lin (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu5%qf1 \">%")))
((= lu 1) (setq lin (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu1%qf1 \">%")))
)
(command "mtext" tpt "w" "0" lin "")
(setq plineReactor (vlr-object-reactor (list tab)  "pline Reactor" '((:vlr-modified . ufa))))

(princ)
)       

(defun c:areacalc (/ key)
(initget  1 "Boundary Label-existing")
(setq key (getkword "\nWould you like to create a new Boundary<B> or Label-existing<L>: "))
   (cond
     ((= key "Boundary")(plar)(ar5))
     ((= key "Label-existing")(ar5))
   )
(princ)
)
(defun C:AC () (C:areacalc))


hornet 103

  • Guest
Re: Reactor Help
« Reply #5 on: March 13, 2006, 05:30:54 AM »
hello CADwoman

I've just had a request to add to your program, is there any chance of adding an area name option, to the area size, I guess this will be "getstring" so that you name the area you are measuring.

many thanks :-)

Hornet 103

Shade

  • Guest
Re: Reactor Help
« Reply #6 on: March 17, 2006, 02:14:23 PM »
What modification would one have to make to dvarino’s code for the AreaTag.lsp to get it update the area (attribute) automatically after the drawing has been closed and reopened and the pline (entity) has been adjusted, without running Areatag again and selecting the pline again?

I really like the lisp, and I would like to modify it to work like the fields do in autocad 2006.  I am self employed as a drafter. My clients have different versions of autocad, most pre 2005.  It a pain doing area calcs, the old fashion way.  :-(
Any tips on how to modify Areatag would be appreciated…

By the way Great Lisp, Dvarino! I have learned a lot from your code. :-)

LE

  • Guest
Re: Reactor Help
« Reply #7 on: March 17, 2006, 03:56:39 PM »
Shade;

Have a look into this topic, about object reactors:

http://www.theswamp.org/index.php?topic=8889.0


HTH

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Reactor Help
« Reply #8 on: March 17, 2006, 10:34:38 PM »

Quote
By the way Great Lisp, Dvarino! I have learned a lot from your code.

Thanks, I'm glad that I can some assistance. Props go out to the guys here at the swamp though. They really helped me with this.

If you first do not succeed, try, try again.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CADwoman

  • Guest
Re: Reactor Help
« Reply #9 on: March 20, 2006, 12:07:53 PM »
Have you try the one I posted which uses the fields in ACAD2006?

What modification would one have to make to dvarino’s code for the AreaTag.lsp to get it update the area (attribute) automatically after the drawing has been closed and reopened and the pline (entity) has been adjusted, without running Areatag again and selecting the pline again?

I really like the lisp, and I would like to modify it to work like the fields do in autocad 2006.  I am self employed as a drafter. My clients have different versions of autocad, most pre 2005.  It a pain doing area calcs, the old fashion way.  :-(
Any tips on how to modify Areatag would be appreciated…

By the way Great Lisp, Dvarino! I have learned a lot from your code. :-)


Shade

  • Guest
Re: Reactor Help
« Reply #10 on: March 20, 2006, 02:29:13 PM »
Have you try the one I posted which uses the fields in ACAD2006?

I don't have access to autocad 2006 all the time. Instead I would like something that will work in 2004.
I did check your lisp CADwoman, and I learned some new stuff from it. It just hard to test my code when 2006 is not always available.

By the way nice work.
 :mrgreen:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Reactor Help
« Reply #11 on: March 20, 2006, 02:42:28 PM »
Mabe this one will help you Shade.  This is where Luis helped me a lot with my reactor routine.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.