Author Topic: Getting insertion point of block INSIDE another block.  (Read 10102 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting insertion point of block INSIDE another block.
« Reply #15 on: January 09, 2007, 03:12:09 AM »
Quote
This will not work on a scaled, rotated, mirrored, uniform block

You tested it?. it's work with any block insert on drawing (scaled, rotated, mirrored, uniform block)


I just tested it, Luis is correct, it does not work correctly.

... and I am quietly laughing because Andrea still hasn't stated what he wants   :?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Patrick_35

  • Guest
Re: Getting insertion point of block INSIDE another block.
« Reply #16 on: January 09, 2007, 06:00:51 AM »
I don't understand. It's work for me ? :?

I try with this drawing

@+
« Last Edit: January 09, 2007, 06:08:59 AM by Patrick_35 »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Getting insertion point of block INSIDE another block.
« Reply #17 on: January 09, 2007, 07:15:10 AM »
Hi,

I answered to the same question here, in French, in the web site Call me Bert told.

Serais-tu CADy sur Cadxp ?

Here's the code :

Code: [Select]
;;; Nested_coord Retourne une liste dont chaque élément est du type :
;;; (Nom_du_parent Coordonnées_l'enfant_dans_le_parent)
;;;
;;; L'argument est le nom du bloc dont on recherche les coordonnées dans les
;;; blocs dans lequels il est imbriqué (quelque soit le niveau d'imbrication).
;;;
;;; L'exécution du LISP peut prendre un peu de temps si la collection est fournie.

(defun nested_coord (enfant / temp_lst parent ent final_lst)
  ;; Dans un premier temps, la liste est constituée d'un seul élément :
  ;; le nom du bloc enfant et les coordonnées de son point de base.
  (setq temp_lst
(cons
   (cons enfant (cdr (assoc 10 (tblsearch "BLOCK" enfant))))
   temp_lst
)
  )
  ;; On boucle sur chaque élément de la liste pour chercher dans chaque bloc de la table
  ;; si le bloc fait partie de ses composants. Si c'est le cas, le bloc parent est ajouté
  ;; en fin de liste et sera traité à son tour.
  (while temp_lst
    (setq parent (tblnext "BLOCK" T))
    (while parent
      (setq ent (cdr (assoc -2 parent)))
      (while ent
(if (and (= (cdr (assoc 0 (entget ent))) "INSERT")
(= (cdr (assoc 2 (entget ent))) (caar temp_lst))
    )
  ;; Ajout du nouveau bloc "parent" en fin de liste
  ;; Addition des coordonnées du point d'insertion du bloc enfant dans le
  ;; bloc parent et des coordonnées associées au bloc enfant
  (setq temp_lst
(reverse
   (cons
     (cons
       (cdr (assoc 2 parent))
       (mapcar '+
       (cdr (assoc 10 (entget ent)))
       (cdar temp_lst)
       )
     )
     (reverse temp_lst)
   )
)
  )
)
(setq ent (entnext ent))
      )
      (setq parent (tblnext "BLOCK"))
    )
    (setq final_lst (cons (car temp_lst) final_lst)
  temp_lst  (cdr temp_lst)
    )
  )
  ;; Suppression de l'élément "enfant" de la liste
  (reverse (cdr (reverse final_lst)))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:test (/ nest ss n ref r_lst n_lst)
  (setq nest "")
  (while (not (tblsearch "Block" nest))
    (setq nest (getstring "\nEntrez le nom du bloc recherché: "))
  )
  (if (setq ss (ssget "_A" '((0 . "INSERT"))))
    (repeat (setq n (sslength ss))
      (setq ref   (ssname ss (setq n (1- n)))
    r_lst (entget ref)
    n_lst (nested_coord nest)
      )
      (if (assoc (cdr (assoc 2 r_lst)) n_lst)
(progn
  (setq
    c_lst (mapcar
    'cdr
    (vl-remove-if-not
      '(lambda (x) (= (car x) (cdr (assoc 2 r_lst))))
      n_lst
    )
  )
    c_lst (mapcar '(lambda (x)
     (setq x (list
       (* (car x) (cdr (assoc 41 r_lst)))
       (* (cadr x) (cdr (assoc 42 r_lst)))
       (* (caddr x) (cdr (assoc 43 r_lst)))
     )
   x (polar '(0 0 0)
    (+ (angle '(0 0 0) x)
       (cdr (assoc 50 r_lst))
    )
    (distance '(0 0 0) x)
     )
   x (trans (mapcar '+
    (cdr (assoc 10 r_lst))
    x
    )
    ref
    1
     )
     )
   )
  c_lst
  )
  )
  (princ (strcat "\nLe bloc \"" nest "\" imbriqué dans \"" (cdr (assoc 2 r_lst)) "\" est inséré en : "))
  (mapcar 'print c_lst)
)
(prompt (strcat "\nAucune imbrication du bloc \""
nest
"\" dans le bloc \""
(cdr (assoc 2 r_lst))
"\"."
)
)
      )
    )
  )
  (textscr)
  (princ)
)
« Last Edit: January 09, 2007, 01:27:53 PM by gile »
Speaking English as a French Frog

Patrick_35

  • Guest
Re: Getting insertion point of block INSIDE another block.
« Reply #18 on: January 09, 2007, 07:27:45 AM »
Et oui, c'est le même  ^-^

It's more easy to speak french  :roll:

@+

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Getting insertion point of block INSIDE another block.
« Reply #19 on: January 09, 2007, 09:13:20 AM »
Great one Gile, here is the translation:
Although I could not find a translation for Aucne

Code: [Select]
;;  http://www.theswamp.org/index.php?topic=14347.msg173186#msg173186
;;  By Gile 01.09.2007
;;; Nested_coord Turns over a list whose each element is of the type:
;;; (Name_of_parent  Coordinates_l' child_in_the_parent)
;;;
;;; The argument is the name of the block which one seeks the co-ordinates in
;;; blocks in lequels it is overlapping (some is the level of overlap).
;;;
;;; The execution of the LISP can take a little time if the collection is provided.

(defun nested_coord (enfant / temp_lst parent ent final_lst)
  ;; Initially, the list consists of only one element:
  ;; the name of the block child and co-ordinates of his basic point.
  (setq temp_lst
         (cons
           (cons enfant (cdr (assoc 10 (tblsearch "BLOCK" enfant))))
           temp_lst
         )
  )
  ;; One buckles on each element of the list to seek in each block of the table
  ;; if the block forms part of its components. If it is the case, the block relative is added
  ;; at the end of the list and will be treated in its turn.
  (while temp_lst
    (setq parent (tblnext "BLOCK" t))
    (while parent
      (setq ent (cdr (assoc -2 parent)))
      (while ent
        (if (and (= (cdr (assoc 0 (entget ent))) "INSERT")
                 (= (cdr (assoc 2 (entget ent))) (caar temp_lst))
            )
          ;; Addition of the new block "relative" at the end of the list
          ;; Addition of the co-ordinates of the insertion point of the block child in
          ;; block relative and of the co-ordinates associated with the block child
          (setq temp_lst
                 (reverse
                   (cons
                     (cons
                       (cdr (assoc 2 parent))
                       (mapcar '+
                               (cdr (assoc 10 (entget ent)))
                               (cdar temp_lst)
                       )
                     )
                     (reverse temp_lst)
                   )
                 )
          )
        )
        (setq ent (entnext ent))
      )
      (setq parent (tblnext "BLOCK"))
    )
    (setq final_lst (cons (car temp_lst) final_lst)
          temp_lst  (cdr temp_lst)
    )
  )
  ;; Removal of the element "child" of the list
  (reverse (cdr (reverse final_lst)))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:test (/ nest ss n ref r_lst n_lst)
  (setq nest "")
  (while (not (tblsearch "Block" nest))
    (setq nest (getstring "\nEnter the name of the required block: "))
  )
  (if (setq ss (ssget "_A" '((0 . "INSERT"))))
    (repeat (setq n (sslength ss))
      (setq ref   (ssname ss (setq n (1- n)))
            r_lst (entget ref)
            n_lst (nested_coord nest)
      )
      (if (assoc (cdr (assoc 2 r_lst)) n_lst)
        (progn
          (setq
            c_lst (mapcar
                    'cdr
                    (vl-remove-if-not
                      '(lambda (x) (= (car x) (cdr (assoc 2 r_lst))))
                      n_lst
                    )
                  )
            c_lst (mapcar '(lambda (x)
                             (setq x (list
                                       (* (car x) (cdr (assoc 41 r_lst)))
                                       (* (cadr x) (cdr (assoc 42 r_lst)))
                                       (* (caddr x) (cdr (assoc 43 r_lst)))
                                     )
                                   x (polar '(0 0 0)
                                            (+ (angle '(0 0 0) x)
                                               (cdr (assoc 50 r_lst))
                                            )
                                            (distance '(0 0 0) x)
                                     )
                                   x (trans (mapcar '+
                                                    (cdr (assoc 10 r_lst))
                                                    x
                                            )
                                            ref
                                            1
                                     )
                             )
                           )
                          c_lst
                  )
          )
          (princ (strcat "\nThe block \""
                         nest
                         "\" embeded in \""
                         (cdr (assoc 2 r_lst))
                         "\" is inserted in : "
                 )
          )
          (mapcar 'print c_lst)
        )
        (prompt (strcat "\nAucne overlap of the block \""
                        nest
                        "\" in the block \""
                        (cdr (assoc 2 r_lst))
                        "\"."
                )
        )
      )
    )
  )
  (textscr)
  (princ)
)
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.

Tramber

  • Guest
Re: Getting insertion point of block INSIDE another block.
« Reply #20 on: January 09, 2007, 10:02:33 AM »
Although I could not find a translation for Aucne

There's none  :lol:

Because the good spelling is "aucune" and it means "none"  :evil: (aucun or aucune, male or female)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Getting insertion point of block INSIDE another block.
« Reply #21 on: January 09, 2007, 10:14:41 AM »
male or female

Leave it to the French to have male & female versions of words.  :-D
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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Getting insertion point of block INSIDE another block.
« Reply #22 on: January 09, 2007, 11:29:23 AM »
Ouf...!

Exactly what i'm looking for...
What I like when looking in some code....is the explaination
that help me a lot.

Thanks you very much all.

(Oui je suis CADy sur l'autre site car j'ai pas pu m'enregistrer sur AndreaLISP)

One day guys...I promise to surprise you..

Thanks again....and have a good day !
Keep smile...

Tramber

  • Guest
Re: Getting insertion point of block INSIDE another block.
« Reply #23 on: January 09, 2007, 11:34:15 AM »
Leave it to the French to have male & female versions of words.  :-D

Let's play a game :

CAB, do you beleive that AutoCAD is a male or a female ?
(Italian, German and Spanish people can play 'cause they don't give the same gender to things as their european neighbours, but I prefer english and american people to play the game)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting insertion point of block INSIDE another block.
« Reply #24 on: January 09, 2007, 11:40:54 AM »
I have never given Acad a gender, or thought of it with a gender.  But my car is a female.  :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Getting insertion point of block INSIDE another block.
« Reply #25 on: January 09, 2007, 11:56:44 AM »
Let's play a game :

CAB, do you believe that AutoCAD is a male or a female ?
[tongue in cheek ]
Anything that temperamental has go to be a woman.
[/tongue in cheek ]
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Getting insertion point of block INSIDE another block.
« Reply #26 on: January 09, 2007, 12:01:39 PM »
Let's play a game :

CAB, do you believe that AutoCAD is a male or a female ?
[tongue in cheek ]
Anything that temperamental has go to be a woman.
[/tongue in cheek ]
:-D :-D What he said
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Tramber

  • Guest
Re: Getting insertion point of block INSIDE another block.
« Reply #27 on: January 09, 2007, 12:20:04 PM »
German people have a neutral gender and they probably use it for Acad.

But Acad is definitly a male in French, even if it is costly, some would say expensive which better applies to women (experienced)  :kewl:

A DWG is a male
a script is a male
a program is a male
an arc is a male

a line is a female
a dimension is a female
a poyline is a female as well as a spline
......