TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: kruuger on April 30, 2011, 07:45:16 PM

Title: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: kruuger on April 30, 2011, 07:45:16 PM
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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: CAB on April 30, 2011, 09:26:32 PM
Have a look at these post by Gile
Block UCS (http://www.theswamp.org/index.php?action=search2;params=YWR2YW5jZWR8J3wxfCJ8dXNlcnNwZWN8J3xnaWxlfCJ8YnJkfCd8MnwifHNob3dfY29tcGxldGV8J3x8InxzdWJqZWN0X29ubHl8J3x8Inxzb3J0X2RpcnwnfGRlc2N8Inxzb3J0fCd8cmVsZXZhbmNlfCJ8c2VhcmNofCd8YmxvY2sgdWNzIA==)
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: Lee Mac on May 01, 2011, 06:50:34 AM
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.
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: kruuger on May 01, 2011, 09:12:59 AM
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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: Lee Mac on May 01, 2011, 09:49:58 AM
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?
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: kruuger on May 01, 2011, 01:48:36 PM
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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: Lee Mac on May 01, 2011, 02:24:09 PM
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.
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: kruuger on May 01, 2011, 02:52:47 PM
.... 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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: Lee Mac on May 01, 2011, 02:56:47 PM
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.
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: kruuger on May 01, 2011, 03:07:02 PM
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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: Lee Mac on May 01, 2011, 04:09:53 PM
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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: kruuger on May 01, 2011, 04:33:17 PM
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
Title: Re: How to get correct insertion point of attribute inside block (at any ucs) ?
Post by: Lee Mac on May 01, 2011, 04:48:14 PM
You're welome Kruuger  :-)