Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Google EARTH Command in AutoCAD

10 REPLIES 10
Reply
Message 1 of 11
CodeDing
1654 Views, 10 Replies

Google EARTH Command in AutoCAD

Hi All,

 

I just wanted to get this command out there because I find myself using it religiously and hope that you may find it useful as well. If you use Geolocation in C3D + Google Earth Pro often, I recommend you give it a try.

 

It is the EARTH command (of my creation). You just run the command and if you have Google Earth, then it will open.. And even better, if you drawing is Geo-Located it will prompt you for a point to select to automatically navigate to in Google Earth.

 

If it seems so simple, that's the beauty of it.. Sometimes you just find yourself working in cad then all of the sudden you need to look at some stuff in Google Earth, BOOM you have a command for that. It's an easy way to just reduce the amount of navigating through the computer and typing in addresses or Lat/Longs when you're looking right at the area in AutoCAD.

 

Anyways, hope it helps somebody . It will work in Vanilla AutoCAD also but I posted here since it will primarily benefit C3D users. If you have any questions, don't hesitate to ask.

 

(defun c:EARTH ( / *error* GeoMarker PT->LL errMsg earthPath ptMid ptLL strKML fName f)
;; Opens Google Earth. If dwg is Geo-Located, attempts to open at user-specified location.
  ;; Helper Function(s)
  ;; Error handler
  (defun *error* (msg / )
    (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    );if
    (princ)
  );error defun
  (defun GeoMarker ( / ) ;; Creates arbitrary GeoMarker, returns ename
    (entmakex '((0 . "POSITIONMARKER") (100 . "AcDbEntity") (100 . "AcDbGeoPositionMarker") (90 . 0) (10 0.0 0.0 0.0) (40 . 1.0)
               (1 . "") (40 . 0.5) (290 . 0) (280 . 0) (290 . 1) (101 . "Embedded Object") (100 . "AcDbEntity") (100 . "AcDbMText")
               (10 0.1 0.1 0.0) (40 . 1.0) (1 . "") (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 . 9761.9) (43 . 6666.67)))
  );GeoMarker defun
  (defun PT->LL (pt / e luprec return) ;; Returns Longitude & Latitude of point provided
    (if (setq e (GeoMarker))
      (progn
        (setq e (vlax-ename->vla-object e))
        (vlax-put-property
          e
          'Position
          (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 2)) pt))
        );vlax
        (setq luprec (getvar 'LUPREC))
        (setvar 'LUPREC 8)
        (setq return
          (mapcar
            'atof
            (list (vla-get-Longitude e) (vla-get-Latitude e) "0.")
          );mapcar
        );setq
        (setvar 'LUPREC luprec)
        (vla-delete e)
        return
      );progn
    );if
  );PT->LL defun
  ;; Initial checks
  (cond
    ((not (setq earthPath (vl-registry-read "HKEY_LOCAL_MACHINE\\SOFTWARE\\Google\\Google Earth Pro" "InstallLocation")))
      (setq errMsg "\nCould not locate Google Earth application.")
    );cond 1
    ((not (eq "Model" (getvar 'CTAB))) (setq errMsg "\nMust be in Model space to select location."))
    ((eq "" (getvar 'CGEOCS)) (setq errMsg "\nDrawing is not Geo-Located."))
  );cond
  (if earthPath (setq earthPath (strcat earthPath "googleearth.exe")))
  ;; Open Earth now if path found and error found, or test for other error.
  (cond
    ((and earthPath errMsg) (startapp earthPath) (prompt errMsg) (exit))
    (errMsg (prompt errMsg) (alert errMsg) (exit))
  );cond
  (prompt "\nPreparing to open location in Google Earth...")
  ;; User-selected or arbitrary mid point of project data
  (setq ptMid
    (cond ((getpoint "\nSelect Point or (Enter) for default: "))
          ((getvar 'VIEWCTR))
    );cond
  );setq
  ;; Transform to Lat Long
  (setq ptLL (PT->LL ptMid))
  (print ptLL)
  ;string for KML file
  (if *earth_marker_count*
    (setq *earth_marker_count* (1+ *earth_marker_count*))
    (setq *earth_marker_count* 1)
  );if
  (setq strKML
    (strcat
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"
" <Placemark>"
" <name>" (getvar 'DWGNAME) " (" (itoa *earth_marker_count*) ")</name>"
" <Point>"
" <coordinates>" (rtos (car ptLL) 2 7) "," (rtos (cadr ptLL) 2 7) ",0</coordinates>"
" </Point>"
" </Placemark>"
"</kml>" );strcat );setq ;; Write string to KML file (setq fName (vl-filename-mktemp "C3D" nil ".kml")) (write-line strKML (setq f (open fName "w"))) (close f) ;; Open KML in Google Earth (startapp earthPath fName) (prompt "\nEARTH Complete.") (princ) );defun

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
10 REPLIES 10
Message 2 of 11
cwr-pae
in reply to: CodeDing

This will be handy, thanks for posting it.

Just for reference I attached a lsp someone posted that does the same thing though google maps. The header never had the creator's name. I did change the command name to gsv for convenience in use.

Message 3 of 11
cwr-pae
in reply to: CodeDing

And here are the 3 original lsp with long names and everything. I'm not sure of all the differences.

Message 4 of 11
cneely
in reply to: CodeDing

I really like this lisp! Any chance you could make a companion lisp that when it takes the user to the location it would enter Street View in Google Earth? I have the one for Street View in a browser but would prefer Street View in GE.

Thanks!

AEC Collection 2022
WIN 10 PRO
Dell 3650, Intel i9-11900k @ 3.50GHz, 64 GB
NVIDIA QUADRO RTX 4000
http://www.cobbfendley.com
Message 5 of 11
CodeDing
in reply to: cneely

Thank you @cneely.

 

However, I cannot think of a way to incorporate exactly what you're asking for. The current program creates a KML file and opens that KML file via Google Earth. With the limitations of Lisp & the GE Pro API, I cannot think of a way to open Street View within GE Pro via a KML file or Lisp routine 😕

 

If I think of some way or find a solution I will come back to update. But I am not optimistic.

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 6 of 11
kidznok
in reply to: cwr-pae

Hi,

Is it possible to change this one for Bricscad?
I have 
" error : no function definition <ADE_PROJGETWSCODE> ; expected FUNCTION at [eval]"

Message 7 of 11
CodeDing
in reply to: kidznok

@kidznok ,

 

Try deleting this line. Should let you continue. I'm not very familiar with Bricscad, so I probably couldn't help much further.

 

Delete this line:

    ((eq "" (getvar 'CGEOCS)) (setq errMsg "\nDrawing is not Geo-Located."))

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 8 of 11
kidznok
in reply to: CodeDing

Thank You but still nothing.

I have question... Should I set geolocation in file? Could this work with one zone? And then when I pick point lisp can calculate geografic coordination and next use this to show GSView? 

Message 9 of 11
CodeDing
in reply to: kidznok

@kidznok ,

 

The code I posted will not work with Google Street View. Are you referring to a code that someone else posted here? I have not used them.

 

EDIT:

Ahhh, now I see  you were referring to the code from Message 2

 

I do not know what your best approach is. The difficult part is getting a Latitude and Longitude from the program. Do you know how to do that? Because once you do that, it's just as simple as a URL call to a browser.

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 10 of 11
cwr001
in reply to: CodeDing

This is great stuff! Thanks a lot for sharing!

Message 11 of 11
adaptacad
in reply to: CodeDing

Hello, @CodeDing . This approach can be effective, however, I am not familiar with creating a fixed box on the side in AutoCAD. You will likely need to use the Google Street View API to integrate this functionality.

https://www.cadtutor.net/forum/topic/68011-showhtmlmodalwindow-block-or-browser/ 

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report