Attribute

Attribute

1b-gzde
Explorer Explorer
877 Views
11 Replies
Message 1 of 12

Attribute

1b-gzde
Explorer
Explorer

Hello. We need a lisp to change every line of a table into attributes. In other words, every line of the table should be a group of attributes. Attribute text must have a designated layer. Attached, you can find the sample file. Does anyone have something like this, or interseted in writing it? Please let me know. Thank you.

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

ВeekeeCZ
Consultant
Consultant

Post the example - say one line - of what the desired result should look like.

0 Likes
Message 3 of 12

1b-gzde
Explorer
Explorer

Screenshot_1.png This is my table

Screenshot_2.png This is how it should be. (Has desired layers and attributes)

Screenshot_3.png This shows all desired attributes. I have also added dwg file to make it clearer.

0 Likes
Message 4 of 12

ВeekeeCZ
Consultant
Consultant

Do these tables/lines always have the same structure? The texts are (their insertion points) always at the same coordinates relative to the line frame? 

 

I mean, what could be done is replace your text line with inserted block "VL_STL_8" and fill up the attributes. 

But if you need to convert ANY line of texts to a newly created block that will match that structure...

0 Likes
Message 5 of 12

1b-gzde
Explorer
Explorer

That is a good point, but it doesn't fully meet our needs. Because what we actually need is make this process faster.

We export the tables from another program (which also means tables have the same structure). And we have a lot of these tables, and want to make every single one attributed. We don't prefer to manually change them, we want to automate the process, if possible. However we don't need something to change every type of text line into attribute. What I posted in my previous post as what we have and what we need is the only type we have. We can use a solution that works with only these tables. Do you think that is possible?

0 Likes
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

@1b-gzde wrote:

That is a good point, but it doesn't fully meet our needs. What exactly does not meet your needs.

Because what we actually need is make this process faster. Faster than what?

We export the tables from another program (which also means tables have the same structure). And we have a lot of these (exactly same structured?) tables, and want to make every single one attributed. We don't prefer to manually change them, we want to automate the process, if possible. However we don't need something to change every type of text line into attribute. ??? What I posted in my previous post as what we have and what we need is the only type we have. We can use a solution that works with only these tables. Do you think that is possible?


 

Just to be clear. What I can do is create a routine that will select all purple plines of the length of 3255.064 units, read all the texts within that pline, insert your predefined block at the upper right corner and fill in the attributes. That's all I can offer. Not going to create a block on the fly. Especially not something as fancy as this block of yours.

0 Likes
Message 7 of 12

1b-gzde
Explorer
Explorer

I meant to say faster than filling attributes by hand, one by one. 

Yes, all the tables have the same structure.

I think, what you offered to do is what we need. 

0 Likes
Message 8 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

OK, here you go. 

You need to fill up the rest of the table, distance (3 decimals) with att name.

Haven't figured out an easy way to distinguish the header from the common lines (it's the same closed purple pline). 

 

(vl-load-com)

(defun c:TextToBLSTL8 ( / d *error* atd atr doc s i e v p w z l b)
  
  (setq d '( ; dist Upper-Left Corner to Text Alignment point
	    (32.690  . "PLANNUMMER")
	    (288.921 . "ARTIKELNUMMER")
	    (883.445 . "ANZ")
	    ))
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if atd (setvar 'attdia atd))
    (if atr (setvar 'attreq atr))
    (if z (command-s "_.zoom" "_p"))
    (vla-endundomark doc)
    (princ))
  
  (if (and (or (tblsearch "block" "BL_STL_8")
	       (alert "Routine Error: The drawing does not contain the 'BL_STL_8' block!"))
	   (princ "\nSelect table common lines,")
	   (setq s (ssget '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1))))
	   (setq atd (getvar 'attdia)) (setvar 'attdia 0)
	   (setq atr (getvar 'attreq)) (setvar 'attreq 0)
	   (not (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
	   (setq z (vl-cmdf "_.zoom" "_e"))
	   )
    
    (repeat (setq i (sslength s))
      (if (and (setq e (ssname s (setq i (1- i))))
	       (equal (getpropertyvalue e "Length") 3255.064 1e-3)
	       (setq v (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e))))
	       (setq p (car v))
	       (setq w (ssget "_WP" v '((0 . "TEXT"))))
	       (setq w (vl-remove-if 'listp (mapcar 'cadr (ssnamex w))))
	       (setq l (mapcar '(lambda (x) (cons (distance p (cdr (assoc 11 (entget x)))) (cdr (assoc 1 (entget x))))) w))
	       (setq l (vl-sort l '(lambda (x1 x2) (< (car x1) (car x2)))))
	       (vl-cmdf "_.insert" "BL_STL_8" "_s" 5 "_r" 0 "_non" p)
	       (setq b (entlast))
	       (entmod (append (entget b) '((8 . "0"))))
	       (entdel e)
	       (mapcar 'entdel w)
	       )
	(foreach e l
	  (foreach f d
	    (and (equal (car e) (car f) 1e-3)
		 (vl-catch-all-apply 'setpropertyvalue (list b (cdr f) (cdr e)))))))))
  (*error* "end")
  )

 

0 Likes
Message 9 of 12

1b-gzde
Explorer
Explorer

That works. Thank you

0 Likes
Message 10 of 12

ВeekeeCZ
Consultant
Consultant

One little upgrade. 

 

* now it replaces all the lines automatically

* header is recognized and preplaced (some differences from the common line block seem... hmm silly. Why different font, why different insertion points, why different alg point?!)

* also fixed that generally used FIT alignment method to be applied only in case it's needed.

 

(vl-load-com)

(defun c:TextToBLSTL8 ( / d *error* :getattents atd atr doc s i e v p w z l b a)
  
  (setq d '( ; dist Upper-Left Corner to Text Alignment point
	    (32.690  . "PLANNUMMER")
	    (288.921 . "ARTIKELNUMMER")
	    (589.820 . "ARTIKELBEZEICHNUNG")
	    (883.445 . "ANZ")
	    ))
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if atd (setvar 'attdia atd))
    (if atr (setvar 'attreq atr))
    (if z (command-s "_.zoom" "_p"))
    (vla-endundomark doc)
    (princ))

  (defun :getattents (e / l)
    (while (and (setq e (entnext e))
		(= (cdr (assoc 0 (entget e))) "ATTRIB")
		(setq l (cons (cons (cdr (assoc 2 (entget e))) e) l))))
    l)
    
  
  (if (and (or (tblsearch "block" "BL_STL_8")
	       (alert "Routine Error: The drawing does not contain the 'BL_STL_8' block!"))
	   ;(princ "\nSelect table common lines <wählen sie alle>")
	   ;(or (setq s (ssget '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1))))
	   ;    (setq s (ssget "_X" '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1)))))
	   (setq s (ssget "_X" '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1))))
	   (setq atd (getvar 'attdia)) (setvar 'attdia 0)
	   (setq atr (getvar 'attreq)) (setvar 'attreq 0)
	   (not (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
	   (setq z (vl-cmdf "_.zoom" "_e"))
	   )
    
    (repeat (setq i (sslength s))
      (if (and (setq e (ssname s (setq i (1- i))))
	       (equal (getpropertyvalue e "Length") 3255.064 1e-3)
	       (setq v (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e))))
	       (setq p (car v))
	       (setq w (ssget "_WP" v '((0 . "TEXT"))))
	       (setq w (vl-remove-if 'listp (mapcar 'cadr (ssnamex w))))
	       (setq l (mapcar '(lambda (x) (list (distance p (cdr (assoc (if (= 0 (getpropertyvalue x "Justify")) 10 11) (entget x))))
						  (cdr (assoc 1 (entget x)))
						  (if (and (= 5 (getpropertyvalue x "Justify"))
							   (< (apply 'distance (textbox (vl-remove-if-not '(lambda (y) (vl-position (car y) '(1 7 40))) (entget x))))
							      (distance (getpropertyvalue x "Position") (getpropertyvalue x "AlignmentPoint"))))
						    0 (getpropertyvalue x "Justify"))))
			       w))
	       (setq l (vl-sort l '(lambda (x1 x2) (< (car x1) (car x2)))))
	       (if (= (cadar l) "Plannummer")
		 (and (or (tblsearch "block" "BL_STL_KOPF_8")
			  (alert "Routine Error: The drawing does not contain the 'BL_STL_KOPF_8' block!\nThe header did not replaced."))
		      (vl-cmdf "_.insert" "BL_STL_KOPF_8" "_s" 5 "_r" 0 "_non" (last v))
		      (setq b (entlast))
		      (entmod (append (entget b) '((8 . "0"))))
		      (mapcar 'entdel (cons e w))
		      nil)
		 T)
	       (vl-cmdf "_.insert" "BL_STL_8" "_s" 5 "_r" 0 "_non" p)
	       (setq b (entlast))
	       (entmod (append (entget b) '((8 . "0"))))
	       (mapcar 'entdel (cons e w))
	       (setq a (:getattents b))
	       )
	(foreach e l
	  (foreach f d
	    (if (equal (car e) (car f) 1e-3)
	      (progn
		(vl-catch-all-apply 'setpropertyvalue (list b (cdr f) (cadr e)))
		(vl-catch-all-apply 'setpropertyvalue (list (cdr (assoc (cdr f) a)) "Justify" (last e)))
		)))))))
  (*error* "end")
  )

 

0 Likes
Message 11 of 12

1b-gzde
Explorer
Explorer

I tried the new version. I uploaded the results. Columns "Einh", "WiLI", "WiRE" comes as default, however they have their own values. Also, it doesn't include these marked columns. Is it possible to add them, too? They sometimes have values. 

You are right about your comments, btw. I completely agree. I don't really know why they come like that. It comes from a 3d software that I am not familiar with.

1bgzde_0-1671808586479.png

Thank you

 

0 Likes
Message 12 of 12

ВeekeeCZ
Consultant
Consultant

@1b-gzde wrote:

I tried the new version. I uploaded the results. Columns "Einh", "WiLI", "WiRE" comes as default, however they have their own values. Also, it doesn't include these marked columns. Is it possible to add them, too? They sometimes have values. 

....

 


 

Sure it is. See my first reply, YOU need to fill the list with all the rest of the attributes. I did just a few to prove the concept and show you the syntax, but the rest is just repetitive task.

0 Likes