Move Attribute after insert.

Move Attribute after insert.

Strydaris2492
Advocate Advocate
1,749 Views
24 Replies
Message 1 of 25

Move Attribute after insert.

Strydaris2492
Advocate
Advocate

Afternoon everyone,

 

Hopefully someone can help me out with this.

 

I have a snippet of code that I found somewhere. Props to whomever made it and I wish I kept the location and person that posted it. What it does, is it allows me to move the attribute after the block is inserted into the drawing. 

This is the part that is in my main LISP to insert the block then invoke the function.

     (cond
	(
	 (setq blk (vlax-invoke
		      (vlax-get
			 (vla-get-ActiveLayout
			    (vla-get-activedocument
			       (vlax-get-acad-object)))
			 'Block)
		      'InsertBlock  ptcrv
		      blk2 1 1 1 ang))
	 (setq atb  (Car (vlax-invoke blk 'Getattributes)))
	 (vla-put-textstring atb (strcat hgtnew " HP"))
	 (princ "\n<< Pick point for text location >>")
	 (_NextTrick (trans (vlax-get atb 'TextAlignmentPoint) 0 1) atb)
	 (setq inserted (cons blk2 inserted)
	       )
	 )
	(
	 (and (setq str (eq (type ptcrv) 'STR))(eq ptcrv "U") inserted)
	 (vla-delete (car inserted))
	 (setq inserted (Cdr inserted)
	       counter (1- counter))
	 )
	(str (princ "\nNothing to UNDO"))
	)

 

Below is the subfunction that allows me to move the object.

  (defun _NextTrick  (pt obj / end code pt2)
      (while
            (and (null end)
                 (setq p    (grread t 15 0)
                       code (car p)))
                 (cond
                       ((= 5 code)
                        (vlax-put
                              obj
                              'TextAlignmentPoint
                              (setq pt2 (trans (cadr p) 1 0)))
                        (setq pt pt2)
                        )
                       ((or (= 2 code) (= code 3))
                        (setq end T)))
                 )
      );defun

 

What I am looking to do is modify this so that instead of using the text alignment to grab the text, I would like to use a dynamic block point to move parameter.

I know the area to edit is probably the 'TextAlignmentPoint to something else, but I dont understand where the 'TextAlignmentPoint comes from.

Also I cant seem to find much info on  the VLAX-GET/VLAX-PUT function and how to use it/them.

Can anyone help out?

0 Likes
Accepted solutions (1)
1,750 Views
24 Replies
Replies (24)
Message 21 of 25

komondormrex
Mentor
Mentor

well, considering that block inserted is 'blk and having got dyn props from 'blk by number 2 and 3 for x pos and y pos respectively, you may use following '_nexttrick function for moving your attribute by point to move parameter. use 'trans if needed..

(defun _NextTrick  (blk / end code pt2)
      (while
            (and (null end)
                 (setq p    (grread t 15 0)
                       code (car p)))
                 (cond
                       ((= 5 code)
                        (vla-put-value (nth 2 (vlax-invoke blk 'getdynamicblockproperties))
					(car (mapcar '- (cadr p) (vlax-get blk 'insertionpoint)))
			)
			(vla-put-value (nth 3 (vlax-invoke blk 'getdynamicblockproperties))
					(cadr (mapcar '- (cadr p) (vlax-get blk 'insertionpoint)))
			)
                        )
                       ((or (= 2 code) (= code 3))
                        (setq end T)))
                 )
      )

 

0 Likes
Message 22 of 25

Strydaris2492
Advocate
Advocate

@komondormrex 

Holy SMOKES!!!

Komo, you are a god!

So now the only issue I have is the direction of the block when moving the cursor

Basically the issue now is if the inserted block is anything but 0 degrees, this happens

Strydaris2492_0-1695057634616.png

Any idea on why that might be happening?

0 Likes
Message 23 of 25

komondormrex
Mentor
Mentor

needs to calculate proper move point coordinates for other then zero block rotation.

0 Likes
Message 24 of 25

komondormrex
Mentor
Mentor
Accepted solution

gotcha

 

(defun _NextTrick  (blk / end code pt2)
      (while
            (and (null end)
                 (setq p    (grread t 15 0)
                       code (car p)))
                 (cond
                       ((= 5 code)
			(setq hypotenuse (distance (vlax-get blk 'insertionpoint) (cadr p)))  
			(vla-put-value (nth 2 (vlax-invoke blk 'getdynamicblockproperties))
			  		(* -1 hypotenuse (cos (- (angle (cadr p) (vlax-get blk 'insertionpoint))
							      		(vlax-get blk 'rotation)
							   )
						      )
					)
			)
			(vla-put-value (nth 3 (vlax-invoke blk 'getdynamicblockproperties))
			  		(* -1 hypotenuse (sin (- (angle (cadr p) (vlax-get blk 'insertionpoint))
							                (vlax-get blk 'rotation)
						       	   )
						      )
					)
			)
                        )
                       ((or (= 2 code) (= code 3))
                        (setq end T)))
                 )
      )

 

0 Likes
Message 25 of 25

Strydaris2492
Advocate
Advocate
lol You certainly did get me Komo.
I didnt even have time to think about a solution before you came up with it.
Thank you very much.
This is going to help a lot since a lot of the lisps I am creating use this block to do various different calculations and are inserted at various angles and positions.