Author Topic: How to get correct insertion point of attribute inside block (at any ucs) ?  (Read 3403 times)

0 Members and 1 Guest are viewing this topic.

kruuger

  • Swamp Rat
  • Posts: 637
Hello,

like in subject. for now i got this:
Code: [Select]
; ============================================================ ;
; Get block attribute insertion point                          ;
;   En        - object ename                                   ;
;   Tag [STR] - attribute tag                                  ;
; ============================================================ ;
(defun kr:MVP_GetAttributeInsertionPoint (En Tag / EN PT)
  (while
    (and
      (setq EN (entnext (cdr (assoc -1 (entget En)))))
      (setq PT (cdr (assoc 10 (entget EN))))
      (/= Tag (cdr (assoc 2 (entget EN))))
    )
    T
  )
  PT
)
what should be modified to work it any UCS (now return correct point only for WCS)

thanks
kruuger

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Have a look at these post by Gile
Block UCS
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Maybe something along these lines:

Code: [Select]
(defun GetAttribInsertion ( block tag / att elist ) (setq att block tag (strcase tag))
  (while
    (and
      (eq "ATTRIB"
        (cdr
          (assoc 0
            (setq elist
              (entget (setq att (entnext att)))
            )
          )
        )
      )
      (not (eq tag (strcase (cdr (assoc 2 elist)))))
    )
  )
  (if (eq "ATTRIB" (cdr (assoc 0 elist)))
    (trans
      (cdr
        (assoc
          (if
            (and
              (= 0 (cdr (assoc 72 elist)))
              (= 0 (cdr (assoc 73 elist)))
            )
            10 11
          )
          elist
        )
      )
      att 0       
    )
  )
)

Returns a point in WCS if Tag is present.
« Last Edit: May 01, 2011, 10:15:02 AM by Lee Mac »

kruuger

  • Swamp Rat
  • Posts: 637
thank CAB for links. i found this:
http://www.theswamp.org/index.php?topic=26591.msg320739#msg320739
it seams to do the job i want:
Code: [Select]
(TransNested ((kr:MVP_GetAttributeInsertionPoint En Tag) En 1 0))
Lee,
your code return same point as mine ? right ? but your code is more elegant :)

thanks
kruuger

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Lee,
your code return same point as mine ? right ? but your code is more elegant :)

I thought mine would return the insertion point of the attribute in WCS independent of the UCS settings - does it not?

kruuger

  • Swamp Rat
  • Posts: 637
Lee,
your code return same point as mine ? right ? but your code is more elegant :)

I thought mine would return the insertion point of the attribute in WCS independent of the UCS settings - does it not?
Lee your code return the same point as mine (incorect).
as i mentioned before Gile's code works perfect.
See my test function with block.

kruuger

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Kruuger,

I haven't looked at your drawing but from your code I immediately notice you are using a command call to test the point returned. I would remind you that as stated, my code returns a point in WCS, whereas points supplied to a command are affected by the setting of the UCS.

Perhaps use this to test:

Code: [Select]
(defun c:test ( / e p )
  (if
    (and
      (setq e (car (entsel "\nSelect Block: ")))
      (eq "INSERT" (cdr (assoc 0 (entget e))))
      (= 1 (cdr (assoc 66 (entget e))))
      (setq a (getstring "\nSpecify Attribute Tag: "))
      (setq p (GetAttribInsertion e a))
    )
    (entmakex (list (cons 0 "POINT") (cons 10 p)))
  )
  (princ)
)

I believe Gile's code would only be required for entities that make up the block definition (to transform these relative to the selected Insert) - not attributes (as these are already defined relative to the Insert). But maybe I am wrong.

kruuger

  • Swamp Rat
  • Posts: 637
.... whereas points supplied to a command are affected by the setting of the UCS...
aaa....i forgot about that  :ugly:
with entmakex my code also is correct. my mistake  :oops:
thanks for help and explanation

kruuger

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
with entmakex my code also is correct. my mistake  :oops:

I believe your code will be incorrect for Attribs defined in a plane which differs from the WCS plane, since Attribs are defined relative to their OCS and Points relative to the WCS.

kruuger

  • Swamp Rat
  • Posts: 637
with entmakex my code also is correct. my mistake  :oops:

I believe your code will be incorrect for Attribs defined in a plane which differs from the WCS plane, since Attribs are defined relative to their OCS and Points relative to the WCS.
seams to work for me. you can try my sample
kruuger

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
seams to work for me. you can try my sample

It is not correct in my testing - try inserting a block with normal of '(-1. 0. 0.) for example, then try the different codes.

Lee

kruuger

  • Swamp Rat
  • Posts: 637
seams to work for me. you can try my sample

It is not correct in my testing - try inserting a block with normal of '(-1. 0. 0.) for example, then try the different codes.

Lee
now i understood...for me "any ucs" means, 2d ucs like: north , east etc. (no 3d)
my function work only with normal '(0. 0. 1.), yours with any.

thanks for lesson Lee
kruuger

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
You're welome Kruuger  :-)