Jump to content

Recommended Posts

Posted

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.

Posted

This is similar but allows you to pick a surface and return its name, the vercheck does same as your get registry just a different variable name.

 

(ah:vercheck)  ; version check see vercheck.lsp
(if (not AT:ListSelect)(load "Listseelct"))
      
(vlax-for j (vlax-get *AeccDoc* 'SurfaceS)
(setq lst (cons (cons (vla-get-name j) j) lst))
) 

;if length of surfaces more than 1 else skip pick  if  0 then msg and exit
(setq lenlst (length lst))

(if (= lenlst 0)
    (progn
    (Getstring "\nYou have no surfaces press any key to exit")
    (exit)
    )
)


(if (= lenlst 1)
  (setq surfacepick (car (nth 0 lst)))  ; pull surface out of dotted pair
)

(if (> lenlst 1)
  (progn
  (setq surfacepick (car (AT:ListSelect
    "Set new surface "
    "Select surface name"
    10
    10
    "false"
    (vl-sort (mapcar (function car) lst) '<)
  )))
  ) ; end progn  
) ;end if

(setq lst2 lst)     ; make answer returned list2

listselect.lspFetching info...

Listselect.jpg.2c51c43b272d573a0f8e485dd5a6e288.jpg

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