Refreshing the AutoCAD JavaScript API Tool Palette

Refreshing the AutoCAD JavaScript API Tool Palette

adaptacad
Advocate Advocate
251 Views
1 Reply
Message 1 of 2

Refreshing the AutoCAD JavaScript API Tool Palette

adaptacad
Advocate
Advocate

How can I refresh the Tool Palette in the AutoCAD JavaScript API? I'm developing a program that displays Street View in a side Tool Palette. To achieve this, I create a temporary HTML and JS file and call it using the WEBLOAD command. However, I'm having difficulties in closing, opening, or refreshing this Tool Palette. Is it possible to do so? Would it be feasible to use a reactor for this purpose?

(defun c:STREETVIEW nil

  (defun :radianos->graus (rad)
    (* (/ rad pi) 180.0)
  )
  (defun :limitematematico ( ang )
    (rem (+ (rem ang (+ pi pi)) pi pi) (+ pi pi))
  )
  
  (if (setq del (ssget "_X" '((2 . "Sreetview"))))
    (if (> (sslength del) 1)
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex del)))
        (entdel ent)
      )
      (progn
        (setq entst (car (vl-remove-if 'listp (mapcar 'cadr (ssnamex del)))))
        (setq objst (vlax-ename->vla-object entst))
        (setq pntst (vlax-get objst 'insertionpoint))
        (command "_.Move" entst ""  pntst )
      )      
    )
      (vl-cmdf "_.Insert" "Sreetview" pause 1 1 pause)
      
    
  );;tratar erro
  
  (if (setq obj (vlax-ename->vla-object(entlast)))
        (progn
          (if *updateobjectreactor* (vlr-remove *updateobjectreactor*))
          (setq *updateobjectreactor*
            (vlr-object-reactor
              (list obj)
              (setq dat (list (vlax-get obj 'insertionpoint) (vlax-get obj 'rotation)))
              '((:vlr-modified . :retornoatualizacaomodificado))
            )
          )
          (setq new (list (car dat) (cadr dat)))
        )
      )
  
  (setq obj (vlax-ename->vla-object(entlast)))
  (setq dat (list (vlax-get obj 'insertionpoint) (vlax-get obj 'rotation)))
  (setq ang (:radianos->graus (:limitematematico (- (* 0.5 pi) (cadr dat)))))
  (setq htmlfile_ (:CreateHTMLFile (rtos (cadr (car dat)) 2 8) (rtos (car (car dat)) 2 8) (rtos ang 2 0)))
  (setq jsfile_ (:CreateJSFile htmlfile_))
  (command "_.WEBLOAD" "_l" jsfile_)
)

(defun :retornoatualizacaomodificado (obj rea lst / dat)
  (if (and (vlax-read-enabled-p obj) (setq dat (list (vlax-get obj 'insertionpoint)(vlax-get obj 'rotation))) (not (equal dat (vlr-data rea) 1e-8)))
    (progn
      (vlr-data-set rea dat)
      (:atualizarmudancadevista (car dat) (cadr dat))
    )
    (dos_htmlboxex t)
  )
)

(defun :CreateHTMLFile (latitude longitude angulo / str htmlFile f)
  (setq str
    (strcat
      (strcat
        "<!DOCTYPE html>"
        "\n<html lang=\"en\">"
        "\n<head>"
        "\n<meta charset=\"UTF-8\">"
        "\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
        "\n<style>"
        "\n#map {"
        "\nheight: 100vh;"
        "\nwidth: 100%;"
        "\n}"
        "\n</style>"
        "\n</head>"
        "\n<body>"
        "\n<div id=\"map\"></div>"
        "\n<script>"
        "\nfunction initMap() {"
        "\nvar panorama = new google.maps.StreetViewPanorama("
        "\ndocument.getElementById('map'),"
        "\n{"
        "\nposition: {lat: "  latitude ", lng: " longitude "},"
        "\npov: {heading: " angulo  ", pitch: 0},"
        "\nzoom: 1"
        "\n}"
        "\n);"
        "\n// Adicionando controles de navegação"
        "\nvar streetViewControl = new google.maps.StreetViewControl();"
        "\npanorama.controls[google.maps.ControlPosition.TOP_RIGHT].push(streetViewControl);"
        "\n}"
        "\n</script>"
        "\n<script src=\"https://maps.googleapis.com/maps/api/js?key=YOURAPIKEY&callback=initMap\" async defer></script>"
        "\n</body>"
        "\n</html>"
      );strcat
    );strcat
  );setq
  (setq htmlFile (strcat (vl-filename-mktemp "file_" ".html") ".html"))
  (setq f (open htmlFile "w"))
  (write-line str f)
  (close f)
  htmlFile
);defun

(defun :CreateJSFile (htmlFile / str jsFile f)
  (setq str
    (strcat "Acad.Application.addPalette(\"Streetview\", \""
            (vl-string-translate "\\" "/" htmlFile)
            "\");"
    );strcat
  );setq
  (setq jsFile (strcat (vl-filename-mktemp "file_" ".js") ".js"))
  (setq f (open jsFile "w"))
  (write-line str f)
  (close f)
  jsFile
);defun

 

0 Likes
252 Views
1 Reply
Reply (1)
Message 2 of 2

CodeDing
Advisor
Advisor

@adaptacad ,

 

The underlying problem is that there's no way to retrieve the Tool Palette (the host of the HTML document) to refresh the page. I've struggled with this idea before and could not find a way to solve it. 

 

So your only likely solutions would be:

- code an automatic refresh via JS into your HTML page

- Create a Tool Palette via .NET so you can ultimately have control over the object hosting your HTML page.

 

Best,

~DD

0 Likes