Jump to content

Export each layer to separate FBX file (AutoCAD 2017)


mzlink

Recommended Posts

Hello.

 

I have tried to edit a script found in another topic to suit my needs but i can't get it to work the way i want to.

 

layer2dwg

(defun c:lsave(/ actDoc layCol docName dwgName actSel fCount)

 (vl-load-com)

 (defun BrowseFolder (/ ShlObj Folder FldObj OutVal)
 (vl-load-com)
 (setq
   ShlObj (vla-getInterfaceObject
      (vlax-get-acad-object)
      "Shell.Application"
    )
   Folder(vlax-invoke-method ShlObj 'BrowseForFolder 0
       "Select Folder to create files" 0)
 )
 (vlax-release-object ShlObj)
 (if Folder
   (progn
     (setq
 FldObj (vlax-get-property Folder 'Self)
 OutVal (vlax-get-property FldObj 'Path)
     )
     (vlax-release-object Folder)
     (vlax-release-object FldObj)
     OutVal
   )
 )
)
 
 (setq actDoc(vla-get-ActiveDocument
       (vlax-get-acad-object))
   actSel(vla-get-ActiveSelectionSet actDoc)
   layCol(vla-get-Layers actDoc)
   docName(vla-get-Name actDoc)
   fCount 0
   ); end setq
 (if
   (setq wntPath
      (BrowseFolder))
   (progn
 (vlax-for lay layCol
   (setq layName(vla-get-Name lay)
     dwgName
      (strcat wntPath "\\"
          (vl-filename-base docName)
           " - " layName ".dwg")
     ); end setq
(vla-clear actSel)(vla-erase actSel)
(vla-Select actSel acSelectionSetAll nil nil
 (vlax-safearray-fill
   (vlax-make-safearray vlax-vbInteger '(0 . 0))
    '(
 ) ; end vla-safearray-fill
 (vlax-safearray-fill
   (vlax-make-safearray vlax-vbvariant '(0 . 0))
    (list layName)
 ) ; end vla-safearray-fill
) ; end vla-select
   (if(/= 0(vla-get-Count actSel))
     (vla-WBlock actDoc dwgName actSel)); end if
   (setq fCount(1+ fCount))
   ); end vlax-for
 ); end progn
   ); end if
 (princ
   (strcat "\*** "
       (itoa fCount)
       " files were created *** "))
 (princ)
 ); end of c:lsave

 

I have poked the "WBlock" line in different ways but i can't get FBXEXPORT to work in the script.

 

Any help is appreciated.

Link to comment
Share on other sites

There is no 'vla' method for exporting to FBX. You will have to work with the -FBXEXPORT command I think.

 

I'm just getting errors about "export" / "fbxexport" function not existing when trying to run it in a lsp script. Any ideas for fixing the script?

Link to comment
Share on other sites

I cannot help you with a detailed answer as I use BricsCAD 16 instead of AutoCAD. But you will have to analyse how the -FBXEXPORT command works and then write code containing something like this:

(command "_.-FBXEXPORT" ...)

Your code sample would have to be completely rewritten.

Link to comment
Share on other sites

Try the following:

(defun c:lay2fbx ( / cmd def dir sel spc )
   (setq cmd (getvar 'cmdecho)
         dir (getvar 'dwgprefix)
         spc (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))
   )
   (setvar 'cmdecho 0)
   (while (setq def (tblnext "layer" (null def)))
       (if
           (and
               (zerop (logand (cdr (assoc 70 def)) 21))
               (setq sel (ssget "_X" (list (cons 8 (cdr (assoc 2 def))) spc)))
           )
           (vl-cmdf "_.-fbxexport" "_S" sel "" "_A" "_E" (LM:uniquefilename (strcat dir (cdr (assoc 2 def)) ".fbx")))
       )
   )
   (setvar 'cmdecho cmd)
   (princ)
)

;; Unique Filename  -  Lee Mac
;; Returns a filename suffixed with the smallest integer required for uniqueness

(defun LM:uniquefilename ( fnm )
   (if (findfile fnm)
       (apply
          '(lambda ( pth bse ext / tmp )
               (setq tmp 1)
               (while (findfile (setq fnm (strcat pth bse "(" (itoa (setq tmp (1+ tmp))) ")" ext))))
           )
           (fnsplitl fnm)
       )
   )
   fnm
)

(princ)

Link to comment
Share on other sites

Lee, if my eyes don't fool me, you forgot to add (fnsplitl fnm) sub function... I know it's dummy, but anyway, it's just me and my remark... Happy Christmas holidays and new year...

Link to comment
Share on other sites

Lee, if my eyes don't fool me, you forgot to add (fnsplitl fnm) sub function... I know it's dummy, but anyway, it's just me and my remark... Happy Christmas holidays and new year...

 

No - fnsplitl is a standard AutoLISP function :thumbsup:

 

Happy New Year to you too.

Link to comment
Share on other sites

  • 4 years later...

Very nice...

I am searching for this..

I wrote a simple autolisp shortcut n use it by freezing each layer n giving one file name every time..

You saved my time...

Thanks you 👍

Edited by Jnanashakthi
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...