Jump to content

Recommended Posts

  • 1 year later...
Posted

Hello everyone,

 

Is it possible to have an LSP routine to replace some repetitive lines with a block. Actually, I got a drawing to deal with, wherein, all electrical sockets are lines and circles. Is it possible if i get a sample, transfer it to block, then replace all the other similar sockets with the mentioned block?

Posted

hi Lee Mac

Thanks to you for all codes , which helps me a lot

 

 

(repeat (setq idx (sslength sel))

(LM:burstnested (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))

)

 

The above code modified in NestedBurstV1-0.lsp of Lee Mac

 

(repeat (setq idx (sslength sel))

(LM:ApplytoBlockObjects

(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))

(vla-get-effectivename (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))

'LM:burstnested

)

)

 

 

This works for me so far ,

  • 6 months later...
Posted

Hi,

 

I know, it is an old thread, but i just noticed that EXNEST can burst blocks AutoCAD can't..

Just want to say this is a amazing thing, maybe Lee has an explanation.

I'm not a expert in 'unnamed blocks' etc. but what kind of blocks are there AutoCAD is not able to explode?

 

 

***f2***

 

 

..

..

 

 

Cannot explode that block.

/

Cannot explode that block.

-

Cannot explode that block.

\

Cannot explode that block.

|

Cannot explode that block.

/

Cannot explode that block.

-

Cannot explode that block.

\

Cannot explode that block.

|

Cannot explode that block.

/

Cannot explode that block.

-

Cannot explode that block.

 

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: *Cancel*

Command: B

BLOCK

Select objects: Specify opposite corner: 1405 found

Select objects:

 

 

Command: EXNEST

Select block: Regenerating model.

Command:

Command:

Command: BURST

Select objects: 1 found

 

 

!! done !!

Posted

One type isyis blocks that have unequal scaled 3-D solids. At least until 2012. Probably later

Posted (edited)

*edit*edit*

 

 

Thanks for that insight. With EXNEST still no non-uniform blocks containing 3D SOLIDS can be handled, seems logic as it is result in very complex geometry calculations. In the current model i am working on (SAT origin from Inventor) there seem to be parts mirrored round different axis (parts with x=-1, y=-1, z=-1 and combinations), If i use AutoCAD burst command i seem only to explode if x=-1 (?), but EXNEST also explodes parts with z=-1 and y=-1 ? What is the logic behind this..

 

Anyway, this provides me some more knowlegde for scaling x,y,z and tracking problems with block containing a other value that 1 as scale. And wWhat is nice to know is that with other objects than 2D solids EXNEST can transform and exploded with this principle fine.. !

 

 

http://www.cadtutor.net/forum/showthread.php?98491-Scale-method-(alternative-for-block-inside-block-method)&highlight=sxyz

EXNEST FAILS 3D XYZ.jpg

EXNEST FAILS.dwg

Knipsel.jpg

parts mirrored z.JPG

Drawing2.dwg

Edited by halam
Posted

It hasn't been that long ago when autocad finally figured out how explode most 2D entities properly. Last I checked it still had problems with ellipse entities.

 

In native 2D entities, all data is stored in the entity table database in numeric values.

 

Even this can be quit a complex mathematic calculation

 

Taken into consideration must be :

  • BLOCK'S Table's Insbase Point
  • INSERT Scale
  • INSERT UCS
  • INSERT Insertion Point
  • INSERT Rotation

 

Then for the entity:

  • Entity Type
  • Entity Points
  • Entity UCS
  • Entity Elevation
  • Entity Thickness

 

A non WCS ARC entity with thickness was always a gamble with explode. It had to be converted into a POLYLINE with bulges

 

With 3D solids, all of the geometry data is stored in binary format ( DXF Group 1 ). Extracting the numeric and form data would very difficult ( if not impossilbe ) to convert this into Acad's native entity information

 

 

Create a 3DSOLID and then at the command line type this

(entget (entlast))

 

1 possible work around would be if you can these 3D solids into meshes.

 

Mirrored BLOCKs are the easiest deal with. The X axis scale must be -1. So simply change all of the X axis values from positive to negative or vice versa. Maybe they figured out how to do this the Y and or Z axis.

 

HTH -David

Posted

"simply change all of the X axis values from positive to negative or vice versa".

That is a way to deal with it, but it might have an impact on the workload / proces if you have large quantities of parts in a DWG files

I'm thinking their should be a smarter way, to get mirrored (copies!) of a 3D block, but this is getting off-topic

 

 

================

(off-topic: did some import / export of 3D DWG blocks)

I did some checking how these x,y,z values as i was thinking this might be 'hurtfull' in other applications to import

Was supprised this x,y,z translated pretty good for Sketchup and Allplan, even after exporting it to IFC.

 

 

But AutoCAD 'Surface' and 'Mesh' are not translated.. (I'm starting with DWG geometry coming from Inventor)

When i convert this _MESHSMOOTH ..EXPLODE mesh to 3DFACES

.. exports now 'good'.. now i'm looking for a routine to explode surfaces.)

screnshot surface not translated.zip

  • 7 months later...
Posted

I am using this code, which works great and grabs the exact block i want every time. now I want to have it change everything within the block EXCEPT TEXT/MTEXT to be 0 (layer), byblock (color), byblock (lineweight)

 

Can anyone help me out?

 

(defun c:TWRXP (/ s doc)
 (if (setq s (ssget "X" '((0 . "INSERT") (8 . "TOWER"))))
   (progn
     (vlax-for obj (vla-item (vla-get-blocks
                               (setq doc (vla-get-activedocument
                                           (vlax-get-acad-object)
                                           )
                                     )
                               )
                             (vla-get-effectivename
                               (vlax-ename->vla-object (ssname s 0))
                               )
                             )
       (if (and
             (= "AcDbBlockReference" (vla-get-objectname obj))
             (null (vl-catch-all-error-p
                     (vl-catch-all-apply 'vla-explode (list obj))
                     )
                   )
             )
         (vl-catch-all-apply 'vla-delete (list obj))
         )
       )
     )
   )
 (command "_.-purge" "_B" "*" "_N")
 (vla-regen doc acallviewports)
 (princ)
 )(vl-load-com)


  • 1 year later...
Posted

There is also another problem.
For example, if a block is inserted into a drawing in 2 ways,

1- like a unique block

2- like nested in another block B

all blocks A will be exploded!

both those nested and those not nested.

Posted
41 minutes ago, marmo said:

There is also another problem.
For example, if a block is inserted into a drawing in 2 ways,

1- like a unique block

2- like nested in another block B

all blocks A will be exploded!

both those nested and those not nested.

 

What code are you referring to?

Posted

page 1, second last post

 

(defun c:exnest ( / doc ent )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
                   (princ "\nSelected object is not a block.")
               )
           )
       )
   )
   (if ent
       (progn
           (vlax-for obj 
               (vla-item 
                   (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
                   (LM:name->effectivename (cdr (assoc 2 (entget ent))))
               )
               (exnest:explode obj)
           )
           (vla-regen doc acallviewports)
       )
   )
   (princ)
)
(defun exnest:explode ( obj / lst )
   (if 
       (and
           (= "AcDbBlockReference" (vla-get-objectname obj))
           (vlax-write-enabled-p obj)
           (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
       )
       (progn
           (foreach obj lst (exnest:explode obj))
           (vla-delete  obj)
       )
   )
)

;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
   (if
       (and (wcmatch blk "`**")
           (setq rep
               (cdadr
                   (assoc -3
                       (entget
                           (cdr (assoc 330 (entget (tblobjname "block" blk))))
                          '("AcDbBlockRepBTag")
                       )
                   )
               )
           )
           (setq rep (handent (cdr (assoc 1005 rep))))
       )
       (cdr (assoc 2 (entget rep)))
       blk
   )
)
(vl-load-com) (princ)
Posted

I cannot reproduce this behaviour - can you upload a sample drawing?

Posted

Trying to make the example file I realized that it works instead. I must have tested it badly before. Great job as always Lee-Mac

  • 1 month later...
Posted
On 7/7/2015 at 10:56 AM, Lee Mac said:

 

Please try the following:

 


(defun c:exnest ( / doc ent )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
                   (princ "\nSelected object is not a block.")
               )
           )
       )
   )
   (if ent
       (progn
           (vlax-for obj 
               (vla-item 
                   (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
                   (LM:name->effectivename (cdr (assoc 2 (entget ent))))
               )
               (exnest:explode obj)
           )
           (vla-regen doc acallviewports)
       )
   )
   (princ)
)
(defun exnest:explode ( obj / lst )
   (if 
       (and
           (= "AcDbBlockReference" (vla-get-objectname obj))
           (vlax-write-enabled-p obj)
           (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
       )
       (progn
           (foreach obj lst (exnest:explode obj))
           (vla-delete  obj)
       )
   )
)

;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
   (if
       (and (wcmatch blk "`**")
           (setq rep
               (cdadr
                   (assoc -3
                       (entget
                           (cdr (assoc 330 (entget (tblobjname "block" blk))))
                          '("AcDbBlockRepBTag")
                       )
                   )
               )
           )
           (setq rep (handent (cdr (assoc 1005 rep))))
       )
       (cdr (assoc 2 (entget rep)))
       blk
   )
)
(vl-load-com) (princ)
 

 

 

Currently, this LISP explodes all nested blocks within a block and keeps the original block intact, which is exactly what I need.

 

Could you please help me modify this LISP so it performs following actions:

1.) Select block to explode all nested blocks within a block (already works)

2.) Move all objects inside a block to Layer 0

3.) Sets Color of all objects to: ByLayer

 

Thank you!

 

 

 

 

 

Posted
1 hour ago, mitjak9 said:

Currently, this LISP explodes all nested blocks within a block and keeps the original block intact, which is exactly what I need.

 

Could you please help me modify this LISP so it performs following actions:

1.) Select block to explode all nested blocks within a block (already works)

2.) Move all objects inside a block to Layer 0

3.) Sets Color of all objects to: ByLayer

 

Thank you!

 

Consider the following slight modification:

(defun c:exnest ( / doc ent )
    (while
        (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent) nil)
                (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
                    (princ "\nSelected object is not a block.")
                )
            )
        )
    )
    (if ent
        (progn
            (vlax-for obj 
                (vla-item 
                    (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
                    (LM:name->effectivename (cdr (assoc 2 (entget ent))))
                )
                (exnest:explode obj)
            )
            (vla-regen doc acallviewports)
        )
    )
    (princ)
)
(defun exnest:explode ( obj / lst )
    (cond
        (   (not (vlax-write-enabled-p obj)))
        (   (and (= "AcDbBlockReference" (vla-get-objectname obj))
                 (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
            )
            (foreach obj lst (exnest:explode obj))
            (vla-delete  obj)
        )
        (   t
            (vla-put-layer obj "0")
            (vla-put-color obj acbylayer)
        )
    )
)

;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
    (if
        (and (wcmatch blk "`**")
            (setq rep
                (cdadr
                    (assoc -3
                        (entget
                            (cdr (assoc 330 (entget (tblobjname "block" blk))))
                           '("acdbblockrepbtag")
                        )
                    )
                )
            )
            (setq rep (handent (cdr (assoc 1005 rep))))
        )
        (cdr (assoc 2 (entget rep)))
        blk
    )
)
(vl-load-com) (princ)

 

Posted

Mitjak, i use the code of GileCAD / Edit_block to fix blocks bylayer byblock etc. Use this (in combination with exnest) frequently for all my blocking adventures. Give it a  try. Its allso om the appstore of the autode$k site

 

https://translate.google.com/translate?hl=nl&sl=fr&tl=en&u=http%3A%2F%2Fgilecad.azurewebsites.net%2FLisp.aspx

  • 1 year later...
Posted

Hi Lee Mac, 

I am a fan of your apps. I am trying to see if you of the people in this forum can help with something. I would like to apply the same code you have shown below, but I would like to have the option to select more that one block at the time and also I would like to apply more things.

 

1. Select all the blocks with nested blocks in my drawing.

2. explode all the nasted blocks and keep the first level block

3. to put everything on layer (0), By layer.

 

Do you thing you can make happens. Thank you in advance

 

(defun c:exnest ( / doc ent )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
                   (princ "\nSelected object is not a block.")
               )
           )
       )
   )
   (if ent
       (progn
           (vlax-for obj 
               (vla-item 
                   (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
                   (LM:name->effectivename (cdr (assoc 2 (entget ent))))
               )
               (exnest:explode obj)
           )
           (vla-regen doc acallviewports)
       )
   )
   (princ)
)
(defun exnest:explode ( obj / lst )
   (if 
       (and
           (= "AcDbBlockReference" (vla-get-objectname obj))
           (vlax-write-enabled-p obj)
           (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
       )
       (progn
           (foreach obj lst (exnest:explode obj))
           (vla-delete  obj)
       )
   )
)

;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
   (if
       (and (wcmatch blk "`**")
           (setq rep
               (cdadr
                   (assoc -3
                       (entget
                           (cdr (assoc 330 (entget (tblobjname "block" blk))))
                          '("AcDbBlockRepBTag")
                       )
                   )
               )
           )
           (setq rep (handent (cdr (assoc 1005 rep))))
       )
       (cdr (assoc 2 (entget rep)))
       blk
   )
)
(vl-load-com) (princ)
Posted
17 hours ago, Reinaldo Camacho said:

Hi Lee Mac, 

I am a fan of your apps. I am trying to see if you of the people in this forum can help with something. I would like to apply the same code you have shown below, but I would like to have the option to select more that one block at the time and also I would like to apply more things.

 

1. Select all the blocks with nested blocks in my drawing.

2. explode all the nasted blocks and keep the first level block

3. to put everything on layer (0), By layer.

 

Do you thing you can make happens. Thank you in advance

 


(defun c:exnest ( / doc ent )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
                   (princ "\nSelected object is not a block.")
               )
           )
       )
   )
   (if ent
       (progn
           (vlax-for obj 
               (vla-item 
                   (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
                   (LM:name->effectivename (cdr (assoc 2 (entget ent))))
               )
               (exnest:explode obj)
           )
           (vla-regen doc acallviewports)
       )
   )
   (princ)
)
(defun exnest:explode ( obj / lst )
   (if 
       (and
           (= "AcDbBlockReference" (vla-get-objectname obj))
           (vlax-write-enabled-p obj)
           (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
       )
       (progn
           (foreach obj lst (exnest:explode obj))
           (vla-delete  obj)
       )
   )
)

;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
   (if
       (and (wcmatch blk "`**")
           (setq rep
               (cdadr
                   (assoc -3
                       (entget
                           (cdr (assoc 330 (entget (tblobjname "block" blk))))
                          '("AcDbBlockRepBTag")
                       )
                   )
               )
           )
           (setq rep (handent (cdr (assoc 1005 rep))))
       )
       (cdr (assoc 2 (entget rep)))
       blk
   )
)
(vl-load-com) (princ)

 

Try this, although untested...

 

(defun c:exnest-all ( / exnest:explode LM:name->effectivename ss i ent nme itm lst doc )

    (vl-load-com)

    (defun exnest:explode ( obj / lst )
       (if 
           (and
               (= "AcDbBlockReference" (vla-get-objectname obj))
               (vlax-write-enabled-p obj)
               (not (vla-put-explodable (vla-item (vla-get-blocks doc) (vla-get-effectivename obj)) :vlax-true))
               (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)))))
           )
           (progn
               (foreach obj lst (exnest:explode obj))
               (vla-delete  obj)
           )
       )
    )

    ;; Block Name -> Effective Block Name  -  Lee Mac
    ;; blk - [str] Block name

    (defun LM:name->effectivename ( blk / rep )
       (if
           (and (wcmatch blk "`**")
               (setq rep
                   (cdadr
                       (assoc -3
                           (entget
                               (cdr (assoc 330 (entget (tblobjname "block" blk))))
                              '("AcDbBlockRepBTag")
                           )
                       )
                   )
               )
               (setq rep (handent (cdr (assoc 1005 rep))))
           )
           (cdr (assoc 2 (entget rep)))
           blk
       )
    )

    (while
        (or
            (prompt "\nSelect Block References...")
            (not (setq ss (ssget "_:L" '((0 . "INSERT")))))
        )
        (prompt "\nEmpty sel. set...")
    )
    (repeat (setq i (sslength ss))
        (setq ent (ssname ss (setq i (1- i))))
        (setq nme (LM:name->effectivename (cdr (assoc 2 (entget ent)))))
        (if (not (vl-position nme lst))
            (if (= (vla-get-isxref (setq itm (vla-item (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object)))) nme))) :vlax-false)
                (progn
                    (vlax-for obj itm
                        (exnest:explode obj)
                    )
                    (setq lst (cons nme lst))
                )
            )
        )
    )
    (foreach nme lst
        (vlax-for obj (vla-item (vla-get-blocks doc) nme)
            (vla-put-layer obj "0")
            (vla-put-color obj 256)
        )
    )
    (vla-regen doc acallviewports)
    (princ)
)

HTH., Regards, M.R.

Posted

Thank you Marko,

 

It works PERFECT, but it still leaves some blocks orphans. But this is exactly what I need, Also I forgot to add an extra item in the list. Thank you for everything guys.

 

I will be happy if you can help me to add the last item shown in the list into the routine you sent me.

 

1. Select all the blocks with nested blocks in my drawing.

2. explode all the nasted blocks and keep the first level block

3. to put everything on layer (0), By layer.

4. to put everything on Linetype, By layer.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...