Jump to content

Help: Hashcode from dxf file


mhy3sx

Recommended Posts

Hi, I want  to export hash code SHA-512 from dxf file . The code works but I want to do two updates. I know that will ask what are you hiding and why you do this  etc... so I will explain that some drawings saved as dxf with the hashcode  then convert to zip file and upload to gov webpage. So I am trying to do this fast.

 

1) the fist change I want to do is that I want low letters not caps in the hashcode. I don't know how to do it !!

 

the code export hash code like this
D00EB86B0E2E4A3ED990A98B0D0A75E4CD33A947D3E2C916CECA9329D477E71D9C0C77B8A0117C81DE271B5B4120F5A882369ABDA8105B8583ED5269416C533F

And I want o export like 
d00eb86b0e2e4a3ed990a98b0d0a75e4cd33a947d3e2c916ceca9329d477e71d9c0c77b8a0117c81de271b5b4120f5a882369abda8105b8583ed5269416c533f

 

2) The second is that print the hashcode to command line. Is it possible to export a pdf file with the hash code  with name hashcode.pdf in the same path with the open dxf file?

 

here is the code

 

(defun c:sha512HASH ( / file-path hash-value )

  ;; Prompt user to select a file
  (setq file-path (getfiled "Select a file to hash" "" "dxf" 0))
  
  
  ;; Check if a file was selected
  (if file-path
    (progn
      ;; Generate SHA-512 hash using PowerShell
      (setq hash-value (run-powershell-command file-path))
      
      ;; Display the hash value
      (princ (strcat "\nSHA-512 Hash: " hash-value))
    )
    (princ "\nNo file selected.")
  )
  (princ)
)



(defun run-powershell-command (file-path / ws str output result exec stdOut)
  (setq ws (vlax-get-or-create-object "WScript.Shell"))
  (setq str (strcat "Powershell.exe -WindowStyle Hidden Get-FileHash -Algorithm SHA512 -Path '" file-path "' | Select-Object -ExpandProperty Hash"))
  (setq output "")
  (setq result (vl-catch-all-apply
                 '(lambda ()
                    (setq exec (vlax-invoke ws 'exec str))
                    (setq stdOut (vlax-get exec 'StdOut))
                    (setq output (vlax-invoke stdOut 'ReadAll))
                  )
               ))
  (vlax-release-object ws)
  (if (vl-catch-all-error-p result)
    (progn
      (princ "\nError generating hash.")
      nil
    )
    (substr output 1 (- (strlen output) 2))
  )
)

 

Link to comment
Share on other sites

Hi exceed

I try

 

(princ (strcat "\nSHA-512 Hash: " hash-value T))

;Error: invalid argument type: stringp: T

 

Link to comment
Share on other sites

(princ (strcat "\nSHA-512 Hash: " (strcase hash-value T)))

strcat and strcase is different

  • Like 1
Link to comment
Share on other sites

      (setq hash512 (strcase hash-value T))
      ;; Display the hash value
      (princ (strcat "\nSHA-512 Hash: " hash512))

ok I find it

Link to comment
Share on other sites

You can zip and unzip using lisp.

Unzip

(getfiled "Select the File \"Cad tools 5-03-2024\"" "" "ZIP" 16))
(startapp (strcat "powershell -command Expand-Archive -Path '" filename "' -DestinationPath 'C:/CAD-TOOLS' -FORCE"))

 

Zip 

I know I have it somewhere it uses -command Compress-Archive

# Create a zip file with the contents of C:\Stuff\
Compress-Archive -Path C:\Stuff -DestinationPath archive.zip

# Add more files to the zip file
# (Existing files in the zip file with the same name are replaced)
Compress-Archive -Path C:\OtherStuff\*.txt -Update -DestinationPath archive.zip

# Extract the zip file to C:\Destination\
Expand-Archive -Path archive.zip -DestinationPath C:\Destination

 

Edited by BIGAL
Link to comment
Share on other sites

Posted (edited)

Hi BIGAL is possible to export the hashcode to pdf file with name Hashcode and save it to the same place with the dxf file?

 

Thanks

Edited by mhy3sx
Link to comment
Share on other sites

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