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

GET AREA AND PUT THE VALUE IN EXISTING MTEXT

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jaimuthu
170 Views, 2 Replies

GET AREA AND PUT THE VALUE IN EXISTING MTEXT

 

 

HOW TO GET THE AREA AND PUT THE VALUE IN EXISTING MTEXT

 

 

 

(defun c:UpdateAreaValue ()
  (vl-load-com)
  (setq layerName "BLOCK1")
  (setq areaText "BLOCK1=")
  
  (setq ss (ssget "X" (list (cons 8 layerName))))
  (if ss
      (progn
        (setq obj (ssname ss 0))
        (if (= (vla-get-ObjectName (vlax-ename->vla-object obj)) "AcDbText")
            (progn
              (setq areaValue "")
              (setq entText (vla-get-TextString (vlax-ename->vla-object obj)))
              (if (vl-string-search areaText entText)
                  (progn
                    (setq areaStart (vl-string-position areaText entText))
                    (setq areaValue (substr entText (+ areaStart (strlen areaText))))
                    (setq areaValue (strcase areaValue))
                  )
              )
              (if (/= areaValue "")
                  (alert (strcat "Area value found: " areaValue))
                  ; Update MText value here
                  ; Replace the following line with code to update the MText entity
                  (alert "Area value not found in MText")
              )
            )
        )
      )
  )
  (princ)
)

 

 

2 REPLIES 2
Message 2 of 3
komondormrex
in reply to: jaimuthu

update existing mtext like in sample dwg.

 

(defun  c:update_area_mtext ()
	(setq pline_mtext_list (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "lwpolyline,mtext"))))))
	      mtext_ename (car (vl-remove-if-not '(lambda (ename) (= "MTEXT" (cdr (assoc 0 (entget ename))))) pline_mtext_list))
	      mtext_string (vla-get-textstring (vlax-ename->vla-object mtext_ename))
	      pline_list (vl-remove mtext_ename pline_mtext_list)
	)  
	(foreach pline pline_list
		(setq pline_area (rtos (vla-get-area (vlax-ename->vla-object pline)) 2 2)
		      pline_layer (cdr (assoc 8 (entget pline)))
		)
	  	(if (setq layer_pos (vl-string-search pline_layer mtext_string)) 
			(progn
			  	(setq equal_pos (vl-string-search "=" mtext_string layer_pos)
				      next_paragraph_pos (vl-string-search "\\P" mtext_string equal_pos)
			        )
			  	(if (null next_paragraph_pos)
				  (setq next_paragraph_pos (+ 2 equal_pos)  
			      	  	mtext_string (strcat (substr mtext_string 1 (+ 2 equal_pos))
						   	     pline_area
					   	     )
			          )
			  	  (setq mtext_string (strcat (substr mtext_string 1 (+ 2 equal_pos))
						   	     pline_area
							     (substr mtext_string next_paragraph_pos)
					   	     )
			          )
			  	)
			)
	  	)
	)
	(vla-put-textstring (vlax-ename->vla-object mtext_ename) mtext_string)
  	(princ)
)

 

Message 3 of 3
jaimuthu
in reply to: komondormrex

great work thanks

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

Post to forums  

Forma Design Contest


AutoCAD Beta