+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Forum Newbie mzlink's Avatar
    Using
    AutoCAD 2017
    Join Date
    Jan 2017
    Posts
    3

    Default Export each layer to separate FBX file (AutoCAD 2017)

    Registered forum members do not see this ad.

    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
    Code:
    (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))
         '(8)
      ) ; 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.

  2. #2
    Senior Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    295

    Default

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

  3. #3
    Forum Newbie mzlink's Avatar
    Using
    AutoCAD 2017
    Join Date
    Jan 2017
    Posts
    3

    Default

    Quote Originally Posted by Roy_043 View Post
    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?

  4. #4
    Senior Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    295

    Default

    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:
    Code:
    (command "_.-FBXEXPORT" ...)
    Your code sample would have to be completely rewritten.
    BricsCAD 16

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,962

    Default

    Try the following:
    Code:
    (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)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    1,120

    Default

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

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,962

    Default

    Quote Originally Posted by marko_ribar View Post
    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

    Happy New Year to you too.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Forum Newbie mzlink's Avatar
    Using
    AutoCAD 2017
    Join Date
    Jan 2017
    Posts
    3

    Default

    Quote Originally Posted by Lee Mac View Post
    Try the following: [#CODE]
    Works perfectly. Tyvm

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,962

    Default

    Quote Originally Posted by mzlink View Post
    Works perfectly. Tyvm
    Excellent - you're welcome!
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    739

    Default

    Registered forum members do not see this ad.

    That LM:uniquefilename is cleverly written, I like it!

Similar Threads

  1. Export/transfer the workspace in Autocad 2017
    By Icemax76 in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 0
    Last Post: 6th Dec 2016, 01:57 pm
  2. save each layer in a separate file
    By x.bonnet in forum AutoLISP, Visual LISP & DCL
    Replies: 47
    Last Post: 25th Nov 2016, 12:07 am
  3. What's New in AutoCAD 2017 – AutoCAD 2017 Preview Guide
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 3
    Last Post: 26th Mar 2016, 12:14 am
  4. AutoCAD 2017 File Format
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 22nd Mar 2016, 04:00 am
  5. help me to create lisp to export multiple DWG to separate PDF
    By mostafa badran in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 4th Oct 2013, 04:27 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts