Change all objects to layer 0, delete unused layers and change color to BYBLOCK.

Change all objects to layer 0, delete unused layers and change color to BYBLOCK.

arron.craig
Collaborator Collaborator
817 Views
6 Replies
Message 1 of 7

Change all objects to layer 0, delete unused layers and change color to BYBLOCK.

arron.craig
Collaborator
Collaborator

I am trying to batch clean up a few thousand 3D .dwg files and would like some help coming up with a .lisp file that will do most of the work for me. 

Here are the steps I am wanting to carry out:

  1. Move everything in the .dwg to the default layer "0"
  2. Delete all remaining unused layers
  3. Change the color of everything to BYBLOCK
  4. Create a block, name = filename (excluding extension), base point = 0,0,0
  5. Change view style to 2D wireframe
  6. Change view to "Front View"
  7. Save
  8. Close

Hopefully this is possible, would appreciate any available help.

0 Likes
Accepted solutions (1)
818 Views
6 Replies
Replies (6)
Message 2 of 7

EnM4st3r
Advocate
Advocate
Accepted solution

not sure if thats exactly how you want it, but i tried something

(defun c:Cleanthisdwg (/ doc)
  (setq doc (vla-get-activedocument(vlax-get-acad-object)))
  (vlax-for obj (vla-get-modelspace doc)
    (ultimatelayerchange obj "0")
    (vla-put-color obj 0)
  )
  (command "_-purge" "_LAYER" "" "_no")
  (vla-add (vla-get-blocks doc) (vlax-3d-point 0 0 0) (vl-filename-base (getvar 'DWGNAME)))
  (command "_vscurrent" "_2d" "_-view" "_front" "_qsave" "_close")
)

(defun ultimatelayerchange (obj str / makelayer doc oldlayer oldlock)
  (defun makelayer (str / layers)
    (setq layers (vla-get-layers doc))
    (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layers str))))
      t
      (vla-add layers str)
    )
  )
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (makelayer str)
    (progn 
      (setq oldlayer (vla-item (vla-get-layers doc)(vla-get-layer obj)))       
      (setq oldlock (vla-get-lock oldlayer))
      (vla-put-lock oldlayer :vlax-false)    
      (vla-put-layer obj str)    
      (vla-put-lock oldlayer oldlock)
    )
  )
)
Message 3 of 7

ronjonp
Mentor
Mentor

@arron.craig 

Step #4 will create a circular reference.

0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant

@arron.craig wrote:

....

    4, Create a block, name = filename (excluding extension), base point = 0,0,0

....

I also wondered about step 4.  Does that mean you want to make the whole drawing into a Block, i.e. define everything in the drawing into a single Block, whose name is the same as the drawing's?  That would create a circular reference if that drawing were ever to be INSERTed [not XREF'd] into another drawing, becoming a Block as any Inserted drawing does.

 

If that would never happen, it's possible to have a Block in a drawing with the same name as the drawing, but if it contains everything, what would be the purpose?  It takes more memory to define the Block-of-everything and have it Inserted than to just have the pieces, without the Block definition.

 

But the "base point = 0,0,0" part implies to me that you would INSERT this drawing into some other drawing(s).  In that case, don't define everything into a Block.  Just set the INSBASE System Variable to 0,0,0 [that's the default anyway, if you haven't changed it].  That will be used as the insertion base point when INSERTing into another drawing, and it will be a Block there, with no need for a nested Block definition within it [whether or not with a different name to prevent the circular reference].

Kent Cooper, AIA
0 Likes
Message 5 of 7

arron.craig
Collaborator
Collaborator

Is it the block name = dwg name that creates the circular reference or just the whole drawing contents being in a block? I can certainly change it a bit to dwgname_"block" or something, as long as I can use the dwg name somewhere to identify it..

The use case is actually for a separate Autodesk utility "Spec Editor for Autodesk Plant3D". I need each of my 3D .dwg valve models to be in a block, with nothing else in the drawing for it to import the block correctly into the spec/catalogue. 

0 Likes
Message 6 of 7

ronjonp
Mentor
Mentor

@arron.craig wrote:

 I need each of my 3D .dwg valve models to be in a block, with nothing else in the drawing for it to import the block correctly into the spec/catalogue. 


If you create a block within that drawing then insert it into another drawing you will have a block within a block.

 

Here's an example of circular reference .. try to insert it in a drawing.

0 Likes
Message 7 of 7

arron.craig
Collaborator
Collaborator

I see. That situation is not applicable in this case because the blocks and drawings are never inserted into another drawing. The workflow I am trying to automate is the same as the manual method which is recommended by Plant 3D/Autodesk. 

0 Likes