Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to export layers to KML/KMZ seperately

6 REPLIES 6
Reply
Message 1 of 7
wian.meier
6831 Views, 6 Replies

Lisp to export layers to KML/KMZ seperately

Good day all,

 

I've written a LISP for AutoCAD Map 3d, but I can't seem to get the export to work correctly. I can correctly export all the layers to separate shape/Tab files, but not KML.

 

Am I using the command wrong?

 

(defun c:test (/ file nam lst table)
(vlax-for lyr
(vla-get-layers
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(setq table (cons (vla-get-name lyr) table))
)
(setq file (LM:browseforfolder "Select a folder" "C:\\" 0))

(while 
	(setq lst (car table))
	(setq nam (strcat file "\\" lst))
	(command ".-mapexport" "OGCKML" nam "_N" "_S" "_ALL" lst "*" "_N" "_Proceed")
	(setq table (cdr table))
)

)

;; Browse for Folder  -  Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.
 
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)

 

6 REPLIES 6
Message 2 of 7
CodeDing
in reply to: wian.meier

@wian.meier ,

 

What does your command history say when you run your lisp?


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 3 of 7
wian.meier
in reply to: CodeDing

This is what my command history shows, only 2 of the layers have blocks drawn in, the rest of the layers are empty.

 

Command: TEST
.-mapexport Enter file type to export to, or ? for list <OGCKML>:OGCKML Enter name of file to create <C:\Test\0>:C:\Test\5m 100 125 pole Load Profile? [Yes/No] <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_S Select objects for export [All/Manually] <All>:_ALL Enter name(s) of layer(s) to filter for objects or ? for list <*>:5m 100 125 pole Enter name(s) of class(es) to filter for objects or ? for list <*>:* Export Polygon Toplogy? [Yes/No]  <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_Proceed Processing...
"4 object(s) of 4 selected, exported in 0 sec(s).
Command: .-mapexport Enter file type to export to, or ? for list <OGCKML>:OGCKML Enter name of file to create <C:\Test\5m 100 125 pole>:C:\Test\5m 150 175 pole Load Profile? [Yes/No] <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_S Select objects for export [All/Manually] <All>:_ALL Enter name(s) of layer(s) to filter for objects or ? for list <*>:5m 150 175 pole Enter name(s) of class(es) to filter for objects or ? for list <*>:* Export Polygon Toplogy? [Yes/No]  <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_Proceed Processing...
"4 object(s) of 4 selected, exported in 0 sec(s).
Command: .-mapexport Enter file type to export to, or ? for list <OGCKML>:OGCKML Enter name of file to create <C:\Test\5m 150 175 pole>:C:\Test\4F Aerial Load Profile? [Yes/No] <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_S Select objects for export [All/Manually] <All>:_ALL Enter name(s) of layer(s) to filter for objects or ? for list <*>:4F Aerial Enter name(s) of class(es) to filter for objects or ? for list <*>:* Export Polygon Toplogy? [Yes/No]  <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_Proceed Processing...
"0 object(s) of 0 selected, exported in 0 sec(s).
Command: .-mapexport Enter file type to export to, or ? for list <OGCKML>:OGCKML Enter name of file to create <C:\Test\4F Aerial>:C:\Test\Defpoints Load Profile? [Yes/No] <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_S Select objects for export [All/Manually] <All>:_ALL Enter name(s) of layer(s) to filter for objects or ? for list <*>:Defpoints Enter name(s) of class(es) to filter for objects or ? for list <*>:* Export Polygon Toplogy? [Yes/No]  <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_Proceed Processing...
"0 object(s) of 0 selected, exported in 0 sec(s).
Command: .-mapexport Enter file type to export to, or ? for list <OGCKML>:OGCKML Enter name of file to create <C:\Test\Defpoints>:C:\Test\0 Load Profile? [Yes/No] <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_S Select objects for export [All/Manually] <All>:_ALL Enter name(s) of layer(s) to filter for objects or ? for list <*>:0 Enter name(s) of class(es) to filter for objects or ? for list <*>:* Export Polygon Toplogy? [Yes/No]  <No>:_N Change options  [Selection/Data/Options/Proceed] <Proceed>:_Proceed Processing...
"0 object(s) of 0 selected, exported in 0 sec(s).

 

Message 4 of 7
CodeDing
in reply to: wian.meier

@wian.meier ,

 

Thank you. If I am interpreting correctly, you are saying that you are getting 2 KML files but you are expecting 5?

 


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 5 of 7
wian.meier
in reply to: CodeDing

I'm expecting only 2, but the problem is these files can't be opened in google earth. When I look at the file size of the KML/KMZ it is 1kb regardless of how many objects are placed.

 

It doesn't seem to be exporting the layers correctly. When I manually export the layers with

_mapexport

it works perfectly

 

See the attached image 

 

 

 

Message 6 of 7
CodeDing
in reply to: wian.meier

@wian.meier ,

 

Can you post one of the KMZ files? I would like to see what is in it when I extract / open it with Notepad.

 

--Edit--

Better yet, IF you can upload a copy of the dwg file you're having issues with, I can see if the error duplicates when I try the same process.

 

Best,

~DD

 


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 7 of 7
braudpat
in reply to: wian.meier

Hello

 

1) Maybe a "stupid" remark !?


2) Have you tested your DWG (+ your Lisp) with a standard/classic filename for your DWG ?

Please ONLY : A-Z , 0-9 , - , _

 

3) NO Space/Blank or ANY special cars !

 

THE HEALTH (Stay Safe), Regards, Patrice

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report