Author Topic: [ wip ] Select nested  (Read 14781 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
[ wip ] Select nested
« on: March 10, 2009, 03:31:44 PM »
This could go in the ' show your stuff ' area I guess, but I don't think it is done yet.  This will let you select nested items ( not attributes, didn't want that for this function ) as if you are using ssget.  I have used a lot of gile's code because he understands matrix math a whole lot better than I, and I'm not ashamed to admit it.  There is also a test function at the bottom ' efb ' ( erase from block ) that will show what I'm talking about.

Doesn't really work in 3d space, or when the UCS isn't world.  That is one issue that makes this a work in progress.  Another one was maybe limiting the nesting level, as of right now it grabs the most basic items no matter how low they are nested.

Comment / concerns / opinions all welcomed.

Maybe I should add the work flow of it.
It uses ' grread ' to start.  If you select an item, it will see if it is nested.  If so, it will copy the nested item to the current space, and add the copied item into a list that will delete all such objects when the code is finished running.  Did it this way because I couldn't figure out how to show a nested item as highlighted.  If no nested item is selected, it will show the dragging motion of a window.  Once it has the window, then it uses ' ssget ' with a crossing polygon to select all inserts in that area.  Then it copies the window, as a polyline, to each block, and tests each object within the block.  If it finds another insert, then it will step through that blocks definition, and so forth.  When it finds an item that matches the search criteria ( honoring window or crossing only ), then it will add it to a list of list, along with the matrix to represent it correctly in the current space.  All that uses the matrix functions from gile ( Thanks again gile for all that work! ).  What it returns is a flat list of objects from whatever block they happen to be in.  The objects should only be listed once in the list.  It will honor layer properties, and visibility of objects within the blocks.

Edit: Updated code - 2009-03-11.  Also attached it as file, since it is too large for the message.
Edit: Updated code - 2009-03-18.  Changed the calling functions of the routine ( now ssgetNested ), and added an option for depth.  Right now the depth option is giving me problems with xrefs when set to 1.  If set to 0 it will go as deep as it can, otherwise it will just go as deep as the option.  I tested it on straight blocks, and the depth option works.  I don't know if I have to go with an ObjectDBX version, as that seems like it would work, as I can't figure out the option.  It errors saying that the object is not in the database, but it is.  So frustrating!  I also changed what it returns.  ie:
Quote
Command: (ssgetNested 1)
 Select entity:                                         
(
    (
        <Entity name: 7e3cf1a8>
        (
            (36.3689 20.1553 0.0)
            (38.6465 21.6041 0.0)
        )
        (
            (1.0 0.0 0.0 26.8625)
            (0.0 1.0 0.0 17.4983)
            (0.0 0.0 1.0 0.0)
            (0.0 0.0 0.0 1.0)
        )
        (
            <Entity name: 7e3cf230>
        )
    )
)
It is a list of lists.  Each list is like what is returned by ' nentsel ', except that they second item will either be a point or a list of points.  List items:
1. The nested entity name
2. Point or list of points
3. Real 4x4 matrix ( if copying into the current drawing, you would apply this matrix to have it show in the correct location )
4. The nesting path of the entity in item 1

Edit:  Forgot to add the depth option for the single selection option.  Will add and then repost the code.
Edit: Attached updated code.
« Last Edit: March 18, 2009, 12:34:33 PM by T.Willey »
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: [ wip ] Select nested
« Reply #1 on: March 10, 2009, 03:57:54 PM »
Tim,

It needs this function too:

Code: [Select]
(defun GetCurrentSpace (Doc / BlkCol SpaceList CurSpace ActSpace temp1)
; Returns the "block object" for the active space
; Thanks to Jeff Mishler

(if (= (getvar "cvport") 1)
 (vla-get-PaperSpace Doc)
 (vla-get-ModelSpace Doc)
)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #2 on: March 10, 2009, 04:17:32 PM »
Tim,

It needs this function too:

Code: [Select]
(defun GetCurrentSpace (Doc / BlkCol SpaceList CurSpace ActSpace temp1)
; Returns the "block object" for the active space
; Thanks to Jeff Mishler

(if (= (getvar "cvport") 1)
 (vla-get-PaperSpace Doc)
 (vla-get-ModelSpace Doc)
)
)

Thanks Ron.  I forget ones that get loaded by my mnl.

Also, this doesn't work right on xref's yet.  I think I know how to fix that ( ObjectDBX ).
Tim

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

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: [ wip ] Select nested
« Reply #3 on: March 11, 2009, 10:45:30 AM »
Nice code Tim, and thanks for the compliments.

I see you use Inv-mat to inverse a 4x4 matrix, you'd rather use Inverse which is perhaps less elegant but runs about 6.5 times faster with a 4x4 matrix. (you can read this dicussion with Joe Burke).

I think I issued with simulating the cross/window selection display and returning correct UCS points whatever the current view about current UCS.
Try the following snippet

Code: [Select]
(defun gr-sel-display (/ pt1ucs gr pt3ucs pt1view pt3view pt2view pt4view pt2ucs pt4ucs ssmode)
  (setq pt1ucs (getpoint))
  (while (and (setq gr (grread T 12 0)) (/= (car gr) 3))
    (redraw)
    (setq pt3ucs  (cadr gr)
  pt1view (trans pt1ucs 1 2)
  pt3view (trans pt3ucs 1 2)
  pt2view (list (car pt3view) (cadr pt1view) (caddr pt1view))
  pt4view (list (car pt1view) (cadr pt3view) (caddr pt3view))
  pt2ucs  (trans (ilp pt2view
      (mapcar '+ pt2view '(0 0 1))
      (trans '(0 0 0) 1 2)
      (trans '(0 0 1) 1 2 T)
)
2
1
  )
  pt4ucs  (trans (ilp pt4view
      (mapcar '+ pt4view '(0 0 1))
      (trans '(0 0 0) 1 2)
      (trans '(0 0 1) 1 2 T)
)
2
1
  )
  ssmode (if (< (car pt3view) (car pt1view))
   "_CP"
   "_WP"
)
    )
    (grvecs
      (list (if (= ssmode "_CP")
      -255
      255
    )
    pt1ucs
    pt2ucs
    pt2ucs
    pt3ucs
    pt3ucs
    pt4ucs
    pt4ucs
    pt1ucs
      )
    )
  )
  (redraw)

  ;----------test the returned points----------;
  ;(command "_pline")
  ;(foreach pt (list pt1ucs pt2ucs pt3ucs pt4ucs)
  ;  (command "_non" pt)
  ;)
  ;(command "_c")
  ;--------------------------------------------;
 
  (list ssmode pt1ucs pt2ucs pt3ucs pt4ucs)
)


;; ILP (gile)
;; Returns the intersection point between the line defined by two points
;; and the plane defined by a point and a normal vector
;;
;; Arguments
;; p1 et p2 : 3d points which defines the line
;; org : any point of the plane
;; nor : the normal vector of the plane

(defun ilp (p1 p2 org nor / scl)
  (if (and
(/= 0 (setq scl (vxv nor (mapcar '- p2 p1))))
(setq scl (/ (vxv nor (mapcar '- p1 org)) scl))
      )
    (mapcar (function (lambda (x1 x2) (+ (* scl (- x1 x2)) x1)))
    p1
    p2
    )
  )
)

Another way to test the selection

Code: [Select]
(defun c:test (/ gsd ssmod)
  (and
    (setq gsd (gr-sel-display))
    (setq ss (ssget (car gsd) (cdr gsd)))
    (sssetfirst ss ss)
  )
  (princ)
)
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #4 on: March 11, 2009, 11:07:38 AM »
Thanks gile.  I should have time to look at this later today.
Tim

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

Please think about donating if this post helped you.

xshrimp

  • Mosquito
  • Posts: 14
Re: [ wip ] Select nested
« Reply #5 on: March 11, 2009, 12:41:12 PM »
Doesn't work in block. (XScaleFactor = 2.0,YScaleFactor = 1.0)
abc

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #6 on: March 11, 2009, 01:14:56 PM »
Doesn't work in block. (XScaleFactor = 2.0,YScaleFactor = 1.0)

You are correct.  That is because you can't scale a non-block item by a non-uniform scale matrix.  Thanks for pointing that out, as I didn't.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #7 on: March 11, 2009, 02:56:34 PM »
Updated code in first post ( now as attachment ).  Added the ability to remove items from the selection set, and the selection window looks correct now with the help of gile's code.  Haven't worked out the bugs with NUS blocks ( which I think I will just not allow, and prompt with a message ), or xrefs.  Still have some issues with 3d view selection.  Will not represent the polyline correct, even though the selection is shown correctly.

If anyone has an idea on how to speed up the search for which items are within the selection window, please tell me.  I think this is the major stumbling of the routine now.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: [ wip ] Select nested
« Reply #8 on: March 11, 2009, 05:39:06 PM »
I tried your updated file:

Command: EFB
Backtrace:
[0.55] (VL-BT)
[1.51] (*ERROR* "no function definition: GETCURRENTSPACE")
[2.46] (_call-err-hook #<SUBR @08d3ecd0 *ERROR*> "no function definition:
GETCURRENTSPACE")
[3.40] (sys-error "no function definition: GETCURRENTSPACE")
:ERROR-BREAK.35 nil
[4.32] (#<SUBR @0854258c null-fun-hk> #<VLA-OBJECT IAcadDocument 01b389d8>)
[5.28] (GETCURRENTSPACE #<VLA-OBJECT IAcadDocument 01b389d8>)
[6.23] (SELECTNESTED)
[7.19] (C:EFB)
[8.15] (#<SUBR @09324dfc -rts_top->)
[9.12] (#<SUBR @08542334 veval-str-body> "(C:EFB)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #9 on: March 11, 2009, 06:02:10 PM »
I tried your updated file:

Command: EFB
Backtrace:
[0.55] (VL-BT)
[1.51] (*ERROR* "no function definition: GETCURRENTSPACE")
[2.46] (_call-err-hook #<SUBR @08d3ecd0 *ERROR*> "no function definition:
GETCURRENTSPACE")
[3.40] (sys-error "no function definition: GETCURRENTSPACE")
:ERROR-BREAK.35 nil
[4.32] (#<SUBR @0854258c null-fun-hk> #<VLA-OBJECT IAcadDocument 01b389d8>)
[5.28] (GETCURRENTSPACE #<VLA-OBJECT IAcadDocument 01b389d8>)
[6.23] (SELECTNESTED)
[7.19] (C:EFB)
[8.15] (#<SUBR @09324dfc -rts_top->)
[9.12] (#<SUBR @08542334 veval-str-body> "(C:EFB)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

Thanks Gary.  It has been updated again.  Sometimes those little programs are not worth the hassle.  :wink:
Tim

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

Please think about donating if this post helped you.

xshrimp

  • Mosquito
  • Posts: 14
Re: [ wip ] Select nested
« Reply #10 on: March 13, 2009, 12:27:41 AM »
我的方法支持不等比例块.
但是对于外部参照,坐标系我不知道怎么转换,希望会的修改一下.
英语很差,谁能帮忙翻译一下.  :-)
Code: [Select]
;xshrimp 2009.3.13
(defun c:nn ( / acaddocument acadobject blockobj blockrefobj i mspace n nent obj objent)
(VL-LOAD-COM)
(defun make*ublock(obj / blockobj) 
  (setq blockObj (vla-add (vla-get-Blocks AcadDocument) (vlax-3d-point (list 0 0 0))  "*U" )  )     
  (vla-CopyObjects AcadDocument
    (vlax-safearray-fill
      (vlax-make-safearray vlax-vbObject (cons 0 0) )
      (list obj)   
    )
   blockObj
  )   
 (vla-delete obj)
 (vla-get-name  blockObj)
)
(setq AcadObject (vlax-get-acad-object)
      AcadDocument (vla-get-ActiveDocument Acadobject)
      mSpace (vla-get-ModelSpace Acaddocument)
)
(if (= (length (setq nent (nentsel))) 4)
(progn
  (entmake (entget (car nent)))
  (setq objent (vlax-ename->vla-object (entlast))i 0)   
  (foreach n (last nent) 
  (setq obj (vlax-ename->vla-object n))   
  (setq blockRefObj
    ( vla-InsertBlock
      mSpace
      (vla-get-InsertionPoint obj)
      (make*ublock  objent )
      (vla-get-xScaleFactor   obj)
      (vla-get-yScaleFactor   obj)
      (vla-get-zScaleFactor   obj)
      (vla-get-Rotation       obj)
    )
  )
  (setq i (1+ i)) 
  (if(> i 1)  (command "_.explode" (entlast))  )
  (setq objent(vlax-ename->vla-object (entlast)))     
  );end foreach 
(command "_.explode" (entlast))
(sssetfirst nil (ssget "p")) 
)
)
(prin1)
)
« Last Edit: March 13, 2009, 12:35:48 AM by xshrimp »
abc

Joe Burke

  • Guest
Re: [ wip ] Select nested
« Reply #11 on: March 13, 2009, 09:27:36 AM »
Hi Tim,

Interesting readiing, though I don't quite understand it yet.

Regarding objects nested in xrefs, I doubt ODBX is needed. Use the database object associated with an xref. I think you can copy an object from there into the active file in order to highlight it.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #12 on: March 13, 2009, 11:44:01 AM »
xshrimp,

  That does work.  But it is still only single selection.  I want to use a window.  Maybe can see how to do it.  Thanks for the idea.


Joe,

  I thought I tied that before, and it didn't work.  But I must have been wrong because it does work.  Now I just need to fine tune it.  Thanks.  If there is anything you want me to explain, let me know.
Tim

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

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: [ wip ] Select nested
« Reply #13 on: March 14, 2009, 10:20:16 AM »
Tim,

You're welcome.

I think I understand what you are tyring to do and I certainly applaud the idea. I wrote a routine some years ago which is similar to the ExpressTools command NCOPY. It's primary goal is copying objects from an xref into the active file, with the correct transformations so the copy is on top of the source object.

It works well, but like NCOPY, you cannot use a selection area. It loops while one object at a time is picked.
« Last Edit: March 14, 2009, 10:28:11 AM by Joe Burke »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: [ wip ] Select nested
« Reply #14 on: March 14, 2009, 12:22:06 PM »
Tim,
Nice job as always.  8-)

In a quick test, the ENTER key does not end the selection process although 'Right Click' does.

Also the Undo command does not work after objects have been erased from the block.
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.

Spike Wilbury

  • Guest
Re: [ wip ] Select nested
« Reply #15 on: March 14, 2009, 06:25:24 PM »
Tim,
Nice job as always.  8-)

In a quick test, the ENTER key does not end the selection process although 'Right Click' does.

Also the Undo command does not work after objects have been erased from the block.


I tried the routine, nice one Tim (as normal) - I been using the Block Editor feature for this (I know), your routine is a great alternative - since it won't required a 2nd (or more) block editor opening when the nest entities are inside of a nest block, and so on.. (hope it make sense). :)

Hi Alan,
Just need a Regen after the operation.

« Last Edit: March 14, 2009, 06:46:33 PM by LE »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: [ wip ] Select nested
« Reply #16 on: March 14, 2009, 09:11:45 PM »
Oh, thanks Luis, the regen did the trick with the undo. I should have though of that. :oops:
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.

cjw

  • Guest
Re: [ wip ] Select nested
« Reply #17 on: March 15, 2009, 12:16:43 AM »
Tim,

Thank you sharing.
Nice work!
It's amazing, fantastic !

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #18 on: March 16, 2009, 12:29:43 PM »
Thanks everyone for the kind words, and the testing.  I'm still trying to make it better, as per Joe's comments about xrefs.  I think I have a way to do it.  Now all I need is the time to write it.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [ wip ] Select nested
« Reply #19 on: March 18, 2009, 12:06:04 PM »
Updated code in the first post, and listed what has changed.
Tim

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

Please think about donating if this post helped you.