Jump to content

Recommended Posts

Posted

This might be what your looking for.

 

Posted (edited)

To Mhupp - Hi, thank you for your reaction, but it doesn't seem to fit my requirement. Example dwg attached. 

area2txt.dwg

 

To zwonko - Quick Filed does it! (but only support one polyline) - maybe I will use it (99% ares are in one polyline). How to modify my format (%lu2%pr2%ds44%ct8[1e-006]%ps[, m2]) to support "m2" as an upper index?

Edited by VAC
Posted

a2f support more polylines.

I don't know how to put stuck. Maybe is the thing that i use zwcad not autocad. the stack mtext code is for example \S2^;

 

Posted

a2f supports more polylines, but creates new mtext instead of putting it into an existing one

m2 can be added next to inserted area field as a simple text (not as a field suffix), but I don't know where (script line Quick Field lisp) and how to add it in (syntax). Any idea?

Posted (edited)

in quickfield everything is explanind in the file. Bassically you should add on the end

 

(defun c:youarea ( ) (LM:QuickField "Area" "%lu2%pr2%ds44%ct8[1e-006]%ps[, m2]" 1)) 

 

or maybe 

(defun c:youareastack ( ) (LM:QuickField "Area" "%lu2%pr2%ds44%ct8[1e-006]%ps[, m\S2^;]" 1))      

to get stack (in ZWCAD it is not working. Eventually try to inspect mtext properties how is the code for stack in your cad.

 

 

 

Eventually you can modiffy:

 

(defun LM:quickfield ( prop format mode / ent ins obj str )  
    (if (setq str (LM:quickfield:constructfieldstring prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:quickfield:selectifhasprop "Textstring" nentsel))
                    (progn
                        (setq obj (vlax-ename->vla-object ent))
                        (vla-put-textstring obj "") ;; To clear any existing field
                        (vla-put-textstring obj (strcat str "square meter"))
                        (if (= "ATTRIB" (cdr (assoc 0 (entget ent))))
                            (vl-cmdf "_.updatefield" ent "")

(where i add suare meter)

 

 

also you can check changed a2f which update text instead off putting new. FOr me is not working becouse zwcad can't sum fields in formulas.

(defun c:a2fmodoverwrite ( / *error* fmt inc ins lst sel str )

    (setq fmt "%lu6%qf1") ;; Field Formatting

    (defun *error* ( msg )
        (LM:endundo (LM:acdoc))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (if
        (and
            (setq sel (ssget '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))))
        )
        (progn
            (if (= 1 (sslength sel))
                (setq str
                    (strcat
                        "%<\\AcObjProp Object(%<\\_ObjId "
                        (LM:ObjectID (vlax-ename->vla-object (ssname sel 0)))
                        ">%).Area \\f \"" fmt "\">%"
                    )
                )
                (progn
                    (repeat (setq inc (sslength sel))
                        (setq lst
                            (vl-list*
                                "%<\\AcObjProp Object(%<\\_ObjId "
                                (LM:ObjectID (vlax-ename->vla-object (ssname sel (setq inc (1- inc)))))
                                ">%).Area>%" " + "
                                lst
                            )
                        )
                    )
                    (setq str
                        (strcat
                            "%<\\AcExpr "
                            (apply 'strcat (reverse (cdr (reverse lst))))
                            " \\f \"" fmt "\">%"
                        )
                    )
                )
            )
            (LM:startundo (LM:acdoc))
		(if (setq ent (LM:quickfield:selectifhasprop "Textstring" nentsel))
                    (progn
                        (setq obj (vlax-ename->vla-object ent))
                        (vla-put-textstring obj "") ;; To clear any existing field
                        (vla-put-textstring obj str)
                        (if (= "ATTRIB" (cdr (assoc 0 (entget ent))))
                            (vl-cmdf "_.updatefield" ent "")
                        )
                    )
                )
            (LM:endundo (LM:acdoc))
        )
    )
    (princ)
)

;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
 
(defun LM:ObjectID ( obj )
    (eval
        (list 'defun 'LM:ObjectID '( obj )
            (if
                (and
                    (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                    (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                )
                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:ObjectID obj)
)
 
;; Start Undo  -  Lee Mac
;; Opens an Undo Group.
 
(defun LM:startundo ( doc )
    (LM:endundo doc)
    (vla-startundomark doc)
)
 
;; End Undo  -  Lee Mac
;; Closes an Undo Group.
 
(defun LM:endundo ( doc )
    (while (= 8 (logand 8 (getvar 'undoctl)))
        (vla-endundomark doc)
    )
)
 
;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object
 
(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
 
(vl-load-com) (princ)




(defun LM:quickfield:selectifhasprop ( prop func / ent )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (func (strcat "\nSelect object with " prop " property: "))))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                    (princ (strcat "\nSelected object does not have " prop " property."))
                )
            )
        )
    )
    ent
)
 
;;------------------------------------------------------------;;
;;                        End of File                         ;;
;;------------------------------------------------------------;;

 

Edited by zwonko
Posted

A way may be to add the unicode \U+00B2 to the mtext string. Which is superscript 2.

Posted

Zwonko, Bigal, both script works great (I add succesfully unicode string for m2 from Bigal) - many thanks. 🙂

If in a2f script (is better) should persist the possibility to add field even to table cell (you changed this function) - depending on where I will click - so field should be added to any text(works), mtext(works), attribute(works) or table cell(works in original lisp) in one lisp - you will be my HERO(s)!

Posted

You didn't say what You need on the beggining.

So the thing is to use this one:

http://www.lee-mac.com/lengthfield.html

on the beggining make your own like:

(defun c:afm ( ) (areafield nil "%lu6%qf1%ct8[1e-6]")) ;; Current units with 1e-6 (0.000001) conversion factor (mm2->m2)

 

In this lisp you could add new text/ replace table cell, or select Object to change (object is text, mtext, atrib, bla bla)

image.png.ced839477f5306c02cee90908dfd5ff8.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...