Jump to content

Wblock for all objects into individual dwgs


robertbon

Recommended Posts

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!

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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
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...