Author Topic: Moving a Block Entity  (Read 3815 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
Moving a Block Entity
« on: January 18, 2016, 07:50:07 AM »
is there a way to access the Geometry Position X Y Z?  I started with entmod and discovered that attributes don't move with the block, but when I change the Geometry properties every thing moves together and this is what I want to happen.

Thanks


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Moving a Block Entity
« Reply #1 on: January 18, 2016, 07:56:57 AM »
To use the same functionality as the property palette does, you use the ActiveX Move method (i.e. vla-Move). You could also use the move command to accomplish the same task. I can't remember if modifying the ActiveX Position property does the same as the Move method or as the entmod function. Too long since I've worked in anger in AutoCAD, never mind AutoLisp.


The reason this happens is because of how AutoCAD saves attributes. They're actually separate entities, just grouped with the block by being those following it and ending with a SEQEND entity. So editing the INSERT entity does not affect the attributes. If you want to stick with using entmod, then you need to modify the ATTRIB entities following the INSERT in the same way.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Moving a Block Entity
« Reply #2 on: January 18, 2016, 08:19:15 AM »

You can do it with (entmod) but it does take some effort.  Non WCS INSERTs and ATTRIButes would be a lot more pain.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ins-move (/ bp mp dp ss i en ed an ad np)
  2.   (initget 1)
  3.   (setq bp (getpoint "\nBase Point:   "))
  4.  
  5.   (initget 1)
  6.   (setq mp (getpoint bp "\nMove Point:   "))
  7.  
  8.   (and (setq ss (ssget '((0 . "INSERT")(66 . 1)(210 0 0 1))))
  9.        (setq i 0)
  10.        (while (setq en (ssname ss i))
  11.               (setq ed (entget en)
  12.                     an (entnext en)
  13.                     ad (entget an))
  14.               (setq dp (mapcar '- mp bp))
  15.               (setq np (mapcar '+ (cdr (assoc 10 ed)) dp))
  16.               (entmod (subst (cons 10 np) (assoc 10 ed) ed))
  17.               (while (= "ATTRIB" (cdr (assoc 0 ad)))
  18.                      (if (and (= 0 (cdr (assoc 72 ad)))
  19.                               (= 0 (cdr (assoc 74 ad))))
  20.                          (entmod (subst (cons 10 (mapcar '+ dp (cdr (assoc 10 ad))))
  21.                                         (assoc 10 ad) ad))
  22.                          (entmod (subst (cons 11 (mapcar '+ dp (cdr (assoc 11 ad))))
  23.                                         (assoc 11 ad) ad)))
  24.                      (setq an (entnext an)
  25.                            ad (entget an)))
  26.               (entupd en)
  27.               (setq i (1+ i))))
  28.   (prin1))

-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Moving a Block Entity
« Reply #3 on: January 18, 2016, 08:39:50 AM »
Non WCS INSERTs and ATTRIButes would be a lot more pain.

Providing the transformation is only a translation, non-WCS INSERTs & ATTRIBs shouldn't cause a problem as all are being displaced by the same vector.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Moving a Block Entity
« Reply #4 on: January 18, 2016, 12:28:50 PM »
Hmm  Thanks !  I'll take a look see.  -David
R12 Dos - A2K

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Moving a Block Entity
« Reply #5 on: January 18, 2016, 03:47:47 PM »
Lee, This is the scenario that I was thinking about.  -David
R12 Dos - A2K

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Moving a Block Entity
« Reply #6 on: January 19, 2016, 01:45:29 AM »
Yep, if you look at the ATTRIB entity's DXF codes: http://www.autodesk.com/techpubs/autocad/acad2000/dxf/attrib_dxf_06.htm


You'll note the code 10 (effectively the text insertion point) is listed as relevant to OCS (Object Coordinate System). I.e. they're in relation to the INSERT's coordinate system (i.e. if it's rotated / mirrored / tilted / scaled / etc.).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Moving a Block Entity
« Reply #7 on: January 19, 2016, 01:30:46 PM »
Lee, This is the scenario that I was thinking about.  -David

The points will still need to be translated from WCS to OCS as Irneb has noted, but this is quite painless:

Code - Auto/Visual Lisp: [Select]
  1. (defun moveblock ( ent vec / enx fun sub )
  2.     (setq fun (lambda ( p )   (trans (mapcar '+ (trans p ent 0) vec) 0 ent))
  3.           sub (lambda ( k l ) (subst (cons k (fun (cdr (assoc k l)))) (assoc k l) l))
  4.           enx (entget ent)
  5.     )
  6.     (entmod (sub 10 enx))
  7.     (if (= 1 (cdr (assoc 66 enx)))
  8.         (while (= "ATTRIB" (cdr (assoc 0 (setq ent (entnext ent) enx (entget ent)))))
  9.             (entmod (sub 10 (sub 11 enx)))
  10.         )
  11.     )
  12. )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / pt1 pt2 sel )
  2.     (if (and (setq sel (ssget "_+.:E:S:L" '((0 . "INSERT"))))
  3.              (setq pt1 (getpoint "\nSpecify base point: "))
  4.              (setq pt2 (getpoint "\nSpecify second point: " pt1))
  5.         )
  6.         (moveblock (ssname sel 0) (trans (mapcar '- pt2 pt1) 1 0 t))
  7.     )
  8.     (princ)
  9. )

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Moving a Block Entity
« Reply #8 on: January 19, 2016, 02:13:22 PM »
... I can't remember if modifying the ActiveX Position property does the same as the Move method or as the entmod function...
Changing the InsertionPoint property of the block reference means the attributes are also repositioned. So this works:
Code - Auto/Visual Lisp: [Select]
  1. (vlax-put (vlax-ename->vla-object (car (entsel))) 'InsertionPoint '(0.0 0.0 0.0))

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Moving a Block Entity
« Reply #9 on: January 20, 2016, 12:17:14 AM »
... I can't remember if modifying the ActiveX Position property does the same as the Move method or as the entmod function...
Changing the InsertionPoint property of the block reference means the attributes are also repositioned. So this works:
Code - Auto/Visual Lisp: [Select]
  1. (vlax-put (vlax-ename->vla-object (car (entsel))) 'InsertionPoint '(0.0 0.0 0.0))
Thanks, I did think that at the back of my mind, just forgot if this was truly the case. AFAIK, that's exactly what happens when you modify a block's insertion point through the properties palette. I.e. no need for individual ATTRIB modifications and coordinate translations.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.