add text value to a block attibute

add text value to a block attibute

Anonymous
Not applicable
3,735 Views
20 Replies
Message 1 of 21

add text value to a block attibute

Anonymous
Not applicable

I have a block with one attribute and text placed near to it. 

I need to add the text value to the attribute.

 

can anyone help me.

 

text-to-blockattribute.JPG

0 Likes
3,736 Views
20 Replies
Replies (20)
Message 2 of 21

Anonymous
Not applicable

Sorry for any grammatical error, I'm using google to translate.

Could you attach the DWG?

 

 

 

Júnior Nogueira.

Por favor,  Aceitar como Solução se meu post te ajudar.

Please Accept as Solution if my post helps you.

0 Likes
Message 3 of 21

jaggisingh003
Advocate
Advocate

CAN U EXPLAIN BRIFLY WHAT U WANT TO DO ?

 

 

Sorry for my bad English

0 Likes
Message 4 of 21

john.uhden
Mentor
Mentor

Do you want to concatenate the text string to the attribute string, or replace the attribute string with the text string?

If concatenating, do you want a space or some other character(s) between them?

Do you want to erase the text entity?

John F. Uhden

0 Likes
Message 5 of 21

Anonymous
Not applicable

I want to the nearby text as an attribute value

DWG attached

0 Likes
Message 6 of 21

Anonymous
Not applicable

replace the attribute value.

0 Likes
Message 7 of 21

Anonymous
Not applicable

@Anonymous

Were these blocks added manually or did you use a LISP for this?

 

 

 

 

Júnior Nogueira.

Por favor,  Aceitar como Solução se meu post te ajudar.

Please Accept as Solution if my post helps you.

0 Likes
Message 8 of 21

Anonymous
Not applicable

manually.

0 Likes
Message 9 of 21

Anonymous
Not applicable

is there any possible way to do this.

0 Likes
Message 10 of 21

john.uhden
Mentor
Mentor
Probably.

John F. Uhden

0 Likes
Message 11 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

is there any possible way to do this.


Yes, there is a way, But i don't think the drawing sample you posted is anything like the actual drawing file you are trying to fix, all entities are in layer "0". 

 

Post a more realistic drawing if you please.

 

 

0 Likes
Message 12 of 21

Anonymous
Not applicable

The actual drawing file is very huge with 1.4 million sqm having 144.5km of roads. we have 4 to 6 block points across the road in every 10m.

 

Its not possible to upload this file. 

 

All these block points are in one layer and the text in another layer.

 

I can provide u with all the information you need.

 

It takes a long time to do this manually. if there a possible way to do this quickly it would be very useful.

I hope you can help.

 

0 Likes
Message 13 of 21

john.uhden
Mentor
Mentor
I am having trouble in wondering what difference it makes if all the
entities are on layer 0. What, a few more milliseconds of processing?
There must be other properties to distinguish one entity from the next,
even such as content or position.

John F. Uhden

0 Likes
Message 14 of 21

pbejse
Mentor
Mentor

@john.uhden wrote:
....There must be other properties to distinguish one entity from the next,
even such as content or position.

True, But I would prefer to include the layer name on a filter, plus it's just good practice to use layers in any drawing package.

  

@Anonymous wrote:

The actual drawing file is very huge with 1.4 million sqm   

I am not asking for THE file but only something similar.

  

@Anonymous wrote:

 

All these block points are in one layer and the text in another layer. 

That will do. 

0 Likes
Message 15 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

is there any possible way to do this.


One way

 

(Defun c:demo ( / _DXF attrcoll textcoll tfattr attrblk i entity data)
(defun _DXF (d e)(Cdr (Assoc d (entget e))))
  (if
    (and
	;;;	  Select block where value will be stored	;;;
	(setq attrcoll nil textcoll nil
	    bwattr (car (entsel "\nSelect Block: ")))
	(eq "INSERT" (_DXF 0 bwattr))

	;;;	  Select Text object to pair with block       	;;;
	(setq tfattr (car (entsel "\nSelect text: ")))
	(eq "TEXT" (_DXF 0 tfattr))

        ;;;	  Search whole database for  Block/Text/layer	;;;
	(princ "\nSelect objects to process")
	(setq ss (ssget "_X" (apply 'append
		(list

        ;;;	Blocks using 2 filters from selection block	;;;
	;;;	Block name (Assoc 2 ..)				;;;
	;;;	Layer name (Assoc 8 ..)                		;;;
		'((-4 . "<OR")(-4 . "<AND")(0 . "INSERT")(66 . 1))                
		  (list (assoc 2 (entget bwattr))
                        (assoc 8 (entget bwattr)))

        ;;;	Text entity using 1 filter from selected text	;;;
	;;;	Layer name (Assoc 8 ..)                		;;;
	 	'((-4 . "AND>")(-4 . "<AND")(0 . "TEXT"))
	          (list  (assoc 8 (entget tfattr)))				  
	 	'((-4 . "AND>")(-4 . "OR>")))))
						     
	)
      )
	(progn
	;;;	Process selection. gather insertion point	;;;
	(repeat (setq i (sslength ss))
		(setq entity (ssname ss (setq i (1- i))))
		(setq data (list (_DXF 10 entity) entity))
		(if (eq "INSERT" (Cdr (Assoc 0 (entget entity))))
                            
	;;;	 Block attribue collection			;;;
			  	(Setq attrcoll (cons data attrcoll))
                            
	;;;	 Text collection				;;;
			  	(Setq textcoll (cons data textcoll))
			  )
		)

	(Foreach itm attrcoll
        ;;;     Search text ins point nearest the block (itm)	;;;
	(setq from_To (car (vl-sort
			(mapcar '(lambda (to)
			   (list (distance (car itm) (car to))
                                 (_DXF 1 (cadr to)) to )) textcoll)
	                	'(lambda (a b) (< (Car a)(Car b)))) 
	                )
	      )
              
         ;;;	 The text entity closest to the block		;;;
	(setq attrblk (cadr (last from_To))

	;;;	 Remove the current nearest text list		;;;
	           textcoll (vl-remove (last from_To)  textcoll))

	;;;	 Assign the string value to attribute		;;;
              
	(Vla-put-textstring
	      (car (Vlax-invoke (vlax-ename->vla-object (cadr itm))
                         'Getattributes))
	      (cadr from_To))

	;;;	 Delete the processed string entity		;;;
	(entdel attrblk)
	    )
	)
    )
    (princ)
    )

HTH

Message 16 of 21

Anonymous
Not applicable

Hi Mr Bp,

Can you help me to copy length of line or polyline to the block attribute when I select 1 block attribute and 1 line (polyline).

Thank you!

 

 

0 Likes
Message 17 of 21

dlanorh
Advisor
Advisor

Try this snippet

 

(defun c:len2att ( / lu lp att lin len)
(vl-load-com)
  (setq lu (getvar 'lunits)
        lp (getvar 'luprec)
        att (vlax-ename->vla-object (car (nentsel "Select Attribute : ")))
        lin (car (entsel "Select Line/Polyline : "))
        len (rtos (vlax-curve-getdistatparam lin (vlax-curve-getendparam lin)) lu lp)
  );end_setq
  (vlax-put-property att 'textstring len)
);end_defun

 

It should work with a Lines, All Polylines, Arcs, Ellipses, Circles (perimeter), Splines

I am not one of the robots you're looking for

Message 18 of 21

Anonymous
Not applicable

Thanks for your help!

I have a same lisp 🙂

;_____01/03/2020 by Luongnguyen________;
(defun Ltron ( n )
    (fix (+ n (if (minusp n) -0.3 0.3)))
)
(defun Length1(To) (vlax-curve-getDistAtParam To (vlax-curve-getEndParam To)))
;-----------------------------------------------------------------------------------;
(defun c:Ta (/ st e ss L na str ten)
(setq  ob (ssget '((0 . "INSERT,LINE,POLYLINE,LWPOLYLINE"))))
(setq i 0)
(repeat 2
    (setq Ten (cdr(assoc 0 (entget (ssname ob i)))))
    (if (= Ten "INSERT")
      (Progn
	(setq
           na (ssname ob (- 1 i))
	   L (Ltron (length1 na))
           str (itoa L)
	)
 ; Find ATT with "CD" TAG to copy length of line
	(setq ss (ssdel (ssname ob (- 1 i)) ob ))    
	   ((lambda (j / sn)
	      (while (setq sn (ssname ss (setq j (1+ j))))
	        (mapcar
	          '(lambda (x)
	             (if (eq (strcase (vla-get-tagstring x)) "CD")
	               (vla-put-textstring x str)))
	          (vlax-invoke
	            (vlax-ename->vla-object sn)
	            'getattributes))
	        ))
	   -1)	
      )
      (setq i (1+ i))
     )
   )          
 (princ)
 )
(vl-load-com)

 

 

 

 

 

 

 

0 Likes
Message 19 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

Thanks for your help!

I have a same lisp 🙂


 

And so... did it work for you ? are you looking for help? what of @dlanorh  suggestion. Hows the code posted there working for you?

 

 

Message 20 of 21

john.uhden
Mentor
Mentor
You don't need a program for that.
Just list the polyline, copy its length value from the screen, and paste it
into the attribute editor.

John F. Uhden

0 Likes