Author Topic: Select objects inside 3D solid - SOLVED -  (Read 3120 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #15 on: August 20, 2022, 04:34:04 AM »
I grouped every pair of sphere-block, after using your lisp only spheres are selected not the entire group.
another way to link them?

tried Gccoincident but only works with 2d objects

For linking purposes, I stated GROUPS, but there are more ways : XDATA, LDATA, LAYER, and so on...
Could you try to GROUP/LINK by LAYER for ex...
After your SOLIDS have been highlighted, you could qselect with LAYER matching filter, and choose non SOLID entity types, do SELECT command, press ENTER, qselect with LAYER matching filter, choose only SOLID entity types, hit DEL and finally you'll have (sssetfirst nil (ssget "_P"))...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Select objects inside 3D solid
« Reply #16 on: August 20, 2022, 07:09:45 AM »
I compiled this for 2018 (R22), I can't test it
if it does load call the lisp function (getBlocksInsidesolid)
« Last Edit: August 20, 2022, 07:22:44 AM by It's Alive! »

nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #17 on: August 20, 2022, 10:48:20 AM »
Bummer, yeah you can probably get the solid and decode it (http://www.theswamp.org/index.php?topic=25097.0)
You should be able to build a list of planes from the face vertexs, then do the ray trace thing. 
I noticed some plane functions here (http://www.theswamp.org/index.php?topic=40494.msg457913#msg457913)

here's the list of objects I found.. though it seems the ID is not unique

Quote
ID = BJ1-106
ID = BJ1-106
ID = BJ1-106
ID = BJ1-140
ID = BJ1-108
ID = BJ1-102
ID = BJ1-140
ID = BJ1-125
ID = BJ1-102
ID = BJ1-143
ID = BJ1-132
ID = BJ1-132
ID = BJ1-119
ID = BJ1-115
ID = BJ1-145
ID = BJ1-141
ID = BJ1-131
ID = BJ1-129
ID = BJ1-127
ID = BJ1-122
ID = BJ1-12
ID = BJ1-117
ID = BJ1-107
ID = BJ1-106
ID = BJ1-10


before uploading the file I just copied some of them to make more evident what I want, but in a real job it'll be unique.


nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #18 on: August 20, 2022, 10:52:11 AM »
I grouped every pair of sphere-block, after using your lisp only spheres are selected not the entire group.
another way to link them?

tried Gccoincident but only works with 2d objects

For linking purposes, I stated GROUPS, but there are more ways : XDATA, LDATA, LAYER, and so on...
Could you try to GROUP/LINK by LAYER for ex...
After your SOLIDS have been highlighted, you could qselect with LAYER matching filter, and choose non SOLID entity types, do SELECT command, press ENTER, qselect with LAYER matching filter, choose only SOLID entity types, hit DEL and finally you'll have (sssetfirst nil (ssget "_P"))...


Thanks Marko, gonna try the layer thing now...

nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #19 on: August 21, 2022, 11:58:15 AM »
Marko, again asking for your help, would it be possible to modify your code so that, instead of checking for interference between each and every one of the solids, it would check only using the first one as a base/pivot and only those that interfere with it?

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #20 on: August 21, 2022, 02:26:28 PM »
Marko, again asking for your help, would it be possible to modify your code so that, instead of checking for interference between each and every one of the solids, it would check only using the first one as a base/pivot and only those that interfere with it?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:chk3DSOLint ( / *error* s sol_ sol n interf sol_interf ss )
  2.  
  3.  
  4.   (defun *error* ( msg )
  5.     (if msg (prompt msg))
  6.     (princ)
  7.   )
  8.  
  9.   (if
  10.     (and
  11.       (princ "\nSelect MAIN 3D SOLID")
  12.       (setq s (ssget "_+.:E:S" '((0 . "3DSOLID"))))
  13.       (while (null sol_)
  14.         (princ "\nSelect CHECKING 3D SOLIDS")
  15.         (setq sol_ (ssget "_:L" '((0 . "3DSOLID"))))
  16.         (if (null sol_)
  17.           (prompt "\nEmpty sel. set... Try selecting again...")
  18.           sol_
  19.         )
  20.       )
  21.     )
  22.     (progn
  23.       (if (ssmemb (ssname s 0) sol_)
  24.         (ssdel (ssname s 0) sol_)
  25.       )
  26.       (repeat (setq n (sslength sol_))
  27.         (setq sol (cons (ssname sol_ (setq n (1- n))) sol))
  28.       )
  29.       (setq interf 0)
  30.       (mapcar
  31.         (function (lambda ( a )
  32.           (if (vla-checkinterference (vlax-ename->vla-object a) (vlax-ename->vla-object (ssname s 0)) :vlax-true 'test)
  33.             (progn
  34.               (setq sol_interf (cons a sol_interf))
  35.               (setq interf (1+ interf))
  36.               (entdel (entlast))
  37.             )
  38.           )
  39.         ))
  40.         sol
  41.       )
  42.       (setq ss (ssadd))
  43.       (foreach ent sol_interf (ssadd ent ss))
  44.       (sssetfirst nil ss)
  45.       (princ
  46.         (strcat
  47.           "\nNumber of checked 3D SOLIDS : " (itoa (sslength ss))
  48.           "\nNumber of interferences : " (itoa interf)
  49.         )
  50.       )
  51.     )
  52.   )
  53.   (*error* nil)
  54. )
  55.  

HTH.
« Last Edit: August 21, 2022, 11:55:05 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #21 on: August 21, 2022, 04:51:18 PM »
Marko, again asking for your help, would it be possible to modify your code so that, instead of checking for interference between each and every one of the solids, it would check only using the first one as a base/pivot and only those that interfere with it?

Code: [Select]
(defun c:chk3DSOLint ( / *error* s sol_ sol n interf sol_interf ss )

  (vl-load-com)

  (defun *error* ( msg )
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    (if msg (prompt msg))
    (princ)
  )

  (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
  (if (and
      (princ "\nSelect MAIN 3D SOLID")
      (setq s (ssget "_.+:E:S" '((0 . "3DSOLID"))))
      (princ "\nSelect CHECKING 3D SOLIDS")
      (while (null sol_)
        (setq sol_ (ssget "_:L" '((0 . "3DSOLID"))))
        (if (null sol_) (prompt "\nEmpty sel. set... Try selecting again...") sol_ )
      )
    )
    (progn
      (repeat (setq n (sslength sol_))
        (setq sol (cons (ssname sol_ (setq n (1- n))) sol))
      )
      (mapcar
        (function (lambda ( a )
          (if (vla-CheckInterference (vlax-ename->vla-object a) (vlax-ename->vla-object (ssname s 0)) :vlax-true 'test)
            (progn
              (setq sol_interf (cons a sol_interf))
              (entdel (entlast))
              (setq interf (1+ interf))
            )
          )
        ))
        sol
      )
      (setq ss (ssadd))
      (foreach ent sol_interf (ssadd ent ss))
      (sssetfirst nil ss)
      (princ
        (strcat
          "\nNumber of checked 3D SOLIDS : " (itoa (sslength ss))
          "\nNumber of interferences : " (itoa interf)
        )
      )
    )
  )
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  (princ)
)

HTH.


Thanks for the quick response, it says      --bad ssget mode string-- 
as I try to use it. 


changed the first sseget to     ssget "_:L"    and now it allows me to select the objects (it's posible to select more than one 3d solid now, but I select the main one and then enter, but after selecting the next set, it returns: --  bad argument type: numberp: nil --
« Last Edit: August 21, 2022, 05:03:37 PM by nekonihonjin »

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #22 on: August 21, 2022, 11:44:50 PM »
I've fixed it in my post...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #23 on: August 22, 2022, 12:33:41 AM »
I suppose this is what you were aiming to/for :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:chk3DSOLint-processlinks ( / *error* mid s en ex sel elst n counter layname bb sph bbx sphx minpt maxpt midpt assoclst sol interf sol_interf ss dx dy dz ) ;; *templayprefix* - global variable ;; cad ; doc ; spc ; alo - main globals
  2.  
  3.   (or doc (setq doc (vla-get-activedocument cad)))
  4.   (or spc (setq spc (vla-get-block (setq alo (vla-get-activelayout doc)))))
  5.  
  6.   (defun *error* ( msg )
  7.     (vla-endundomark doc)
  8.     (if msg
  9.       (prompt msg)
  10.     )
  11.     (princ)
  12.   )
  13.  
  14.   (defun mid ( p1 p2 )
  15.     (mapcar (function (lambda ( a b ) (/ (+ a b) 2.0))) p1 p2)
  16.   )
  17.  
  18.   (if
  19.     (and
  20.       (princ "\nSelect MAIN 3D SOLID")
  21.       (setq s (ssget "_+.:E:S" (list (cons 0 "3DSOLID"))))
  22.       (setq en (ssname s 0))
  23.       (while (not sel)
  24.         (princ "\nSelect CHECKING ENTITIES")
  25.         (setq sel (ssget))
  26.         (if (not sel)
  27.           (prompt "\nEmpty sel. set... Try selecting again...")
  28.           sel
  29.         )
  30.       )
  31.       (not (initget "BB SPH"))
  32.       (or (setq ch (getkword "\nChoose option [BB / SPH] <BB> : ")) (setq ch "BB"))
  33.       (or *templayprefix* (setq *templayprefix* (cond ( (/= (setq *templayprefix* (getstring t "\nSpecify temporary layer prefix <\"link_\"> : ")) "") *templayprefix* ) ( t "link_" ))))
  34.     )
  35.     (progn
  36.       (if (ssmemb en sel)
  37.         (ssdel en sel)
  38.       )
  39.       (repeat (setq n (sslength sel))
  40.         (setq elst (cons (ssname sel (setq n (1- n))) elst))
  41.       )
  42.       (setq counter 0)
  43.       (foreach e elst
  44.         (while (tblsearch "LAYER" (setq layname (strcat *templayprefix* (itoa (setq counter (1+ counter)))))))
  45.         (cond
  46.           ( (/= (cdr (assoc 0 (entget e))) "3DSOLID")
  47.             (vla-getboundingbox (vlax-ename->vla-object e) 'minpt 'maxpt)
  48.             (mapcar (function set) (list (quote minpt) (quote maxpt)) (mapcar (function safearray-value) (list minpt maxpt)))
  49.             (setq midpt (mid minpt maxpt))
  50.             (if (= ch "BB")
  51.               (setq bb (vla-addbox spc (vlax-3d-point midpt) (if (> (setq dx (- (nth 0 maxpt) (nth 0 minpt))) 0) dx 1e-3) (if (> (setq dy (- (nth 1 maxpt) (nth 1 minpt))) 0) dy 1e-3) (if (> (setq dz (- (nth 2 maxpt) (nth 2 minpt))) 0) dz 1e-3)))
  52.               (setq sph (vla-addsphere spc (vlax-3d-point midpt) 1.0))
  53.             )
  54.             (if (= ch "BB")
  55.               (progn
  56.                 (setq bbx (entget (vlax-vla-object->ename bb)))
  57.                 (entupd (cdr (assoc -1 (entmod (subst (cons 8 layname) (assoc 8 bbx) bbx)))))
  58.                 (setq sol (cons (vlax-vla-object->ename bb) sol))
  59.               )
  60.               (progn
  61.                 (setq sphx (entget (vlax-vla-object->ename sph)))
  62.                 (entupd (cdr (assoc -1 (entmod (subst (cons 8 layname) (assoc 8 sphx) sphx)))))
  63.                 (setq sol (cons (vlax-vla-object->ename sph) sol))
  64.               )
  65.             )
  66.           )
  67.           ( t
  68.             (setq ex (entget (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object e)))))
  69.             (setq sol (cons (entupd (cdr (assoc -1 (entmod (subst (cons 8 layname) (assoc 8 ex) ex))))) sol))
  70.           )
  71.         )
  72.         (setq assoclst (cons (list layname e) assoclst))
  73.       )
  74.       (setq interf 0)
  75.       (mapcar
  76.         (function (lambda ( x / el chk )
  77.           (setq el (entlast))
  78.           (if (and en (not (vl-catch-all-error-p (setq chk (vl-catch-all-apply (function vla-checkinterference) (list (vlax-ename->vla-object x) (vlax-ename->vla-object en) :vlax-true 'test))))) chk)
  79.             (progn
  80.               (setq sol_interf (cons x sol_interf))
  81.               (setq interf (1+ interf))
  82.               (if (not (eq el (entlast)))
  83.                 (while (setq el (entnext el))
  84.                   (entdel el)
  85.                 )
  86.               )
  87.               (if (vlax-erased-p en)
  88.                 (entdel en)
  89.               )
  90.             )
  91.           )
  92.         ))
  93.         sol
  94.       )
  95.       (setq ss (ssadd))
  96.       (foreach ent sol_interf
  97.         (if (and ent (not (vlax-erased-p ent)))
  98.           (ssadd (cadr (assoc (setq layname (cdr (assoc 8 (entget ent)))) assoclst)) ss)
  99.         )
  100.       )
  101.       (foreach ent sol
  102.         (if (and ent (not (vlax-erased-p ent)))
  103.           (progn
  104.             (setq layname (cdr (assoc 8 (entget ent))))
  105.             (entdel ent)
  106.             (vla-delete (vla-item (vla-get-layers doc) layname))
  107.           )
  108.         )
  109.       )
  110.       (sssetfirst nil ss)
  111.       (princ
  112.         (strcat
  113.           "\nNumber of interferences : " (itoa interf)
  114.           "\nNumber of highlighted entities inside boundary MAIN 3DSOLID : " (itoa (sslength ss))
  115.         )
  116.       )
  117.     )
  118.   )
  119.   (*error* nil)
  120. )
  121.  

HTH.
« Last Edit: August 22, 2022, 06:18:26 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #24 on: August 22, 2022, 01:02:00 AM »
I've fixed it in my post...

perfect! thanks a lot man.

the code from last post it's not working for some reason, but with the one you just fixed it's more than enough.

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #25 on: August 22, 2022, 01:26:56 AM »
I've fixed it in my post...

perfect! thanks a lot man.

the code from last post it's not working for some reason, but with the one you just fixed it's more than enough.

Can you check it once again, have changed some minor mistakes...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #26 on: August 22, 2022, 01:54:06 AM »
I've fixed it in my post...

perfect! thanks a lot man.

the code from last post it's not working for some reason, but with the one you just fixed it's more than enough.

Can you check it once again, have changed some minor mistakes...


still error, but not the same, if I select "BB" it says "bb too few actual parameters".
if I choose "SPH" it creates a sphere only in one block and then it says "bad argument type: stringp nil".

Maybe I am not following the procedure as requested by the lisp, as I understand now you can directly select the blocks, but they need to be grouped with a solid? a sphere inserted inside the same block?
What would be an input entity?


ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #27 on: August 22, 2022, 02:13:10 AM »
I've fixed it in my post...

perfect! thanks a lot man.

the code from last post it's not working for some reason, but with the one you just fixed it's more than enough.

Can you check it once again, have changed some minor mistakes...


still error, but not the same, if I select "BB" it says "bb too few actual parameters".
if I choose "SPH" it creates a sphere only in one block and then it says "bad argument type: stringp nil".

Maybe I am not following the procedure as requested by the lisp, as I understand now you can directly select the blocks, but they need to be grouped with a solid? a sphere inserted inside the same block?
What would be an input entity?

OK... Thanks for feedback... I'll try to debug on some drawing with few blocks and bounding 3DSOLID...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Select objects inside 3D solid
« Reply #28 on: August 22, 2022, 03:47:02 AM »
Quote
It works, but during debugging, I've noticed that rectangular Bounding Box 3DSOLIDS (height = 1e-3) don't match position of blocks - it looks that perhaps that small height (1e-3) causes that blocks don't overlap with their linking 3DSOLID - with spheres it's all well... Don't know, try changing that height to something more reliable, but can't guess what would it be...

I've figured it out :
vla-addbox looks for first argument as center of box - i.e. (mid minpt maxpt) and I thought it should be just minpt... Fixed all - should work as expected...
« Last Edit: August 22, 2022, 03:53:23 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: Select objects inside 3D solid
« Reply #29 on: August 22, 2022, 10:46:32 AM »
Quote
It works, but during debugging, I've noticed that rectangular Bounding Box 3DSOLIDS (height = 1e-3) don't match position of blocks - it looks that perhaps that small height (1e-3) causes that blocks don't overlap with their linking 3DSOLID - with spheres it's all well... Don't know, try changing that height to something more reliable, but can't guess what would it be...

I've figured it out :
vla-addbox looks for first argument as center of box - i.e. (mid minpt maxpt) and I thought it should be just minpt... Fixed all - should work as expected...


Sir, you're a mastermind, it works like a charm indeed, thank you again!!