Export the surface to an .xml file using LISP

Export the surface to an .xml file using LISP

rdzyundzya
Contributor Contributor
519 Views
0 Replies
Message 1 of 1

Export the surface to an .xml file using LISP

rdzyundzya
Contributor
Contributor

Hi, I’m trying to automate exporting a surface to an .xml file by creating a LISP function for it. But so far, no success... Can you tell me if this is even possible?

(defun ExportSurfaceToLandXML ( surfaceName saveFolder / C3D verstring prodstring datastr acadApp C3D civilDoc surfs landXMLTools surface filePath )
;------------------
(vl-load-com)
;------------------
; Example (ExportSurfaceToLandXML "TIN_example" "C:\\Users\\surfl\\Desktop\\New_folder")
;------------------
(setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
                    (if vlax-user-product-key
                      (vlax-user-product-key)
                      (vlax-product-key)
                    )
            )
        C3D (vl-registry-read C3D "Release")
        verstring (substr C3D
                          1
                          (vl-string-search
                            "."
                            C3D
                            (+ (vl-string-search "." C3D) 1)
                          )
            )
        prodstring (strcat "AeccXUiLand.AeccApplication." verstring)
  )
(setq datastr (strcat "AeccXLand.AeccTinCreationData." verstring))
;--------------------
(if (and (setq acadApp (vlax-get-acad-object))
           (setq C3D (vla-getinterfaceobject acadApp prodstring))
           (setq civilDoc (vla-get-activedocument C3D))
           (setq surfs (vlax-get civilDoc 'surfaces)))
(progn
    
    (if (not (vlax-property-available-p civilDoc "LandXMLTools"))
        (progn
            (alert "This is not a Civil 3D document or LandXMLTools are not available!")
            (exit)
        )
    )
    
    ; Get LandXML tools
    (setq landXMLTools (vla-get-LandXMLTools civilDoc))
    
    ; Trying to find a surface by name
    (setq surface (vl-catch-all-apply 
        '(lambda () 
            (vla-Item (vla-get-Surfaces landXMLTools) surfaceName)
        )
    ))
    
    ; Checking if the surface is found
    (if (vl-catch-all-error-p surface)
        (progn
            (alert (strcat "Surface with name '" surfaceName "' not found!"))
            (exit)
        )
    )
    
    ; Create a full path to the file
    (setq filePath (strcat saveFolder "\\" surfaceName ".xml"))
    
    ; Exporting the surface to LandXML
    (vl-catch-all-apply 
        '(lambda () 
            (vla-ExportSurface surface filePath)
        )
    )
    
    ; Checking the success of export
    (if (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (findfile filePath))))
        (alert (strcat "Error exporting surface to file: " filePath))
        (alert (strcat "The surface has been successfully exported to file: " filePath))
    )
    
    ; Returning the path to the file
    filePath
); end of progn
); end of if
); end of defun

Most likely, I'm using the wrong Visual LISP functions.

 

0 Likes
520 Views
0 Replies
Replies (0)