Author Topic: vla-explode changes drawing ?!?  (Read 12250 times)

0 Members and 1 Guest are viewing this topic.

matthias312

  • Guest
vla-explode changes drawing ?!?
« on: August 28, 2014, 08:27:41 AM »
Hello,
i have a problem exploding a block.
I want to explode the added block with the following code:

Code: [Select]
(if (setq sstSelection (ssget "x" '((0 . "insert")(67 . 0))))
    (repeat (setq i (sslength sstSelection))
(setq ent (ssname sstSelection (setq i (1- i))))
(vla-explode (vlax-ename->vla-object ent))
(vla-delete (vlax-ename->vla-object ent))
)
    )

Exploding the block works but the result looks different to the original block.
To Show what i mean i added the block and the result in a dwg-File.
I'm using ACAD2015 but i tried this in ACAD2012 with the same problem.
Please excuse my bad englisch and thanks.
mfg matthias

BlackBox

  • King Gator
  • Posts: 3770
Re: vla-explode changes drawing ?!?
« Reply #1 on: August 28, 2014, 09:49:14 AM »
Welcome to TheSwamp!

Did you by chance intend to BURST the block instead of exploding it?

Cheers
"How we think determines what we do, and what we do determines what we get."

matthias312

  • Guest
Re: vla-explode changes drawing ?!?
« Reply #2 on: August 28, 2014, 10:14:41 AM »
Hi, yes.
Simply said  i want the same result as if i use this code
Code: [Select]
(if (setq sstSelection (ssget "x" '((0 . "insert")(67 . 0))))
    (repeat (setq i (sslength sstSelection))
(command-s "_.explode" (ssname sstSelection (setq i (1- i))))
)
    )
But using this code takes very long and i would like to find a faster solution.
Sometimes there are drawing with hundrets of block sometimes nested etc.

It would also be great to learn why this blocks behaves like this when using vla-explode. I thinks the Constraints in the block but no idea why its changing.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: vla-explode changes drawing ?!?
« Reply #3 on: August 28, 2014, 10:18:06 AM »
Hi, yes.
Simply said  i want the same result as if i use this code
Code: [Select]
(if (setq sstSelection (ssget "x" '((0 . "insert")(67 . 0))))
          (repeat (setq i (sslength sstSelection))
         (command-s "_.explode" (ssname sstSelection (setq i (1- i))))
         )
          )
But using this code takes very long and i would like to find a faster solution.
Sometimes there are drawing with hundrets of block sometimes nested etc.

It would also be great to learn why this blocks behaves like this when using vla-explode. I thinks the Constraints in the block but no idea why its changing.


Off topic, but why are you exploding the block ?  And welcome to TheSwamp  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: vla-explode changes drawing ?!?
« Reply #4 on: August 28, 2014, 10:20:59 AM »
...

But using this code takes very long and i would like to find a faster solution.
Sometimes there are drawing with hundrets of block sometimes nested etc.

It would also be great to learn why this blocks behaves like this when using vla-explode. I thinks the Constraints in the block but no idea why its changing.

Perhaps you'd consider performing this task in .NET, or instead simply export the drawing back to 2000 format (maybe older; whichever version does this for you at export)?
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7526
Re: vla-explode changes drawing ?!?
« Reply #5 on: August 28, 2014, 10:41:06 AM »
Not sure why that block behaves the way it does. Here is some code to convert the block to static with a name that matches the properties table.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ ent i o ss)
  2.   (if (setq ss (ssget "x" '((0 . "insert") (67 . 0))))
  3.     (repeat (setq i (sslength ss))
  4.       (setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
  5.       (if (vl-some
  6.             '(lambda (x) (and (= (vla-get-propertyname x) "Size") (setq name (vlax-get x 'value))))
  7.             (vlax-invoke o 'getdynamicblockproperties)
  8.           )
  9.         (vla-converttostaticblock o name)
  10.       )
  11.     )
  12.   )
  13.   (princ)
  14. )



Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

matthias312

  • Guest
Re: vla-explode changes drawing ?!?
« Reply #6 on: August 28, 2014, 01:24:53 PM »
Quote
Off topic, but why are you exploding the block ?

I have to write a program to clean up dwg-files making them as small as possible.
My program allready works, but the part exploding blocks in drawing works only with (command-s "_.explode" ....).
As there are really big dwgs with many blocks this sometimes takes a while.

Quote
Here is some code to convert the block to static
Allready tried something like this. As long as the constraints stay in the block the problem stays.
When i manually delete the constraints in the Blockeditor and then use the vla-explode it works fine.

Someone knows a way how to delete theese out of the block before/while exploding?

BlackBox

  • King Gator
  • Posts: 3770
Re: vla-explode changes drawing ?!?
« Reply #7 on: August 28, 2014, 01:30:53 PM »

Someone knows a way how to delete theese out of the block before/while exploding?

Since you're working on a drawing in the editor, can you not first call DELCONSTRAINT Command?
"How we think determines what we do, and what we do determines what we get."

matthias312

  • Guest
Re: vla-explode changes drawing ?!?
« Reply #8 on: August 28, 2014, 01:40:35 PM »
Perhaps you'd consider performing this task in .NET, or instead simply export the drawing back to 2000 format (maybe older; whichever version does this for you at export)?

I have to use Lisp for this. I will give the exporting back a try tomorrow at work where a have my acad running.

matthias312

  • Guest
Re: vla-explode changes drawing ?!?
« Reply #9 on: August 28, 2014, 01:43:23 PM »
Since you're working on a drawing in the editor, can you not first call DELCONSTRAINT Command?

The constraints are in the blocks so i would have to do this in the blockeditor for every block.
This probably wouldn't make the programm much faster than using (command-s "_.explode" ....) for every block^^

BlackBox

  • King Gator
  • Posts: 3770
Re: vla-explode changes drawing ?!?
« Reply #10 on: August 28, 2014, 01:52:09 PM »
Since you're working on a drawing in the editor, can you not first call DELCONSTRAINT Command?

The constraints are in the blocks so i would have to do this in the blockeditor for every block.
This probably wouldn't make the programm much faster than using (command-s "_.explode" ....) for every block^^

Poop... Looks like it doesn't remove nested constraints. *kicks dirt*
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7526
Re: vla-explode changes drawing ?!?
« Reply #11 on: August 28, 2014, 01:53:52 PM »
Quote
Off topic, but why are you exploding the block ?

I have to write a program to clean up dwg-files making them as small as possible.
...


Wouldn't exploding all the blocks make the drawing larger ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

matthias312

  • Guest
Re: vla-explode changes drawing ?!?
« Reply #12 on: August 28, 2014, 02:01:47 PM »
Wouldn't exploding all the blocks make the drawing larger ?
Of course i purge the drawing after exploding. My guideline is to make the drawing complettly clean so there is nothing left but single elements.
And then put all together in one block. This block builds the basic for future work .... offtopic^^

The resulting drawings are often under 5% of the original size^^

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: vla-explode changes drawing ?!?
« Reply #13 on: August 28, 2014, 02:07:47 PM »
Maybe this can work?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / s )
  2.     (if (setq s (ssget "_+.:E:S:L" '((0 . "INSERT"))))
  3.         (explodeblock (ssname s 0))
  4.     )
  5.     (princ)
  6. )
  7.  
  8. (defun explodeblock ( ent / enx lay mat obj )
  9.     (setq enx (entget ent)
  10.           obj (tblobjname "block" (cdr (assoc 2 enx)))
  11.           lay (assoc 410 enx)
  12.           mat
  13.         (vlax-tmatrix
  14.             (append
  15.                 (apply '(lambda ( m v ) (mapcar '(lambda ( r v ) (append r (list v))) m v)) (refgeom ent))
  16.                '((0.0 0.0 0.0 1.0))
  17.             )
  18.         )
  19.     )
  20.     (while (setq obj (entnext obj))
  21.         (setq enx (entget obj))
  22.         (if (/= 1 (cdr (assoc 60 enx)))
  23.             (vla-transformby (vlax-ename->vla-object (entmakex (subst lay (assoc 410 enx) enx))) mat)
  24.         )
  25.     )
  26.     (entdel ent)
  27. )
  28.  
  29. ;; RefGeom (gile)
  30. ;; Returns a list whose first item is a 3x3 transformation matrix and
  31. ;; second item the object insertion point in its parent (xref, block or space)
  32.  
  33. (defun refgeom ( ent / ang enx mat ocs )
  34.     (setq enx (entget ent)
  35.           ang (cdr (assoc 050 enx))
  36.           ocs (cdr (assoc 210 enx))
  37.     )
  38.     (list
  39.         (setq mat
  40.             (mxm
  41.                 (mapcar '(lambda ( v ) (trans v 0 ocs t))
  42.                    '(
  43.                         (1.0 0.0 0.0)
  44.                         (0.0 1.0 0.0)
  45.                         (0.0 0.0 1.0)
  46.                     )
  47.                 )
  48.                 (mxm
  49.                     (list
  50.                         (list (cos ang) (- (sin ang)) 0.0)
  51.                         (list (sin ang) (cos ang)     0.0)
  52.                        '(0.0 0.0 1.0)
  53.                     )
  54.                     (list
  55.                         (list (cdr (assoc 41 enx)) 0.0 0.0)
  56.                         (list 0.0 (cdr (assoc 42 enx)) 0.0)
  57.                         (list 0.0 0.0 (cdr (assoc 43 enx)))
  58.                     )
  59.                 )
  60.             )
  61.         )
  62.         (mapcar '- (trans (cdr (assoc 10 enx)) ocs 0)
  63.             (mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx))))))
  64.         )
  65.     )
  66. )
  67.  
  68. ;; Matrix Transpose  -  Doug Wilson
  69. ;; Args: m - nxn matrix
  70.  
  71. (defun trp ( m )
  72.     (apply 'mapcar (cons 'list m))
  73. )
  74.  
  75. ;; Matrix x Matrix  -  Vladimir Nesterovsky
  76. ;; Args: m,n - nxn matrices
  77.  
  78. (defun mxm ( m n )
  79.     ((lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n))
  80. )
  81.  
  82. ;; Matrix x Vector  -  Vladimir Nesterovsky
  83. ;; Args: m - nxn matrix, v - vector in R^n
  84.  
  85. (defun mxv ( m v )
  86.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  87. )
  88.  

ronjonp

  • Needs a day job
  • Posts: 7526
Re: vla-explode changes drawing ?!?
« Reply #14 on: August 28, 2014, 02:48:44 PM »
Here's a way to strip the constraints ( use with caution as it's a lobotomy ) :)

I tested and seemd to fix the vla-explode problem.
Code - Auto/Visual Lisp: [Select]
  1. (defun _stripconstraint ( / dic)
  2.   (and (setq dic (dictsearch (namedobjdict) "acad_assocnetwork")) (entdel (cdr (assoc -1 dic))))
  3. )
  4. (_stripconstraint)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC