Author Topic: Flip Attribute  (Read 3289 times)

0 Members and 1 Guest are viewing this topic.

debgun

  • Guest
Flip Attribute
« on: August 05, 2010, 05:27:34 PM »
I thought this would be a simple task for me, but apparently not.  I need some help with mirroring an attribute.  When I insert the neutral wire numbers it inserts on the wrong side of the ladder.  Here is my logical steps to solve this problem.
  1. Select all "WD_WCH" blocks
  2. Get attribute "WIRECOPY"
  3. Get attribute's insertion point
  4. If the x = 6.63 or 13.63 then mirror block

I started FlipNum, but AutoCAD chokes on the "vla-get-insertionpoint" for the attribute.  I've been flipping through the help manuals, but I'm getting lost.

Any suggestions?
Code: [Select]
[color=blue](defun FlipNum (/ ss i ent obj attributes x y)
  (vl-load-com)
  (setq ss (ssget "X" '((0 . "INSERT") (2 . "WD_WCH")))
i -1)
  (if ss
    (while (setq ent (ssname ss (setq i (1+ i))))
      (setq x (cadr (assoc 10 (entget ent)))
    y (caddr (assoc 10 (entget ent))))
      (if (and
    (setq obj (vlax-ename->vla-object ent))
    (= (vla-get-objectname obj) "AcDbBlockReference")
    (= (vla-get-hasattributes obj) :vlax-true)
  )
(progn
  (setq attributes (vlax-invoke obj 'getattributes))
  (foreach att attributes
    (if (= "WIRECOPY" (vla-get-tagstring att))
      (if (or
    (= (cadr (vla-get-insertionpoint att)) 6.63)
    (= (cadr (vla-get-insertionpoint att)) 13.63)
  )
(progn
  (vla-mirror att (x , y), (0 , 90))
  (vla-delete)
) ;progn
      ) ;if
     ) ;if
    ) ;foreach
  ) ;progn
) ;if
      ) ;while
    ) ;if
  ) ;close function[/color]

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Flip Attribute
« Reply #1 on: August 05, 2010, 05:38:48 PM »
Not sure that I completely understand, but:

Code: [Select]
(defun c:FlipNum ( / i ss e a p )
  (vl-load-com)

  (if (setq i -1 ss (ssget "_X" '((0 . "INSERT") (2 . "WD_WCH") (66 . 1))))
       
    (while (setq e (ssname ss (setq i (1+ i))))
     
      (foreach a (vlax-invoke (vlax-ename->vla-object e) 'GetAttributes)
        (setq p (vlax-get a 'InsertionPoint))
       
        (if (and (eq "WIRECOPY" (strcase (vla-get-TagString a)))
                 (vl-some '(lambda ( x ) (equal x (cadr p) 0.001)) '(6.63 13.63)))
          (vla-put-rotation a (+ (vla-get-rotation a) pi))
        )
      )
    )
  )

  (princ)
)
       
 
 

Bear in mind that the insertion point property is only valid for those attribs which are left justified, else the textalignmentpoint takes over.

[ EDIT: forgot to check for tag ]
« Last Edit: August 05, 2010, 05:46:39 PM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Flip Attribute
« Reply #2 on: August 05, 2010, 05:49:00 PM »
Oh, and one of the reasons that your code fails is that vla-get-insertionpoint will return a variant, and hence will need to be converted to a safearray and finally a list in order to retrieve the 'Y' coordinate.

Using vlax-get returns a list straight up, so no need for conversion.

You might want to read this also:

http://www.theswamp.org/index.php?topic=31674.0

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Flip Attribute
« Reply #3 on: August 05, 2010, 05:52:26 PM »
Just for completeness, I suppose you don't need to go the whole way and convert to a list (although this is easiest), but you can use the safearray functions:

Code: [Select]
(vlax-safearray-get-element
  (vlax-variant-value
    (vla-get-InsertionPoint <object>)
  )
  1
)

debgun

  • Guest
Re: Flip Attribute
« Reply #4 on: August 12, 2010, 08:29:47 PM »
Lee,

Thanks for your help!  I've been busy with a project and wasn't able to digest your information.  I need to mirror the attributes only with x = 6.63 or x = 13.63 rather than rotate.  So added in the following, but with no luck.  I'm getting an error message "error: lisp value has no coercion to VARIANT with this type: (13.63 5.8154 0.0)".

Code: [Select]
(vla-mirror attribute pt '(x secpt 0))
I found the syntax for the function "(vla-Mirror obj fpoint spoint)".  Any suggestions?
Thanks,
Debbie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Flip Attribute
« Reply #5 on: August 12, 2010, 08:58:29 PM »
Try this:
(vla-mirror attribute pt (list x secpt 0))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

debgun

  • Guest
Re: Flip Attribute
« Reply #6 on: August 12, 2010, 09:11:48 PM »
Thanks, Cab!  I received the same error message.

LOG Error trace
...............
<1> :ERROR-BREAK
[2] (vla-Mirror #<VLA-OBJECT IAcadAttributeReference2 01467a54> (13.63 5.81549 0.0) (13.63 5.91549 0))
[3] (FOREACH ...)
[4] (FLIPNUM)
<5> :CALLBACK-ENTRY
<6> :ARQ-SUBR-CALLBACK

Code: [Select]
(defun FlipNum (/ ss i ent obj attribute x y)
  (vl-load-com)
  (if (setq i -1 ss (ssget "_X" '((0 . "INSERT") (2 . "WD_WCH") (66 . 1))))
    (while (setq ent (ssname ss (setq i (1+ i))))
  (foreach attribute (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes)
    (setq pt (vlax-get attribute 'InsertionPoint)
  x (car pt)
  y (cadr pt)
  y2 (+ y 0.1))
  ;secpt '(x y2 0.0))
    (if (= "WIRECOPY" (vla-get-tagstring attribute))
      (if (or
    (= x 6.63)
    (= x 13.63)
  )
        (vla-mirror attribute pt (list x y2 0))
)
     )

  )
      ) ;while
 ) ;if
) ;close function

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Flip Attribute
« Reply #7 on: August 12, 2010, 11:08:04 PM »
Off to bed but here is another:
Code: [Select]
(vla-mirror attribute (vlax-3d-point pt) (vlax-3d-point (list x y2 0)))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: Flip Attribute
« Reply #8 on: August 13, 2010, 03:18:43 AM »
Would it perhaps be easier to mirror the attributes in the block definition (using Block Editor), then attsync all your blocks (I think that attsyncing one block updates all blocks with the same name, as an addded bonus)?

dJE
===
dJE

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Flip Attribute
« Reply #9 on: August 14, 2010, 09:03:05 AM »
Something like this?

Code: [Select]
(defun c:FlipNum ( / i ss e a p )
  (vl-load-com)

  (if (setq i -1 ss (ssget "_X" '((0 . "INSERT") (2 . "WD_WCH") (66 . 1))))
       
    (while (setq e (ssname ss (setq i (1+ i))))
     
      (foreach a (vlax-invoke (vlax-ename->vla-object e) 'GetAttributes)
        (setq p (vlax-get a 'InsertionPoint))
       
        (if (and (eq "WIRECOPY" (strcase (vla-get-TagString a)))
                 (vl-some '(lambda ( x ) (equal x (cadr p) 0.001)) '(6.63 13.63)))
          (vla-mirror a (vlax-3D-point p) (vlax-3D-point (polar p (/ pi 2.) 1.)))
        )
      )
    )
  )

  (princ)
)

debgun

  • Guest
Re: Flip Attribute
« Reply #10 on: August 14, 2010, 09:50:32 PM »
No luck, yet!  I've attached the drawing.  I didn't receive an error message, but nothing happened either.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Flip Attribute
« Reply #11 on: August 14, 2010, 10:52:12 PM »
Just a guess but perhaps a REGEN is needed to see the change. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

debgun

  • Guest
Re: Flip Attribute
« Reply #12 on: August 16, 2010, 04:09:56 PM »
Thanks, CAB!  I tried that, but no luck.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Flip Attribute
« Reply #13 on: August 16, 2010, 05:43:34 PM »
Debbie, unless the IF statement is not being fulfilled, there isn't too much that can go wrong with my code... Are the testing conditions that I am using correct?