Copy the With Factor of text from one attributive block to onother one

Copy the With Factor of text from one attributive block to onother one

eakos1
Advocate Advocate
1,381 Views
19 Replies
Message 1 of 20

Copy the With Factor of text from one attributive block to onother one

eakos1
Advocate
Advocate

Hello,

 

we have usually more headers in one drawings. To save the time to fill all one by one I've created a lisp to do it. 

I could manage it - the program is working for content. I used the getpropertyvalue and setpropertyvalue. 

Sometimes the name is too long - in this case we setup the with factor of text less than 1 by Text Option. 

Is it possible somehow to read and setup this With Factor? 

 

eakos1_0-1628407039731.png

eakos1_1-1628407066160.png

 

Thanks

 

0 Likes
Accepted solutions (2)
1,382 Views
19 Replies
Replies (19)
Message 2 of 20

pbejse
Mentor
Mentor

@eakos1 wrote:

we have usually more headers in one drawings. To save the time to fill all one by one I've created a lisp to do it. 

I could manage it - the program is working for content... 

 

Thanks


Where is the lisp?. we will just modify that to tackle with width issue.

If possible, post a drawing sample.

 

 

0 Likes
Message 3 of 20

eakos1
Advocate
Advocate

Hello,

 

here is the code and the dwg

 

		    ;Created by Ákos Erdélyi
		    ;This program can take the contant of the selected Company_Header
		    ;and put into the other Headers which are available in the drawing


		    ;v00: 2021.05.03
-------------------------------------------------
		    ;:v01: 2021.05.05
		    ;write the customer number into the JSS label too
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
(defun C:HEADER	(/ *error* s sslen nameMasterEntity dataMasterEntity nameMasterBlock allHeaderSelection	sslenOther c)

   -----------------------------------------------------------
   (defun c:test (/ *error*)

      (defun *error* (msg)
	 (if (not
		(member	msg
			'("console break" "Function cancelled" "quit / exit abort")
		)
	     )
	    (princ (strcat "\nError: " msg))
	 )
	 (princ)
      )

      (rtos
	 (getreal "\nPress Esc to exit, press Enter to force an error ..."
	 )
      )
      (princ)
   )
   -----------------------------------------------------------

		    ;select the Master Header
   (vl-load-com)
   (setq s (ssget "_:S+." '((0 . "INSERT") (2 . "Company_Header"))))
   (setq sslen (sslength s)) ;- this is always 1
   (setq nameMasterEntity (ssname s 0))
   (setq dataMasterEntity (entget nameMasterEntity))
   (setq nameMasterBlock (cdr (assoc 2 dataMasterEntity)))
   ------------------------------------------------------------
		    ;Select all other heaters, remove the Master from the selection set
   (setq allHeaderSelection (ssget "x" '((0 . "INSERT") (2 . "Company_Header"))))
   (ssdel nameMasterEntity allHeaderSelection) ;Remove the Master from the list
   (setq sslenOther (sslength allHeaderSelection))

   ------------------------------------------------------------
		    ;read and write the data
   (setq c 0)
   (repeat sslenOther
      (setq HeaderName (ssname allHeaderSelection c))

      (setpropertyvalue
	 HeaderName
	 "DESCRIPTION"
	 (getpropertyvalue nameMasterEntity "DESCRIPTION")
      )
      (setpropertyvalue
	 HeaderName
	 "ITEM"
	 (getpropertyvalue nameMasterEntity "ITEM")
      )
      (setpropertyvalue
	 HeaderName
	 "DRAWING"
	 (getpropertyvalue nameMasterEntity "DRAWING")
      )
      (setpropertyvalue
	 HeaderName
	 "CUSTOMER"
	 (getpropertyvalue nameMasterEntity "CUSTOMER")
      )
      (setpropertyvalue
	 HeaderName
	 "ORIGINATOR"
	 (getpropertyvalue nameMasterEntity "ORIGINATOR")
      )
      (setpropertyvalue
	 HeaderName
	 "DATE_DESIGN"
	 (getpropertyvalue nameMasterEntity "DATE_DESIGN")
      )

      (setq c (1+ c))
   )		    ;end repeat
   ------------------------------------------------------------
		    ;Here will the program the customer number write in the JSS standard lable

   (if
      (setq selectionLable
	      (ssget "x"
		     '((0 . "INSERT") (2 . "5445_PRT-GLO-5113_TAKGEN_Master"))
	      )
      )
	(progn
	   (setq nameLable (ssname selectionLable 0))

	   (setpropertyvalue
	      nameLable
	      "ITEMC"
	      (getpropertyvalue nameMasterEntity "CUSTOMER")
	   )
	   (setpropertyvalue
	      nameLable
	      "CUST_PART_NO"
	      (getpropertyvalue nameMasterEntity "CUSTOMER")
	   )
	)	    ;end progn
   )		    ;end if



   ------------------------------------------------------------
   (princ "\nCreated by Ákos Erdélyi.Thanks for using my program.")

   (princ)
)		    ;end defung

 

 

0 Likes
Message 4 of 20

eakos1
Advocate
Advocate

Here is the header

0 Likes
Message 5 of 20

pbejse
Mentor
Mentor

If i read the program correctly, IT copies the values of these TAGS from the selected block to the rest of the same block names

 

("DESCRIPTION"  "ITEM" "DRAWING" "CUSTOMER" "ORIGINATOR" "DATE_DESIGN")

 

But now you want to include the width (ScaleFactor) yes?

Its just faster if I create new code, After this i will look at your code thoroughly and modify that.

 


(defun C:HEADER ( / TagList AttProp s allHeaderSelection atvSource i f tagValue selectionLable nameLable desCustomer)
  
(setq TagList '("DESCRIPTION"  "ITEM" "DRAWING" "CUSTOMER" "ORIGINATOR" "DATE_DESIGN")
      AttProp '("Tagstring" "Textstring" "ScaleFactor"))
  
	(if (and
		(setq s (ssget "_:S+." '((0 . "INSERT")(66 . 1) (2 . "Company_Header"))))
		(setq allHeaderSelection (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "Company_Header"))))	
	       )
	    (progn
	      (setq atvSource (mapcar '(lambda (at)
			 (mapcar '(lambda (v)
				    (Vlax-get at v)) AttProp
				     )
					 )
		     (Vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'GetAttributes)))      
	      (ssdel (ssname s 0)  allHeaderSelection)
	      
	      (repeat (setq i (sslength allHeaderSelection))
		(foreach itm (Vlax-invoke (vlax-ename->vla-object
					    (ssname allHeaderSelection (setq i (1- i))))
				  			'GetAttributes)
		  (if
		    (and
		      (member (setq tagValue (vla-get-tagstring itm)) TagList)
		      (setq f (assoc tagValue atvSource ))
			)
		    (mapcar '(lambda (prop value)
		      			(Vlax-put itm prop value))
			    	(cdr AttProp) (cdr f)))
		  )
	     )
	      (if
		(And
		    (setq selectionLable
		      (ssget "x"
			     '((0 . "INSERT") (2 . "5445_PRT-GLO-5113_TAKGEN_Master"))
				      )
			      )
		    (setq nameLable (ssname selectionLable 0))
		    (setq desCustomer (cadr (assoc "CUSTOMER" atvSource)))
		    )
			(progn
			  (setpropertyvalue nameLable "ITEMC" desCustomer)
			  (setpropertyvalue nameLable "CUST_PART_NO" desCustomer)
		   	)
		)
		  	 
	   )	
	  )
  (princ)
      )

 

HTH

 

0 Likes
Message 6 of 20

eakos1
Advocate
Advocate

Thanks for helping me. 🙂

This is an label. "5445_PRT-GLO-5113_TAKGEN_Master"

To here only the item number and customer number should be transported. 

"ITEMC"   "CUST_PART_NO"

But her the width factor is not important- it should stay as it is. 

 

By headers problem can happen only by the "DESCRIPTION" so only here is the width factor important. 

By the rest the number of the digits are fix. 

 

I attached the file which contains now the label too. 

0 Likes
Message 7 of 20

pbejse
Mentor
Mentor
Accepted solution

@eakos1 wrote:

By headers problem can happen only by the "DESCRIPTION" so only here is the width factor important. 

By the rest the number of the digits are fix. 


I see, right now it does copy even the width for all the attributes the "Company_Header"block, let me modify the code. is there any particular reason why you're not using Visual lisp funtions? Do you want to stick with vanilla? or are you okay with using VL?

 

Refer to attached lisp file [ HEADER.lsp ]

 

 

0 Likes
Message 8 of 20

Sea-Haven
Mentor
Mentor

This was written for auto layout creation so get lots of layouts with a blank title block, so edit 1 and copy to all the others.

 

; simple update block attribute across all layouts
; By Alan H Nov 2020

(defun c:attall ( / tabs lst x y attnum tabname att bname)

(setq tabs (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))

(setq blk (vlax-ename->vla-object (car (entsel "\nPick title block "))))
(setq atts (vlax-invoke blk 'getattributes))

(setq lst '())
(foreach att atts
(setq lst (cons (vla-get-textstring att) lst))
)
(setq lst (reverse lst))

(setq bname (vla-get-name blk))

(vlax-for lay tabs
  (setq x (vla-get-taborder lay))
  (setq tabname (vla-get-name lay))
  (if  (/= tabname "Model")
    (progn
	(setq attnum -1)
      (setvar "ctab" tabname)
      (IF  (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 410 tabname)(cons 2 bname))))
        (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS 0 )) 'getattributes)
             (vla-put-textstring att (nth (setq attnum (1+ attnum)) lst))
          )
      )
      )
   )
 )


(princ)
)
(c:attall)

 Its a global style routine just copies all attributes as is. 

0 Likes
Message 9 of 20

eakos1
Advocate
Advocate

I tried but this is not working by me

0 Likes
Message 10 of 20

eakos1
Advocate
Advocate

Thank you, it works fine. 🙂

Answering your question I stared programing in AutoLISP not so log time ago and as beginner I could do it this way. Only this is the reason for vanilla. I'm OK with this code.  

0 Likes
Message 11 of 20

pbejse
Mentor
Mentor

@eakos1 wrote:

Thank you, it works fine. 🙂

Answering your question I stared programing in AutoLISP not so log time ago and as beginner I could do it this way. Only this is the reason for vanilla. I'm OK with this code.  


Good for you @eakos1 

I can still post a vanilla version if you want to study it. Just let me know.

 

0 Likes
Message 12 of 20

eakos1
Advocate
Advocate

If you would do it it would be very nice.  Yes, I would be happy if I could study it. 🙂

 

0 Likes
Message 13 of 20

pbejse
Mentor
Mentor

@eakos1 wrote:

If you would do it it would be very nice.  Yes, I would be happy if I could study it. 🙂


Vanilla flavour it is.

 

Weird, regardless of browser/computer/Laptop i use, the "Drag files" does not show to enable me to attached a file, sometimes its there, sometimes NOT. Weird.

 

Is it just me?  Anways. I hope the issue goes away so i can attach the file later. Dont want to clutter the board with codes. It's only going to cause confusion.

 

Later

 

0 Likes
Message 14 of 20

eakos1
Advocate
Advocate

Same issue by me too.

My experience is that if I want to reply then it is not possible to attache a file. 

If I create here a new post I can attache the file. 

0 Likes
Message 15 of 20

pbejse
Mentor
Mentor

@eakos1 wrote:

Same issue by me too.

My experience is that if I want to reply then it is not possible to attache a file. 

If I create here a new post I can attache the file. 


That actually works! Good one @eakos1 

 

HYG.

Refer to attached lisp file [ Vanilla Header.LSP ]

 

0 Likes
Message 16 of 20

eakos1
Advocate
Advocate

Hello, I have to rewrite my program. Until now, we had only one header, but from now on we will have more. 

Its name will be Genthem_header_01,  Genthem_header_02, Genthem_header_03 ........

 

Here is the original code for the selection: at first the sample and all available header in the drawing 

(setq s (ssget "_:S+." '((0 . "INSERT") (66 . 1) (2 . "Gentherm_Header"))))
(setq allHeaderSelection (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "Gentherm_Header"))))

 

The first line I can rewrite, add a * to the name so I can select all header whatever number is at the and

(setq s (ssget "_:S+." '((0 . "INSERT") (66 . 1) (2 . "Gentherm_Header*"))))

 

I stacked by the second line. I have to get the full name of the header. 

(cdr (assoc 2 (entget (ssname s 0))))  result: "Gentherm_Header_01"

If I replace the text it gives an error 

(setq allHeaderSelection (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . (cdr (assoc 2 (entget (ssname s 0)))) ))))

 

Is it possible to read and add the name somehow to the ssget filter?

0 Likes
Message 17 of 20

komondormrex
Mentor
Mentor
Accepted solution

you cannot quote lisp expression.

try it that way

(setq allHeaderSelection (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (cdr (assoc 2 (entget (ssname s 0))))))))

 

0 Likes
Message 18 of 20

eakos1
Advocate
Advocate

unfortunatelly the same result

 

 

eakos1_0-1721415970984.png

 

I tried a variable too but it also not works. 

(setq Header_name (cdr (assoc 2 (entget (ssname s 0)))))
(setq allHeaderSelection (ssget "_X" '((0 . "INSERT") (66 . 1) (cons 2 Header_name) )))

0 Likes
Message 19 of 20

eakos1
Advocate
Advocate

sorry, my first reply was wrong, it works !

0 Likes
Message 20 of 20

john.uhden
Mentor
Mentor

@eakos1 ,

The obvious problem in that snippet is that your are trying to use a quoted list that contains a cons...

(setq allHeaderSelection (ssget "_X" '((0 . "INSERT") (66 . 1) (cons 2 Header_name) )))

should be:

(setq allHeaderSelection (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 Header_name) )))

 

John F. Uhden

0 Likes