Author Topic: How to find exploded blocks  (Read 6237 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How to find exploded blocks
« on: January 12, 2011, 05:55:03 AM »
Is there a way to find and replace exploded blocks
Suppose I have a plan has 10 blocks each block inserted 10 times but all blocks are exploded.
How to find exploded block re block again

I know It is MAD idea but may be there is a solution somewhere

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to find exploded blocks
« Reply #1 on: January 12, 2011, 06:44:45 AM »
That's really MAD  :-)

I think that only way to do this is to compare object layout/position to blocks layout (is it possible ?). If equal that block them.
I will be watching this tread. It is interesting.

Really MAD.

kruuger

pBe

  • Bull Frog
  • Posts: 402
Re: How to find exploded blocks
« Reply #2 on: January 12, 2011, 07:02:33 AM »

I think that only way to do this is to compare object layout/position to blocks layout (is it possible ?).

That would be something indeed 8-)

If a copy of the original block is still in the drawing, i guess you can use that for comparison  :| maybe... maybe not
It would be interesting to see if anyone would even try doing it this way..
 :-)

We shall see   :wink:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to find exploded blocks
« Reply #3 on: January 12, 2011, 08:13:27 AM »
Maybe you can test for gunshot residue. :evil:
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.

Nibster

  • Guest
Re: How to find exploded blocks
« Reply #4 on: January 12, 2011, 08:29:42 AM »
Maybe you can test for gunshot residue. :evil:

i think that test is only good for dead links.   :-)


Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: How to find exploded blocks
« Reply #5 on: January 12, 2011, 08:37:57 AM »
Woooooooo Iam sorry to hear that . :cry:  :cry:  :|

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to find exploded blocks
« Reply #6 on: January 13, 2011, 04:55:41 AM »
It could be probably be done with a high rate of accuracy.  But it would take a major amount of effort

Stumbling points would be INSERTs that were:
  • Rotated
  • Scaled
  • Unequally Scaled
  • Non WCS
prior to being exploded.

If any sub entities had been erased or modified, it would make the task almost impossible.  -David
R12 Dos - A2K

jvillarreal

  • Bull Frog
  • Posts: 332
Re: How to find exploded blocks
« Reply #7 on: July 26, 2011, 02:36:24 PM »
Using the simple idea of selecting the exploded block entities (1 block at a time) and comparing entity count along with min/max lengths of unpurged blocks...this could at least provide a starting point as it seems to work most of the time with limited testing.
I've provided a test drawing. I tried accounting for uniform scaling and rotation as well.
Please note that i haven't been lispin much in the past few months so expect the worst.
Code: [Select]
;;RB.lsp
(defun binfo (ob / sv msv cnt blengths)
 (setq sv (safearray-value (vlax-variant-value (vla-explode ob))) cnt (length sv)
       msv (vl-remove-if-not '(lambda (x)(vl-position (vla-get-objectname x) '("AcDbArc" "AcDbLine" "AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDb3dPolyline"))) sv))
(if msv (setq
       blengths (mapcar '(lambda (x)(olen x)) msv)
       minlen (apply 'min blengths) maxlen (apply 'max blengths)
       mino (nth (vl-position minlen blengths) msv)
       mins (vlax-curve-getpointatparam mino (vlax-curve-getstartparam mino))
       mine (vlax-curve-getpointatparam mino (vlax-curve-getendparam mino))))
 (mapcar '(lambda (x)(vla-delete x)) sv)
 cnt
)


(defun ssget->vla-list (ss / i ename allobj);(Charles Alan Butler)
 (if ss
  (progn
       (setq i -1)
       (while (setq  ename (ssname ss (setq i (1+ i))))
         (setq allobj (cons (vlax-ename->vla-object ename) allobj))
       )
       allobj))
)

(defun olen (ob / on)
(setq on (vla-get-objectname ob))
(cond
 ((vl-position on '("AcDbLine" "AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDb3dPolyline"))
   (vla-get-length ob))
 ((= on "AcDbArc")(vla-get-arclength ob))
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:rb (/ ActDoc *Space* obcontents blk bname bcen ecen bfound tempobj mins mine mino minlen maxlen emins emine emino eminlen emaxlen ecnt)
(vl-load-com)
(setq ActDoc (vla-get-activedocument (vlax-get-acad-object))
      *Space* (vlax-get-property ActDoc (nth (vla-get-ActiveSpace ActDoc)'("PaperSpace" "ModelSpace")))
      obcontents (ssget) ecnt (sslength obcontents)
      vlaobcontents (ssget->vla-list obcontents)
      vlaobcontents (vl-remove-if-not
                     '(lambda (x)(vl-position (vla-get-objectname x) '("AcDbArc" "AcDbLine" "AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDb3dPolyline"))) vlaobcontents)
      elengths (mapcar '(lambda (x)(olen x)) vlaobcontents)
      eminlen (apply 'min elengths) emaxlen (apply 'max elengths)
      emino (nth (vl-position eminlen elengths) vlaobcontents)
      emins (vlax-curve-getpointatparam emino (vlax-curve-getstartparam emino))
      emine (vlax-curve-getpointatparam emino (vlax-curve-getendparam emino)))
(vlax-for blk (vla-get-blocks ActDoc)
   (and (not bfound) tempobj (not (vla-delete tempobj))(setq tempobj nil bname nil))
   (and
      (not bfound)
      (not (wcmatch (vla-get-name blk) "*Model_Space*,*Paper_Space*"))
      (eq (vlax-get-property blk 'explodable) :vlax-true)
      (setq tempobj
        (vla-insertblock *Space*
          (vlax-3d-point
            '(0 0 0)
          )
          (vla-get-name blk) 1.0 1.0 1.0 0.0
        )
      )
      (setq bname (vla-get-name blk))
   )

  (if (and bname tempobj
       (equal(binfo tempobj) ecnt 3)
       (equal (/ minlen eminlen)(/ maxlen emaxlen) -1.0e-6)
      )
      (setq bfound bname)
  )
)
  (if bfound
   (progn
    (vla-move tempobj (vlax-3d-point mins) (vlax-3d-point emins))
    (vla-rotate tempobj (vlax-3d-point emins)(- (angle emins emine)(angle mins mine)))
    (vla-scaleentity tempobj (vlax-3d-point emins)(/ eminlen minlen))
    (princ (strcat "\nBlock Found - " bname))
   )
  )

(and (not bfound) tempobj (vla-delete tempobj))
(if (not bfound)(princ "\nNo Match Found."))
(princ)
)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: How to find exploded blocks
« Reply #8 on: July 26, 2011, 04:26:29 PM »
Well,...ther is my suggestion.

Create a tool who save block name and there propreties in a dictionary when closing the drawing.
so when the drawing will open the tool will check the block list data.

maybe i'm crasy... but this is what it come in mind.
Keep smile...

vnanhvu

  • Guest
Re: How to find exploded blocks
« Reply #9 on: July 26, 2011, 09:20:01 PM »
  Sorry i have a question, if someone broke all DIM, there is way to recover to its. Thanks for all help.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: How to find exploded blocks
« Reply #10 on: July 27, 2011, 04:42:17 PM »
a little handy...but I think yes.
Keep smile...

SOFITO_SOFT

  • Guest
Re: How to find exploded blocks
« Reply #11 on: July 27, 2011, 06:55:49 PM »
Hellosss @llsssss:
The "Handle" may be a clue?
When does the INSERT is assigned a handle (DXF code 5).
When broken, this should go away right HANDLE?.
And the new entintys, daughters of the block, will have to take one.
Will they be consecutive?
The hole is free of disappear INSERT is completed or is it free?

Perhaps these are the remains of the powder of the shooting. :-P :-P :evil:

Greetings for Madrid.  :-) :-)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to find exploded blocks
« Reply #12 on: July 29, 2011, 02:22:15 AM »
Unfortunately not necessarily. The handle isn't like an index, it's more of a hash code. There is probably a way to calculate it, but nothing documented. And there's probably also some objects made in between each of these "daughter' entities (e.g. the text in a Dim would probably also contain some XDictionaries & XRecords - each would also have handles)

I remember another thread about this - trying to get the "previous" entity by trying to calculate it's handle. I think the consensus there was that the ActiveX ObjectID was a better bet.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to find exploded blocks
« Reply #13 on: August 02, 2011, 02:42:30 AM »
For ObjectARX and .NET you can get the next handle using the Database's HandSeed property, the only thing that showed up in search was in DXF reference Headers Section for $HandSeed and not sure if that is helpful for Autolisp, but I do not really see how that helps much for this situation.

Getting the exploded blocks is easy if the drawing has not been closed using BlockTableRecord.GetErasedBlockReferenceIds and you are able to get the scale factor, rotation etc......
If the drawing has been closed then you need to add a event to store the info and using scale, rotation, insertion point etc..... you could find the exploded entites and replace with a BlockReference, but not sure if that is possible in AutoLisp

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to find exploded blocks
« Reply #14 on: August 02, 2011, 04:15:26 AM »
I think the idea with getting the handle would be to check for consecutiveness of entities in the Model/Paper space. Comparing them to what's in the block definition. Though you're correct, a simple entnext would do the same without needing to fiddle with Handle/ObjectID at all.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.