Jump to content
robertbon

Wblock for all objects into individual dwgs

Recommended Posts

robertbon

I've got a dwg that contains lots (hundreds) of 3D polylines.  What I need is to get each individual 3D polyline in its own dwg file?  These can be called 1.dwg, 2.dwg, 3.dwg, etc.

 

Can anyone help me with a LISP routine to acheive this?  It is way beyond my capabilities!

Share this post


Link to post
Share on other sites
mhupp
Posted (edited)

Are they individual blocks?

;EXPORTS ALL BLOCKS IN A DRAWING.
(defun C:BLE (/ blocklist fextr)
  (setq blocklist (ai_table "block" 8))
  (setq fextr (strcat (getvar "dwgprefix") "PROFILE"))
  (if (not (vl-file-directory-p fextr)) (vl-mkdir fextr))
  (if fextr
    (progn
      (foreach n blocklist
        (command "._-wblock" (strcat fextr "\\" n) n)
      )
    )
  )
  (princ)
)

This will Create a subfolder @ the Drawing location Called "Profiles" and export all blocks to it.

Edited by mhupp

Share this post


Link to post
Share on other sites
dlanorh

Try this, it should work without overloading the number of selection sets.

 

(vl-load-com)
(defun c:WBP ( / c_doc o_arr ss o_lst cnt fname)
    (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
          o_arr (vlax-make-safearray vlax-vbobject '(0 . 0))
          ss (ssget "_X" '((0 . "POLYLINE") (-4 . "&=") (70 . 8)))
    );end_setq

    (repeat (setq cnt (sslength ss))
      (setq o_lst (cons (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))) o_lst))
    );end_repeat
    
    (setq cnt 0)
    
    (foreach obj o_lst
      (setq sso (vla-add (vla-get-selectionsets c_doc) "PLO")
            fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      );end_setq
      (vlax-safearray-put-element o_arr 0 obj)
      (vla-additems sso o_arr)
      (vla-wblock c_doc fname sso)
      (vla-delete sso)
      (setq cnt (1+ cnt))
    );end_foreach  
);end_defun

 

It will write each individual 3DPolyline into the same directory as the drawing. The drawing names will start with "0" (zero) then "1" etc until (hopefully) all have been wblocked. It doesn't delete the original polylines from the drawing, but that is a possiblity.

 

Share this post


Link to post
Share on other sites
BIGAL

dlanorh you write good answers it looks to me that your over complicating it by making extra lists, why not just take the ss which is a 3d polyline selection and jump straight to wblock with correct filename. 

 

not tested no cad


(repeat (setq cnt (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (setq fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      (vla-wblock c_doc fname obj)
);end_repeat

Share this post


Link to post
Share on other sites
dlanorh
6 hours ago, BIGAL said:

dlanorh you write good answers it looks to me that your over complicating it by making extra lists, why not just take the ss which is a 3d polyline selection and jump straight to wblock with correct filename. 

 

 


not tested no cad


(repeat (setq cnt (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (setq fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      (vla-wblock c_doc fname obj)
);end_repeat

 

vla-wblock requires a selectionset (safearray of objects) to be passed. I didn't want to attempt handling a selectionset whilst iterating a different selectionset.

 

I've not tested vlax-invoke using an object or list etc so this may be possible.

Share this post


Link to post
Share on other sites
BIGAL

Thanks for reply wblock is one of those things that is a pain command to do easily.

 

I tried this


(setq ss (ssget "_X" '((0 . "POLYLINE") (-4 . "&=") (70 . 8))))
(setq x 0)
(repeat (sslength ss)
(command "_.-wblock" (strcat (getvar 'dwgprefix) (itoa x) ".dwg") "" (list 0 0) (ssname ss x) "" )
(setq x (+ x 1))
)

 

 

  • Like 1

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...