Change item in Field Expression

Change item in Field Expression

neam
Collaborator Collaborator
2,534 Views
11 Replies
Message 1 of 12

Change item in Field Expression

neam
Collaborator
Collaborator

Hi

How can we update a formula field with the help of Lisp after copying it?

Thank you for your help.

0 Likes
Accepted solutions (1)
2,535 Views
11 Replies
Replies (11)
Message 2 of 12

Sea-Haven
Mentor
Mentor

Not sure about your question.

 

A field in this example is using an object ID so each one is different hence using a Area.lsp.

 

If you want say sq Metres not mm then again its in the field formula adjust in code.

0 Likes
Message 3 of 12

neam
Collaborator
Collaborator

Hi

In the first field, the formula is used as follows:

(Area of polygon 1 * Layer 1 text content)

I want to copy the initial field for the next polygon after selecting new polygon updated copied field:

(Area of polygon 2 * Layer 2 text content)

 

Is this possible by Lisp?

0 Likes
Message 4 of 12

pbejse
Mentor
Mentor

@neam wrote:

..I want to copy the initial field for the next polygon after selecting new polygon updated copied field:

...


In the sample drawing you posted, Both Field1 and Field2 shows the value of the LWPOLYLINE area multiplied by the layer name, but has nothing to do with each other. So i dont get the question.

 

Somehow the way you explain it is similar to how the the Jeremy Bearimy Timeline works. and yes it broke me too. 😄

 

 

0 Likes
Message 5 of 12

neam
Collaborator
Collaborator

I edited field 2 manually.

Please, if possible, this edit should be done by Lisp program:

1- select field 2.

2- select new polygon.

3- update items in field 2 (area and layer name).

😁😁😁

 

0 Likes
Message 6 of 12

pbejse
Mentor
Mentor

@neam wrote:

I edited field 2 manually.

Please, if possible, this edit should be done by Lisp program:

1- select field 2.

2- select new polygon.

3- update items in field 2 (area and layer name).


 

I'm not sure if what you shown on the drawing is what the final product would be

  • Do you really want a line and an MTEXT that's pointing to the polyline?
  • Does that mean copy the Mtext, create a line  and update MTEXT string value?.
  • Are you planning to replace the label "5-4-3" with attributed blocks and will that be where the filed values would go that is connected to a datalink table?

 

 

0 Likes
Message 7 of 12

neam
Collaborator
Collaborator

omg 😢😢

  • Do you really want a line and an MTEXT that's pointing to the polyline?
  • answer: NO
  • Does that mean copy the Mtext, create a line  and update MTEXT string value?.
  • answer: NO
  • Are you planning to replace the label "5-4-3" with attributed blocks and will that be where the filed values would go that is connected to a datalink table?
  • answer: NO

I create one field for one polygon.

copy this field to others polygons.

Updated copied fields by click on polygon.

 

0 Likes
Message 8 of 12

pbejse
Mentor
Mentor

@neam wrote:

omg 😢😢

  • Does that mean copy the Mtext, create a line  and update MTEXT string value?.
  • answer: NO

I create one field for one polygon.

copy this field to others polygons.

Updated copied fields by click on polygon.


The answer is YES to that question, other wise there would be nothing to update. The reason i'm asking this is to know if the program also needs to include the creation of the LINES/MTEXT as the user pick a polygon.

 

 

0 Likes
Message 9 of 12

neam
Collaborator
Collaborator

Thank you for understanding what I mean by my poor English.

In response to the second part of your post, we must say that it will be great.

0 Likes
Message 10 of 12

pbejse
Mentor
Mentor
Accepted solution

Here's a simple demo

(Defun c:demo ( / lw p1 p2 _LWArea LW_ID mt )
(if
  (and
	(setq LW  (ssget "_+.:S:E:L" '((0 . "LWPOLYLINE")(8 . "##,###"))))
	(setq p1 (getpoint "\nPick target point"))
	(setq p2 (getpoint p1 "\nText Location"))
	)
    (progn
      (setq LW_ID (itoa (vla-get-ObjectID (setq ev (vlax-ename->vla-object (ssname LW 0))))))
      
      (setq _LWArea     
                    (strcat
                        "%<\\AcObjProp Object(%<\\_ObjId " LW_ID
                        ">%).Area>%")
                   )
	(setq str
		      (strcat "%<\\AcExpr "
			      "(("
			      _LWArea ")*"
			      (vla-get-layer ev) 
			      ") \\f \"%lu2%pr2\">%"
		      )
	       )
        (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)))
      	(setq mt (entmakex (list (cons 0 "MTEXT")         
                  (cons 100 "AcDbEntity")
                  (cons 100 "AcDbMText")
                  (cons 10 p2)
                  (cons 1 "X")))
	    )
        (vla-put-textstring (vlax-ename->vla-object mt) str)
		  )
      )
(princ)
)

HTH

Message 11 of 12

neam
Collaborator
Collaborator

thank you very much

That's absolutely right

😀😀😀

0 Likes
Message 12 of 12

pbejse
Mentor
Mentor

@neam wrote:

thank you very much


Good for you @neam, glad i could help