Jump to content

exctract all block to seprate dwg files and set as references.


jim78b

Recommended Posts

(defun c:exportblocks (/ blk blks x dir)   (vl-load-com)   (if (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))     (progn (setvar 'filedia 0)    (setq dir (strcat (getvar 'dwgprefix) "_ExportedBlocks\\"))    (vl-mkdir dir)    (vlax-for blk blks      (if (and (not (wcmatch (setq x (vla-get-name blk)) "*|*,*`**"))       (= (vla-get-isxref blk) :vlax-false) )        (command "._-wblock" (strcat dir x) x)      )    )    (setvar 'filedia 1)     )   )   (princ) )

 

hello i have this routine but autocad convert the dwg in an old previously release.

i want a lisp please that convert all the blocks to separate files and then automatically convert to xrefs.

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

Please use Code Tags, not Quote Tags for code.

 

AFAIK, WBLOCK uses whatever you have set in Options>Open and Save>Save as for the release it uses.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Didn't like the way the code tag was looking.....

 

(defun c:exportblocks (/ blk blks x dir FileDia_Old)
  (vl-load-com)
  (if (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
    (progn
      (setq FileDia_Old (getvar 'filedia))
      (setvar 'filedia 0)
      (setq dir (strcat (getvar 'dwgprefix) "_ExportedBlocks\\"))
      (vl-mkdir dir)
      (vlax-for blk blks
        (if (and 
              (not (wcmatch (setq x (vla-get-name blk)) "*|*,*`**"))
              (= (vla-get-isxref blk) :vlax-false)
            ) ; end and
            (command "._-wblock" (strcat dir x) x)
        ) ; end if
      ) ; end vlax-for
      (setvar 'filedia Filedia_Old)
    ) ; end progn
  ) ; end if
  (princ)
)

 

 

I haven't tested this yet, does this save the blocks as separate files OK as it is, and you just need to insert them as xrefs?

Link to comment
Share on other sites

So I guess if you look at the existing xref you selected you might find it is say, an AutoCAD 2018 format file and the new xref you are saving might be an AutoCAD 2024 format file. Files are backwards compatible generally (so 2024 will open a 2018 file) but not necessarily forward compatible (so 2018 might not open a 2024 file) - I think the warning is there in case others use the xref with older versions of AutoCAD.

 

You can check - I think this works - open the existing file and type 'version' in the command line to get its current version, and then compare that to the settings as SLW210 suggests

Link to comment
Share on other sites

Ok thanks but is annoying this message. I have acad2023 and can open this files.i create this ext ref with lisp!

Edited by jim78b
Link to comment
Share on other sites

if it is only you that uses the xref, or if everyone has the same version of CAD, I'd be tempted to open and save as a new revision

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