Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Move a block instance's attribute relative to block instance's insertion point

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
tom_brabant
1106 Views, 6 Replies

Move a block instance's attribute relative to block instance's insertion point

What is the best way (assuming there is one) to move a block instance's attribute with respect to the block instance's insertion point?

Entmod on the attribute doesn't seem to work, nor did vla-move.

On one set of blocks instances I'll need to move the attributes east, and in another set I'll need to move them west, so redefining is not an option.

I've attached a simple drawing showing "before" and "after". 

6 REPLIES 6
Message 2 of 7
tom_brabant
in reply to: tom_brabant

I think I've got something that wil work with help from            http://www.theswamp.org/index.php?topic=31674.5;wap2

 

(defun thing ()
 (setq e (car (entsel " pick block ")))
 (setq blockOb (vlax-ename->vla-object e)
   attribSetVariant (vla-getAttributes blockOb)
      )
(setq atref (car (gc:VariantToLispData attribSetVariant)));carring is just moving the first attribute, we will want to loop through (gc:VariantToLispData attribSetVariant)
(vla-move atref (vlax-3d-point (list -5.0 -5.0 -5.0)) (vlax-3d-point (list 0.0 0.0 0.0)));WORKS
)
;http://www.theswamp.org/index.php?topic=31674.5;wap2
(defun gc:VariantToLispData (var)
(cond
((= (type var) 'variant)
(gc:VariantToLispData (vlax-variant-value var)))
((= (type var) 'safearray)
(mapcar 'gc:VariantToLispData (vlax-safearray->list var))
)
(T var)
)
)

Message 3 of 7
hmsilva
in reply to: tom_brabant

As a demo

 

(defun c:test (/ ATT OBJ P1 S1)
  (if (and (setq s1 (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1))))
	   (setq p1 (getpoint "\nPick the new Att Insertion Point: "))
      );; and
    (progn
      (setq obj	(vlax-ename->vla-object (ssname s1 0))
	    att	(nth 0 (vlax-invoke obj 'GetAttributes))
      );; setq
      (vla-move att (vla-get-insertionpoint att) (vlax-3D-point p1))
    );; progn
  );; if
  (princ)
)

HTH

Henrique

EESignature

Message 4 of 7
tom_brabant
in reply to: tom_brabant

Thanks for the clean code!
Message 5 of 7
hmsilva
in reply to: tom_brabant

You're welcome, Tom

Henrique

EESignature

Message 6 of 7
Lee_Mac
in reply to: tom_brabant


@tom_brabant wrote:

Entmod on the attribute doesn't seem to work


FWIW, entmod is a viable method - here is an example:

 

(defun c:moveatt ( / att enx ins key )
    (while
        (progn (setvar 'errno 0) (setq att (car (nentsel "\nSelect attribute: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null att) nil)
                (   (/= "ATTRIB" (cdr (assoc 0 (entget att))))
                    (princ "\nSelected object is not an attribute.")
                )
            )
        )
    )
    (if (and (= 'ename (type att))
             (setq ins (getpoint "\nSpecify new insertion point: "))
             (setq enx (entget att))
        )
        (progn
            (if (and (zerop (cdr (assoc 72 enx)))
                     (zerop (cdr (assoc 74 enx)))
                )
                (setq key 10)
                (setq key 11)
            )
            (if (entmod (subst (cons key (trans ins 1 0)) (assoc key enx) enx))
                (entupd att)
            )
        )
    )
    (princ)
)

 

Message 7 of 7
eladmr
in reply to: Lee_Mac

Hello
I need a similar lisp to allow me to select multiple attributes and move them relative to each other in a nearby location.

Can you help me?
Thanks

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost