Specify insertion.Set text style,height,etc. to extracted block attribute value.

Specify insertion.Set text style,height,etc. to extracted block attribute value.

desmund08
Contributor Contributor
1,601 Views
8 Replies
Message 1 of 9

Specify insertion.Set text style,height,etc. to extracted block attribute value.

desmund08
Contributor
Contributor

Hi All,

 

Hope you are all doing great!

 

I'm still a beginner in autoLISP and would like to ask for your help on how to add the following  in the code below:

 

  1. Specify the insertion point of the text extracted from a block attribute value which is aligned to the attribute (meaning if the attribute is rotated at 0 degree, the text that will be extracted will be at 0 deg too).
  2.  Set the text style, text justification, text color, text height and text layer to my preference.
  3. A command that is incorporated in the program which changes the text height specified in number 2 and the last text height will remain as is unless it will be changed again.

test.png

 

Thank you very much in advance.

 

Regards,

 

Desmund

 

Below is the code:

 

(defun c:test (/ a b)
 (vl-load-com)
 
 (if (setq a (ssget '((0 . "INSERT") (66 . 1))))

   (progn
     (repeat (setq i (sslength a))

      (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))

      (foreach x (vlax-invoke b 'getattributes)
        (entmake
          (list
            (cons 0 "TEXT")
            (cons 1 (strcat (vla-get-textstring x) ) )
            (cons 10 (vlax-get x 'textalignmentpoint))
            (cons 40 (vla-get-height x))
            (cons 50 (vla-get-rotation x))
          )
          
        )
      )
    )
   )
 )
(princ)
)

 

0 Likes
Accepted solutions (2)
1,602 Views
8 Replies
Replies (8)
Message 2 of 9

pbejse
Mentor
Mentor

@desmund08 wrote:

I'm still a beginner in autoLISP and would like to ask for your help on how to add the following  in the code below:

  1. Specify the insertion point of the text extracted from a block attribute value which is aligned to the attribute (meaning if the attribute is rotated at 0 degree, the text that will be extracted will be at 0 deg too).
  2.  Set the text style, text justification, text color, text height and text layer to my preference.
  3. A command that is incorporated in the program which changes the text height specified in number 2 and the last text height will remain as is unless it will be changed again.

Hello Desmund, welcome to the forum

 

  1. Is it bit tricky, your ssget set mode are for multiple selection, Is the user going to be asked for the position on every selected block? Also if there are more than one attribute? one location prompt per attribute?
  2. Basically all you needed from the attribute properties are the string value and rotation, correct?
  3. Which you already have?

Below is an example on how to clone the attributes into text. I use you r posted code as a starting point

(defun c:test (/ a b data)
 (vl-load-com)
  (if (setq a (ssget '((0 . "INSERT") (66 . 1))))
     (repeat (setq i (sslength a))
        (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
	(foreach x  (vlax-invoke b 'getattributes)
		(setq data (mapcar '(lambda (At)
                                      (vlax-get x at))
                               '("textstring" "InsertionPoint"
                                 "textalignmentpoint" "height"
                                 "rotation" "StyleName" "Layer"))
                  )
	 (entmake
                  (append
                        (list
                              (cons 0 "TEXT"))
                        (mapcar 'cons '(1 10 11 40 50 7 8) data))
	                  )
            )
        )
     )
(princ)
)

Hopefully you can pick it up from here Desmund

 

Message 3 of 9

lena.talkhina
Alumni
Alumni

Welcome to the Autodesk Community @desmund08 !

 

Great to see you here on LISP forum.

Hope you will find a solution soon.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

Message 4 of 9

desmund08
Contributor
Contributor

Hi @pbejse ,

 

Thanks for your time in replying to my concern.

 

1. Is it bit tricky, your ssget set mode are for multiple selection, Is the user going to be asked for the position on every selected block? Also if there are more than one attribute? one location prompt per attribute?

-I only need one block selection for now but it would be a bonus to learn how to do multiple blocks also.

-Yes, i want to be asked to pick the position of each block that i want to extract its data.

-Location prompt per attribute will be a bonus also but for now, I only have one attribute inside a block.

 

2. Basically all you needed from the attribute properties are the string value and rotation, correct?

-Yes, I only need the string value and rotation of the attribute then asks me to specify the insertion point. I only have one attribute per block.

 

Sorry for asking too much. I've been searching on google for any reference on how to do it but I cannot find one. As I'm not a programmer, it's very hard for me to learn autolisp. I just started making lisp by the way.

 

Thank you.

0 Likes
Message 5 of 9

pbejse
Mentor
Mentor

@desmund08 wrote:

-Yes, i want to be asked to pick the position of each block that i want to extract its data.

-Location prompt per attribute will be a bonus also but for now, I only have one attribute inside a block.


Then you are going about it the wrong way, it can be as simple as this.

 

(defun c:test	(/ attr pt data)
    (vl-load-com)
    (if
      (and
	(setq attr (car (nentsel "\nSelect Attribute")))
	(eq (cdr (assoc 0 (setq ent (entget attr)))) "ATTRIB")
	(setq data (mapcar '(lambda (p)
			      (assoc p ent)
			    )
			   '(10 1 11 40 50)
		   )
	)
	(setq pt (getpoint (cdar data) "\nPick point for location"))
      )
       (entmake
	 (append (list (cons 0 "TEXT"))
		 (subst (cons 10 pt) (Car data) data)
	 )
       )
    )
  )

 

 

As you mentioned on your first post.

  • Set the text style, text justification, text color, text height and text layer to my preference.
  • A command that is incorporated in the program which changes the text height specified in number 2 and the last text height will remain as is unless it will be changed again.

 

I'm guesing you will be working on those.

Come back to us if you need help completing the task

 


@desmund08 wrote:

Sorry for asking too much. I've been searching on google for any reference on how to do it but I cannot find one. As I'm not a programmer, it's very hard for me to learn autolisp. I just started making lisp by the way.


Its a good start , good for you 👍

 

 

Message 6 of 9

desmund08
Contributor
Contributor
Accepted solution

 


@pbejse wrote:

@desmund08 wrote:

-Yes, i want to be asked to pick the position of each block that i want to extract its data.

-Location prompt per attribute will be a bonus also but for now, I only have one attribute inside a block.


Then you are going about it the wrong way, it can be as simple as this.

 

 

 

(defun c:test	(/ attr pt data)
    (vl-load-com)
    (if
      (and
	(setq attr (car (nentsel "\nSelect Attribute")))
	(eq (cdr (assoc 0 (setq ent (entget attr)))) "ATTRIB")
	(setq data (mapcar '(lambda (p)
			      (assoc p ent)
			    )
			   '(10 1 11 40 50)
		   )
	)
	(setq pt (getpoint (cdar data) "\nPick point for location"))
      )
       (entmake
	 (append (list (cons 0 "TEXT"))
		 (subst (cons 10 pt) (Car data) data)
	 )
       )
    )
  )

 

 

 

 

As you mentioned on your first post.

  • Set the text style, text justification, text color, text height and text layer to my preference.
  • A command that is incorporated in the program which changes the text height specified in number 2 and the last text height will remain as is unless it will be changed again.

 

I'm guesing you will be working on those.

Come back to us if you need help completing the task

 


@desmund08 wrote:

Sorry for asking too much. I've been searching on google for any reference on how to do it but I cannot find one. As I'm not a programmer, it's very hard for me to learn autolisp. I just started making lisp by the way.


Its a good start , good for you 👍

 

 


Hi @pbejse ,

 

Thanks again for the prompt response. I appreciate it much.

 

Last request,

 

The code above works perfectly but I don't want the attribute to be selected but the block instead.

I will select the block (not the attribute) and produces same output as the code below. Sorry I still don't have much knowledge on autolisp.

0 Likes
Message 7 of 9

pbejse
Mentor
Mentor
Accepted solution
(defun c:test2	(/ ss attr pt data otpye)
    (vl-load-com)
	(if
		(setq ss (ssget  '((0 . "INSERT") (66 . 1))))      
		(repeat (setq i (sslength ss))
			(setq attrb (ssname ss (setq i (1- i))))
		  	(redraw attrb 3)
			(while (not (eq (setq otpye (cdr (assoc 0
					(setq e (entget attrb))))) "SEQEND"))
			       (if (eq "ATTRIB" otpye)
				 	(progn
					  (setq data (mapcar '(lambda (p)
					      (assoc p e) ) '(10 1 11 40 50)))
					  (setq pt (getpoint (cdar data) "\nPick point for location"))
					  (entmake
						 (append (list (cons 0 "TEXT"))
							 (subst (cons 10 pt) (Car data) data)
						 )
					       )
					  )
				 )
			  (setq attrb (entnext attrb))
			  )
		  (redraw (ssname ss i) 4)
		  )
	)
(princ)
)

HTH

Message 8 of 9

desmund08
Contributor
Contributor

Thanks again for your help @pbejse. Hope I can do the rest by myself. Is there any good reference you know to hasten my learning in autolisp?

0 Likes
Message 9 of 9

pbejse
Mentor
Mentor

@desmund08 wrote:

Thanks again for your help @pbejse. Hope I can do the rest by myself. Is there any good reference you know to hasten my learning in autolisp?


 

You are welcome. of course you can, Let us know if you hit a snag, we'll be here to help you.

Learn AutoLISP for AutoCAD productivity  <-- this is where I started.

 

Cheers

0 Likes