Jump to content

The opposite of "FieldObjetsV1-0.lsp" of Lee Mac


Recommended Posts

Posted (edited)

Hi everyone,

I've just found all lisp work of Lee Mac and I am quite overwhelmed by the number of useful commands I have found on his website. I will donate him in the future, I promise. He deserved it.
Now with the "help" of Chatgpt i've tried to do the opposite of FieldObjectsV1-0.lsp routine can do. 
This routine allows you to select a block that has fields and say where those fields are located.
I would like to know if it would be possible to do the opposite. That is to say. I have a block (let's call it block A), which has a manually typed attribute with the height. For example 440.00. This would be the base height. And I want you to tell me all the other blocks that calculate their height using the height of the base block. That is to say...
Y coordinate of block B - Y coordinate of block A + height contained in the base block.
I am attaching a file for better understanding.
It's very simple. A block with an attribute to measure heights. In one of them that we call base (block A) we manually set a height. All the other blocks (block B) calculate their height taking into account the height that I manually entered in block A and the difference between their Y coordinates.

 

Yesterday I was trying for 8h without results. Thankyou very much if you can help me.

Here the original routine of Lee Mac:

 

;;--------------------=={ Display Field Objects  }==--------------------;;
;;                                                                      ;;
;;  This program enables the user to easily view the object or set of   ;;
;;  objects referenced by a selected Field.                             ;;
;;                                                                      ;;
;;  Upon issuing the command syntax 'fieldobjects' at the AutoCAD       ;;
;;  command-line, the program will prompt the user to select an         ;;
;;  annotation object (Text, MText or Attribute) containing one or      ;;
;;  more field expressions referencing one or more objects in the       ;;
;;  active drawing.                                                     ;;
;;                                                                      ;;
;;  Following a valid selection, the program will enclose the selected  ;;
;;  annotation object containing the field(s) with a green rectangular  ;;
;;  text box, with links to every referenced object, each of which      ;;
;;  is surrounded by a red rectangular bounding box. The size of the    ;;
;;  rectangular frames relative to the enclosed objects is dependent    ;;
;;  on the current zoom level, and will automatically update as the     ;;
;;  user zooms & pans around the drawing area.                      ;;
;;                                                                      ;;
;;  The diagrammatic display is retained until the user clicks the      ;;
;;  mouse or presses any key to exit the program.                       ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2011  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    2011-11-04                                      ;;
;;                                                                      ;;
;;  First release.                                                      ;;
;;----------------------------------------------------------------------;;

(defun c:fieldobjects

    (
        /
        *error*
        _corners->list
        _offsetoutside
        _midpoint
        _inters-box-point
        _outline
        _fieldobjects
        _selectif

        a b c d e f
    )

    (defun *error* ( m ) (redraw) (princ))

    (defun _corners->list ( a b )
        (mapcar
            (function
                (lambda ( a b ) (list (car a) (cadr b)))
            )
            (list a b b a) (list a a b b)
        )
    )

    (defun _offsetoutside ( a b )
        (mapcar
            (function
                (lambda ( a c )
                    (mapcar
                        (function
                            (lambda ( a c ) ((eval a) c b))
                        )
                        a c
                    )
                )
            )
           '((- -) (+ -) (+ +) (- +)) a
        )
    )

    (defun _midpoint ( a b )
        (mapcar
            (function
                (lambda ( a b ) (/ (+ a b) 2.))
            )
            a b
        )
    )

    (defun _inters-box-point ( a b c )
        (vl-some
            (function
                (lambda ( d e ) (inters b c d e))
            )
            a (cons (last a) a)
        )
    )

    (defun _outline ( a b c d e / f g )
        (mapcar
            (function
                (lambda ( a b ) (grdraw a b e 1))
            )
            a (cons (last a) a)
        )
        (if
            (and c
                (setq f (_inters-box-point a b d))
                (setq g (_inters-box-point c d b))
            )
            (grdraw f g 2 1)
        )
    )

    (defun _fieldobjects ( e / _getfieldobjects )

        (defun _getfieldobjects ( a )
            (apply 'append
                (mapcar
                   '(lambda ( a )
                        (if (= 360 (car a))
                            (_getfieldobjects (cdr a))
                            (if (= 331 (car a)) (list (cdr a)))
                        )
                    )
                    (entget a)
                )
            )
        )
        
        (if (and (wcmatch  (cdr (assoc 0 (setq e (entget e)))) "TEXT,MTEXT,ATTRIB")
                 (setq e (cdr (assoc 360 e)))
                 (setq e (dictsearch e "acad_field"))
                 (setq e (dictsearch (cdr (assoc -1 e)) "text"))
            )
            (_getfieldobjects (cdr (assoc -1 e)))
        )
    )

    (defun _selectif ( a b / c d ) (setq b (eval b))
        (while
            (progn (setvar 'errno 0) (setq c (car (nentsel a)))
                (cond
                    (   (= 7 (getvar 'errno))
                        (princ "\nMissed, try again.")
                    )
                    (   (null c) nil)
                    (   (not (setq d (b c))) (princ "\nInvalid object."))
                )
            )
        )
        (if c (cons c d))
    )

    (if
        (setq a
            (mapcar
                (function
                    (lambda ( a )
                        (vla-getboundingbox (vlax-ename->vla-object a) 'b 'c)
                        (setq b (vlax-safearray->list b)
                              c (vlax-safearray->list c)
                        )
                        (list (_corners->list b c) (_midpoint b c))
                    )
                )
                (_selectif "\nSelect field: " '_fieldobjects)
            )
        )
        (progn
            (princ "\nPress any key to exit...")
            (while (= 5 (car (setq b (grread t 9))))
                (redraw)
                (_outline
                    (setq c (cadar a)
                          f (/ (getvar 'viewsize) 50.0)
                          d (_offsetoutside (caar a) f)
                    )
                    nil nil nil 3
                )
                (foreach e (cdr a)
                    (_outline (_offsetoutside (car e) f) (cadr e) d c 1)
                )
            )
        )
    )
    (redraw) (princ)
)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

ELEVATION.dwg

Edited by SLW210
Added Code Tags!!
Posted

Please place code in code tags (the <> in the editor).

Posted

A very quick look you need pick block A that gets 2 things the Y value of the block and the attribute value. Pick other blocks and add a field that is a formula B-Y value - A-Y value + att value. 

 

You can make fields with say get Y value and copy the code produced to notepad then make the formula then set the field string into the attribute.

 

Wiil add to To do list some one else may jump in sooner.

 

Y block B
%<\AcObjProp Object(%<\_ObjId 1707320608>%).InsertionPoint \f "%pt2">%
Y block a
%<\AcObjProp Object(%<\_ObjId 1707364708>%).InsertionPoint \f "%pt2">%

 

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...