Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using a Formula within a Field

4 REPLIES 4
Reply
Message 1 of 5
brian.wiley
3219 Views, 4 Replies

Using a Formula within a Field

I am currently using a field for my elevation tags. The field reads the y-value of a line and displays the results as the elevation. Our local jurisdiction requires that we list elevations from above grade (A.G.L.) as well as from bottom of base plate. The difference is usually 6"-12".

 

I was wondering if I could create another field that would read the same y-value of a line, but then subtract a predetermined value (6") and display the results.

 

Currently we have to do the math ourselves and this leaves room for errors and is often very tedious.

 

Any assistance is greatly appreciated.

Tags (1)
4 REPLIES 4
Message 2 of 5
M_Hensley
in reply to: brian.wiley

You could make a single cell table with no borders that contains a field referencing the Y value of the line endpoint. Then create a field with a formula that references the table cell - 6.

 

Here's a quick & dirty example.

Message 3 of 5

I don't know if this can help you!

You must define your origin UCS with the good Y value (6" ) and use the code for labeling elevation.

You can explode it if you want do not update the field. ((UCSORG modified)

 

(defun c:level_field ( / AcDoc Space pt_pos obj pt_field htx rtx rtx0)
  (vl-load-com)
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    Space
    (if (= 1 (getvar "CVPORT"))
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
  )
  (initget 8)
  (while (setq pt_pos (getpoint "\nPut a point of level to be quoted: "))
    (cond
      ((null (tblsearch "LAYER" "Label level"))
        (vla-add (vla-get-layers AcDoc) "Label level")
      )
    )
    (vla-addPoint Space (vlax-3d-point (setq pt_pos (trans pt_pos 1 0))))
    (setq obj (vlax-ename->vla-object (entlast)))
    (vlax-put obj 'Layer "Label level")
    (initget 9)
    (setq pt_field (trans (getpoint (trans pt_pos 0 1) "\nPosition of the text?: ") 1 0))
    (cond
      ((and (not htx) (not rtx))
        (initget 6)
        (setq htx (getdist (trans pt_field 0 1) (strcat "\nSpecify the height of the field <" (rtos (getvar "TEXTSIZE")) ">: ")))
        (if htx (setvar "TEXTSIZE" htx))
        (if (not (setq rtx (getorient (trans pt_field 0 1) "\nSpecify the orientation of the field <0.0>: "))) (setq rtx 0.0))
      )
    )
    (setq rtx0 (+ (angle '(0 0 0) (getvar "UCSXDIR")) rtx))
    (mapcar
      '(lambda (lx)
        (apply
          '(lambda (ins_point value_field att_point txt_height dwg_dir name_style name_layer txt_rot / nw_obj)
            (setq nw_obj
              (vla-addMtext Space
                (vlax-3d-point ins_point)
                0.0
                (strcat
                  "{\\fArial|b0|i0|c0|p34;"
                  "%<\\AcExpr (%<\\AcObjProp.16.2 Object(%<\\_ObjId "
                  (itoa (vla-get-ObjectID obj))
                  value_field
                  "-%<\\AcVar ucsorg \\f \"%lu2%pt2\">%) \\f \"%lu2%ps[+ ,]\">%}"
                )
              )
            )
            (mapcar
              '(lambda (pr val)
                (vlax-put nw_obj pr val)
              )
              (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
              (list att_point txt_height dwg_dir ins_point name_style name_layer txt_rot)
            )
          )
          lx
        )
      )
      (list
        (list
          (mapcar '+ pt_field
            (list
              (- (* (getvar "TEXTSIZE") (cos rtx0)) (* (- (* (getvar "TEXTSIZE") 0.5)) (sin rtx0)))
              (+ (* (getvar "TEXTSIZE") (sin rtx0)) (* (- (* (getvar "TEXTSIZE") 0.5)) (cos rtx0)))
              0.0
            )
          )
          ">%).Coordinates \\f \"%lu2%pt2\">%"
          1
          (getvar "TEXTSIZE")
          5
          (getvar "TEXTSTYLE")
          "Label level"
          rtx
        )
      )
    )
    (vlax-invoke Space 'addLeader
      (append pt_pos pt_field)
      (vlax-ename->vla-object (entlast))
      acLineWithArrow
    )
    (vlax-put (vlax-ename->vla-object (entlast)) 'Layer "Label level")
    (vlax-put (vlax-ename->vla-object (entlast)) 'ArrowheadSize (getvar "TEXTSIZE"))
    (initget 8)
  )
  (prin1)
)

 

Message 4 of 5
brian.wiley
in reply to: M_Hensley

Thanks for the input Hensley!

 

While the table cell works great, once I add it to my elevation tag block, I no longer have the ability to modify the cell.

 

Any other suggestions?

Message 5 of 5

Under the "Objects" option in fields there is a Formula Selection. Here, you can place a field (yes, a field within a field, I use these all the time) for your 'y' value and then subtract whatever you like. Ths will update automatically even if the elevation changes. I think that this is the simplest solution to your inquiry.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost