Insert Block and directly move attribute

Insert Block and directly move attribute

C.Utzinger
Collaborator Collaborator
2,453 Views
23 Replies
Message 1 of 24

Insert Block and directly move attribute

C.Utzinger
Collaborator
Collaborator

HI

 

Is it possible to insert the attached block and directly move the Attribute with a lispcode?

 

I mean first you select the instertpoint for the block and the the Location Point for the Attribute.

 

 

Please help....

 

0 Likes
Accepted solutions (3)
2,454 Views
23 Replies
Replies (23)
Message 2 of 24

john.uhden
Mentor
Mentor

Yes.

 

Once the insertion is complete, you can get the entity name of the block insertion simply by...

(setq e (entlast)) before you add any other entities to the dwg

If it contains an attribute, then it would be the very next entity...

(setq att (entnext e))

 

Both e and att are 'ENAMEs.  You can modify the att by either...

a)  changing the dxf values within (entget att), or

b)  changing the properties of its corresponding vla-object (vlax-ename->vla-object att)

John F. Uhden

0 Likes
Message 3 of 24

pbejse
Mentor
Mentor

@C.Utzinger wrote:

 


Is it possible to insert the attached block and directly move the Attribute with a lispcode?

 

I mean first you select the instertpoint for the block and the the Location Point for the Attribute. 


It can be as simple as this Cree-G, try this first...

 

 

(defun c:demo ()
      (command "_insert" "SPI-Datenextraktionspunkt-CM")
	(while (> (getvar "CMDACTIVE") 0)
	  (command pause)
	)
      
(sssetfirst nil (ssadd (entlast)))
)

 

The inserted block will be selected and gripped, the attribute definition on your block is NOT lock in position, you can move to wherever it suits you.

 

HTH

 

0 Likes
Message 4 of 24

john.uhden
Mentor
Mentor

That is very simple and clever.  I was thinking that he would want to either already know the desired attribute location or go directly to dragging the attribute from its known location (a total of somewhere between 0 and 2 clicks including the block location)

John F. Uhden

0 Likes
Message 5 of 24

C.Utzinger
Collaborator
Collaborator

HI

 

I'm just back from Holidays.

 

I'm a little lost with this little Problem.

 

I will explain it again. I have a routine, for inserting this block a lot of times with automatically increasing the attribute value.

The Probleme is after inserting 100 Points or more i have to go one by one and move the location of the attribute.

I would prefer to have the possibility to insert the point, directly move the attribute, and continue inserting the next Point, move the next attribute.......

 

 

Thanks in advance for your help.

 

Christian  

0 Likes
Message 6 of 24

pbejse
Mentor
Mentor
Are the new location for the attribute differ with respect to the blocks insertion point?
If so, What are the condions for the new location?
0 Likes
Message 7 of 24

C.Utzinger
Collaborator
Collaborator

HI

 

Yes, the Insertion point for the block don't will change.

The conditions for the new attribute location... Not be over other things, like other text, or lines, etc., so it has to be selected by the user.

 

 

0 Likes
Message 8 of 24

pbejse
Mentor
Mentor
We can write a new code or you can post you're current routine and we will add the capabilty to pause and continue, whats your pleasure?
0 Likes
Message 9 of 24

C.Utzinger
Collaborator
Collaborator

I just got a code in a private message.

It seems to be useful.

I will try this one first and write again if not.

 

Thank you very much.

 

Kind regards

0 Likes
Message 10 of 24

pbejse
Mentor
Mentor

@C.Utzinger wrote:

I just got a code in a private message.

...

I will try this one first and write again if not.

 

 

Kind regards


Okay, It must be from Santa, early Christmas for you Cree-G.

 

Don't leave us hanging buddy, keep us posted.

 

Cheers

 

An offering from Santas' little helper

 

(defun c:demo ( / pt np)
      (setq counter (cond
	((getint (strcat "\nEnter count"
                 (if counter (strcat " <" (itoa counter) ">: ") ": ")
                            )))(counter))
                )
      
      (while (setq pt (getpoint "\nPick point for block location"))
		(setq blk (vlax-invoke
		                (vlax-get
		                      (vla-get-ActiveLayout
		                            (vla-get-activedocument
		                                  (vlax-get-acad-object)))
		                      'Block)
		                'InsertBlock  pt
		                "SPI-Datenextraktionspunkt-CM" 1 1 1 0))

            (foreach itm  (vlax-invoke blk 'Getattributes)
                  (vla-put-textstring itm (itoa counter))
                        (if (setq np (getpoint (vlax-get itm 'TextAlignmentPoint)
                                           "\nPick New Location"))
                            (vlax-put itm 'TextAlignmentPoint np)))
            (setq counter (1+ counter))
            )
      )

MODIFIED to accept default value

Message 11 of 24

john.uhden
Mentor
Mentor
Why should you have to move the attribute? Maybe because it's middle
justified and the number of digits exceeds 2 (like from 99 to 100) so that
it grows to the left?

If that's the case, I suggest you redefine the block using a left-justified
attribute definition. Then when it grows it will always be to the right.

Or if the attribute is to the left of the block, then make it
right-justified.

John F. Uhden

0 Likes
Message 12 of 24

C.Utzinger
Collaborator
Collaborator

HI

 

No no. Our Plans are so full with Information, that a lot of times the text is over other text...

 

 

Kind regards

0 Likes
Message 13 of 24

C.Utzinger
Collaborator
Collaborator

HI

 

I just modified my code, but I don't can make work the undo function...

 

Can you help me?

 

Perhaps you need the hole code? 

 

(if (/= *<test5-g* nil)
 (progn
  (setq *<test5-i* (1+ (:MaxAttValue 
				(cond ((= Binde 1)(strcat *<test5-g* "-"))
				      (T *<test5-g*))))
        *<test5-i* (cond ((getint (strcat "\nPunktnummer angeben <" (itoa *<test5-i*) ">: ")))
                         (*<test5-i*)))

  (setq enlast (entlast))

  (setq MODEL (VLA-GET-MODELSPACE (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))))

  (while (progn
           (initget "Undo")
	   (cond ((= Binde 1)
		  (setq pnt (getpoint (strcat "\nEinfügepunkt angeben für '" (setq txt (strcat *<test5-g* "-" (:AddLeadingZeros (itoa *<test5-i*) AnZiff))) "' [Undo] <exit>: "))))
                 ((= Binde 0)
		  (setq pnt (getpoint (strcat "\nEinfügepunkt angeben für '" (setq txt (strcat *<test5-g* (:AddLeadingZeros (itoa *<test5-i*) AnZiff))) "' [Undo] <exit>: ")))))
           (setq ATTPT (getpoint pnt (strcat "\nTextpostition angeben [Undo] <exit>: ")))
	 )
    (if (= pnt "pnt")
      (progn
        (if (equal enlast (entlast))
          (alert "Alle eingefügten Punkte gelöscht!")
          (progn
            (setq enl (entlast))
            (command "_.UNDO" 1)
            (if (not (equal enl (entlast)))
              (setq *<test5-i* (1- *<test5-i*))))))
      (progn
        (setq BLK-REF (VLA-INSERTBLOCK MODEL (VLAX-3D-POINT pnt) "SPI-Datenextraktionspunkt-CM.dwg" 1.0 1.0 1.0 0.0)
              ATT (CAR (VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE (VLA-GETATTRIBUTES BLK-REF)))))
        (VLA-PUT-INSERTIONPOINT ATT (VLAX-3D-POINT ATTPT))
        (VLA-PUT-TEXTALIGNMENTPOINT ATT (VLAX-3D-POINT ATTPT))
        (VLA-PUT-TEXTSTRING ATT (STRCAT (VLA-GET-TEXTSTRING ATT) txt))
        (setq *<test5-i* (1+ *<test5-i*)))))
))
0 Likes
Message 14 of 24

C.Utzinger
Collaborator
Collaborator

There was an mistake  

 

  (if (= pnt "Undo")

0 Likes
Message 15 of 24

C.Utzinger
Collaborator
Collaborator

OOOHHHHHH

 

I just saw your code....

 

This is much better!!!!!!!!!!!!!!!!!!!!!! I miss only an UNDO function...

 

 

Thank you very much!

0 Likes
Message 16 of 24

ВeekeeCZ
Consultant
Consultant

It's nice to see that you're trying to solve the same issue as I did 10 years ago. Unfortunately as very much newbie not only with LISP but with no programming experience at all as well I made couple very complex routines which none I can post as they are because they are too much complicated (and czech). But maybe for your inspiration... 

 

- if you hit enter <Rucne> you can adjust the position manually. A dynamic affect is achieved using the MOVE command.

- can by used NumLock as well... 5 is the initial position in the middle, the eg. 4 is W, 8 N, 9 is NE etc. see the screen shot.

 

SCREENCAST

 

But as I've said, would be easier to rewrite the code from a scratch then use the old one... 😕

Message 17 of 24

C.Utzinger
Collaborator
Collaborator

I have it now like this.

 

The UNDO part do not work properly :)...

 

 

(if (/= *<test5-g* nil)
 (progn
  (setq *<test5-i* (1+ (:MaxAttValue 
				(cond ((= Binde 1)(strcat *<test5-g* "-"))
				      (T *<test5-g*))))
        *<test5-i* (cond ((getint (strcat "\nPunktnummer angeben <" (itoa *<test5-i*) ">: ")))
                         (*<test5-i*)))

  (setq enlast (entlast))

  (while (progn
           (initget "Undo")
	   (cond ((= Binde 1)(setq pnt (getpoint (strcat "\nEinfügepunkt angeben für '" (setq txt (strcat *<test5-g* "-" (:AddLeadingZeros (itoa *<test5-i*) AnZiff))) "' [Undo] <exit>: "))))
                 ((= Binde 0)(setq pnt (getpoint (strcat "\nEinfügepunkt angeben für '" (setq txt (strcat *<test5-g* (:AddLeadingZeros (itoa *<test5-i*) AnZiff))) "' [Undo] <exit>: "))))))
    (if (= pnt "Undo")
      (progn
        (if (equal enlast (entlast))
          (alert "Alle eingefügten Punkte gelöscht!")
          (progn
            (setq enl (entlast))
            (command "_.UNDO" 1)
            (if (not (equal enl (entlast)))
              (setq *<test5-i* (1- *<test5-i*))))))
      (progn
	  (setq blk (vlax-invoke
		         (vlax-get
		              (vla-get-ActiveLayout
		                   (vla-get-activedocument
		                         (vlax-get-acad-object)))
		                   'Block)
                                   'InsertBlock  pnt
		                "SPI-Datenextraktionspunkt-CM.dwg" 1 1 1 0))

          (foreach itm  (vlax-invoke blk 'Getattributes)
                (vla-put-textstring itm txt)
                      (if (setq np (getpoint (vlax-get itm 'TextAlignmentPoint)
                                         "\nTextposition angeben: "))
                          (vlax-put itm 'TextAlignmentPoint np)))
          (setq *<test5-i* (1+ *<test5-i*))
      )))
))
0 Likes
Message 18 of 24

pbejse
Mentor
Mentor
Accepted solution

Quick mod

 

(defun c:demo ( / pt np blk inserted str)
      (setq counter (cond
	((getint (strcat "\nEnter count"
                 (if counter (strcat " <" (itoa counter) ">: ") ": ")
                            )))(counter))
                )      
      (while
            (progn
                  (initget "U")
                  (setq pt (getpoint "\nPick point for block location/Undo"))

		(cond	
                      (	(eq (type pt) 'LIST)
			(setq blk (vlax-invoke
			                (vlax-get
			                      (vla-get-ActiveLayout
			                            (vla-get-activedocument
			                                  (vlax-get-acad-object)))
			                      'Block)
			                'InsertBlock  pt
			                "SPI-Datenextraktionspunkt-CM" 1 1 1 0))

		            (foreach itm  (vlax-invoke blk 'Getattributes)
		                  (vla-put-textstring itm (itoa counter))
		                        (if (setq np (getpoint (vlax-get itm 'TextAlignmentPoint)
		                                           "\nPick New Location"))
		                            (vlax-put itm 'TextAlignmentPoint np)))
		            (setq inserted (cons blk inserted)
                                  counter (1+ counter))
                       						)
                      (	(and  (setq str (eq (type pt) 'STR))(eq pt "U") inserted)
                       		(vla-delete (car inserted))
                       		(setq inserted (Cdr inserted)
                                      counter (1- counter) )
		                      				)
                      (	str (princ "\nNothjing to UNDO")	)
                      )
	            )
	     	)
      		(princ)
	      )

 

Message 19 of 24

C.Utzinger
Collaborator
Collaborator

Thank you very much!

 

There is just something i'm looking for.

 

When the UCS is different, then it don´t work. Why is that?

 

 

Kind regards...

 

0 Likes
Message 20 of 24

pbejse
Mentor
Mentor
Accepted solution

@C.Utzinger wrote:

Thank you very much!

 

 


You are welcome Christian


@C.Utzinger wrote:

 

When the UCS is different, then it don´t work. Why is that?

 

 


Read about trans and ViewTwist

 

Refer to attached demo lisp [ modified to include trans and viewtwist)

 

HTH