Author Topic: Problem with block Entity  (Read 4067 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Problem with block Entity
« on: February 01, 2015, 11:27:30 AM »
Hello everyone,
I attach a file dwg where there is the same block with a different orientation.
In the properties of the scale values XY and Z and rotation are the same for both blocks.
Even the values in (entget) are identical for both blocks.

However, the two blocks in the drawing are oriented in a different way.
The block of red color should be the one with the correct rotation.

Maybe I could fix this, using BATTMAN, however it seems that this command does not exist on the command line.
I also thought about using SYNCATT, but unfortunately this affects all the blocks that have the same name.

I wish I could fix a single block (eg. Selected with (setq obj (car (entsel)))) without affecting the other.

Have you any suggestions?

Thanks in advance.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Problem with block Entity
« Reply #1 on: February 01, 2015, 02:12:40 PM »
Here's a rough draft of a possible program to sychronise the attributes for a single block reference:

Code - Auto/Visual Lisp: [Select]
  1. ;; Attsync Block Reference  -  Lee Mac
  2. ;; Allows the user to synchronise the attributes for a single block reference
  3.  
  4. (defun c:attsyncref ( / def ent enx lst mat obj )
  5.     (while
  6.         (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block to synchronise attributes: ")))
  7.             (cond
  8.                 (   (= 7 (getvar 'errno))
  9.                     (princ "\nMissed, try again.")
  10.                 )
  11.                 (   (null ent) nil)
  12.                 (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  13.                     (princ "\nSelected object is not a block.")
  14.                 )
  15.                 (   (/= 1 (cdr (assoc 66 enx)))
  16.                     (princ "\nSelected block is not attributed.")
  17.                 )
  18.                 (   (setq obj (vlax-ename->vla-object ent)
  19.                           mat
  20.                         (vlax-tmatrix
  21.                             (apply
  22.                                '(lambda ( m v )
  23.                                     (append (mapcar '(lambda ( r v ) (append r (list v))) m v)
  24.                                        '((0.0 0.0 0.0 1.0))
  25.                                     )
  26.                                 )
  27.                                 (refgeom ent)
  28.                             )
  29.                         )
  30.                     )
  31.                     (vlax-for obj
  32.                         (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
  33.                             (if (vlax-property-available-p obj 'effectivename)
  34.                                 (vla-get-effectivename obj)
  35.                                 (vla-get-name obj)
  36.                             )
  37.                         )
  38.                         (if (= "AcDbAttributeDefinition" (vla-get-objectname obj))
  39.                             (setq lst (cons (cons (vla-get-tagstring obj) obj) lst))
  40.                         )
  41.                     )
  42.                     (foreach att (vlax-invoke obj 'getattributes)
  43.                         (if (vlax-write-enabled-p att)
  44.                             (if (setq def (cdr (assoc (vla-get-tagstring att) lst)))
  45.                                 (progn
  46.                                     (foreach prp
  47.                                        '(
  48.                                             alignment
  49.                                             backward
  50.                                             color
  51.                                             height
  52.                                             insertionpoint
  53.                                             invisible
  54.                                             layer
  55.                                             linetype
  56.                                             linetypescale
  57.                                             lineweight
  58.                                             normal
  59.                                             obliqueangle
  60.                                             rotation
  61.                                             scalefactor
  62.                                             stylename
  63.                                             textalignmentpoint
  64.                                             thickness
  65.                                             upsidedown
  66.                                         )
  67.                                         (if
  68.                                             (and
  69.                                                 (vlax-property-available-p def prp)
  70.                                                 (vlax-property-available-p att prp t)
  71.                                             )
  72.                                             (vlax-put-property att prp (vlax-get-property def prp))
  73.                                         )
  74.                                     )
  75.                                     (vla-transformby att mat)
  76.                                 )
  77.                                 (vla-delete att)
  78.                             )
  79.                         )
  80.                     )
  81.                 )
  82.             )
  83.         )
  84.     )
  85.     (princ)
  86. )
  87.  
  88. ;; RefGeom (gile)
  89. ;; Returns a list whose first item is a 3x3 transformation matrix and
  90. ;; second item the object insertion point in its parent (xref, block or space)
  91.  
  92. (defun refgeom ( ent / ang enx mat ocs )
  93.     (setq enx (entget ent)
  94.           ang (cdr (assoc 050 enx))
  95.           ocs (cdr (assoc 210 enx))
  96.     )
  97.     (list
  98.         (setq mat
  99.             (mxm
  100.                 (mapcar '(lambda ( v ) (trans v 0 ocs t))
  101.                    '(
  102.                         (1.0 0.0 0.0)
  103.                         (0.0 1.0 0.0)
  104.                         (0.0 0.0 1.0)
  105.                     )
  106.                 )
  107.                 (mxm
  108.                     (list
  109.                         (list (cos ang) (- (sin ang)) 0.0)
  110.                         (list (sin ang) (cos ang)     0.0)
  111.                        '(0.0 0.0 1.0)
  112.                     )
  113.                     (list
  114.                         (list (cdr (assoc 41 enx)) 0.0 0.0)
  115.                         (list 0.0 (cdr (assoc 42 enx)) 0.0)
  116.                         (list 0.0 0.0 (cdr (assoc 43 enx)))
  117.                     )
  118.                 )
  119.             )
  120.         )
  121.         (mapcar '- (trans (cdr (assoc 10 enx)) ocs 0)
  122.             (mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx))))))
  123.         )
  124.     )
  125. )
  126.  
  127. ;; Matrix Transpose  -  Doug Wilson
  128. ;; Args: m - nxn matrix
  129.  
  130. (defun trp ( m )
  131.     (apply 'mapcar (cons 'list m))
  132. )
  133.  
  134. ;; Matrix x Matrix  -  Vladimir Nesterovsky
  135. ;; Args: m,n - nxn matrices
  136.  
  137. (defun mxm ( m n )
  138.     ((lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n))
  139. )
  140.  
  141. ;; Matrix x Vector  -  Vladimir Nesterovsky
  142. ;; Args: m - nxn matrix, v - vector in R^n
  143.  
  144. (defun mxv ( m v )
  145.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  146. )
  147.  
« Last Edit: February 03, 2015, 10:40:26 AM by Lee Mac »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with block Entity
« Reply #2 on: February 03, 2015, 04:49:00 AM »
@ Lee:
There are two issues with your code:
1.
You code cannot add new attributes but only modify or delete existing ones. The only way to add an attribute, as far as I know, is to create a new block reference.
2.
You are not 'resetting' the attribute before applying the transformation matrix. In most cases an existing attribute will have already been transformed by the matrix from its block reference.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Problem with block Entity
« Reply #3 on: February 03, 2015, 07:54:12 AM »
@ Lee:
There are two issues with your code:
1.
You code cannot add new attributes but only modify or delete existing ones. The only way to add an attribute, as far as I know, is to create a new block reference.
2.
You are not 'resetting' the attribute before applying the transformation matrix. In most cases an existing attribute will have already been transformed by the matrix from its block reference.

Hi Roy,

I agree with your first point as the current code makes no attempt to generate new attribute references, and only deletes those which do not correspond to attribute definitions found in the block definition.

However, I disagree with your second point (unless I've misunderstood the point you are making); the position/scale/rotation of each attribute reference is first set to match that of the corresponding attribute definition before the transformation matrix is applied to position the attribute relative to the block reference. I do see that the ActiveX 'normal' property should be included in the list of properties that are to be reset, to account for blocks in a plane which is not parallel to the WCS plane.

Lee


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with block Entity
« Reply #4 on: February 03, 2015, 10:27:18 AM »
I do see that the ActiveX 'normal' property should be included in the list of properties that are to be reset, to account for blocks in a plane which is not parallel to the WCS plane.
That is what I am referring to in my second point, but I should have qualified the word 'resetting'.

However, if I add this property to the list and test with unequally scaled block references there is still an issue. It seems that a matrix derived from such a block reference cannot be applied to an attribute reference. Note: tested on BricsCAD V14 only.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Problem with block Entity
« Reply #5 on: February 03, 2015, 10:40:03 AM »
I have updated the above code to now include the ActiveX 'normal' property.

However, if I add this property to the list and test with unequally scaled block references there is still an issue. It seems that a matrix derived from such a block reference cannot be applied to an attribute reference. Note: tested on BricsCAD V14 only.

Indeed - this has always been a problem unfortunately: any operations involving the application of transformation matrices using the ActiveX transformby method is restricted to matrices which apply a uniform scaling transformation. Hence, for applications which involve non-uniform transformations (such as my 2D projection program), the matrix operations are applied to the defining coordinates which are then used to construct the new shape.
« Last Edit: February 03, 2015, 10:43:14 AM by Lee Mac »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with block Entity
« Reply #6 on: February 04, 2015, 05:06:39 AM »
Thanks Lee, I did not know about this restriction.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with block Entity
« Reply #7 on: February 05, 2015, 08:41:08 AM »
Here's a rough draft of a possible program to sychronise the attributes for a single block reference:

Sorry for the delay in my response but I have been very busy!
Thank You !!
your code in my context, it works very well !!

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Problem with block Entity
« Reply #8 on: February 05, 2015, 11:26:26 AM »
Here's a rough draft of a possible program to sychronise the attributes for a single block reference:

Sorry for the delay in my response but I have been very busy!
Thank You !!
your code in my context, it works very well !!

Excellent, you're welcome!  :-)