Author Topic: Help with a lisp routine that compares the file version & software version...  (Read 3203 times)

0 Members and 1 Guest are viewing this topic.

cyclops

  • Newt
  • Posts: 22
I am looking for lisp routine that compares the drawing file version & software version, the problem is, I have users who double click drawings and open 2012 C3D files in 2014 C3D then save their work.

The routine would compare the variable "acadver" with the output from the "aecdwgversion" command, if the file and software don't agree, an alert dialog box is put on the screen.

Just really looking for a big alert dialog box to annoy the users into paying attention to what they are about to do.

If the dialog box has a "Close File" button that closes the drawings without saving and an OK button that pops an "ARE YOU SURE" alert and then pops another "ARE YOU REALLY SURE" alert, that would be great. Or an OK button that moves away when the user goes to click it.

Thanks in advance for the help..
Cy
It's 'O'Neill', with three L's!!!! (Jack O'Neill)

mailmaverick

  • Bull Frog
  • Posts: 493
My take :

Code: [Select]
(defun c:test ()
  (setq acadverlist
'((15.0 . "2000")
   (15.6 . "2002")
   (16.0 . "2004")
   (16.1 . "2005")
   (16.2 . "2006")
   (17.0 . "2007")
   (17.1 . "2008")
   (17.2 . "2009")
   (18.0 . "2010")
   (18.1 . "2011")
   (18.2 . "2012")
   (19.0 . "2013")
   (19.1 . "2014")
   (20.0 . "2015")
  )
  )
  (setq closefile nil)
  (if (zerop (getvar 'dwgtitled))
    (progn (princ "\nThe current drawing is unsaved."))
    (progn (setq filever (vl-princ-to-string (LM:dwgversion (strcat (getvar 'dwgprefix) (getvar 'dwgname)))))
   (setq acadver (cdr (assoc (atof (getvar "ACADVER")) acadverlist)))
   (if (not (vl-string-search acadver filever))
     (progn (setq df (acet-ui-message
       (strcat "Drawing file of version " filever " opened in CAD Version " acadver "\n\nDo you wish to proceed ?")
       "Warning !!"
       4
     )
    )
    (if (equal df 6)
      (progn (setq df (acet-ui-message "Are you sure you wish to proceed ?" "Warning !!" 4))
     (if (equal df 6)
       (progn (setq df (acet-ui-message "Are you still sure you wish to proceed ?" "Warning !!" 4))
      (if (not (equal df 6))
(setq closefile T)
      )
       )
       (progn (setq closefile T))
     )
      )
      (progn (setq closefile T))
    )
     )
   )
   (if closefile
     (command "_.close")
   )
    )
  )
  (princ)
)

;; Drawing Version  -  Lee Mac
;; Returns the version of the supplied filename (dwg/dws/dwt/dxf)

(defun LM:dwgversion (fn / fd vr)
  (cond ((null (and (setq fn (findfile fn)) (setq fd (open fn "r")))))
((wcmatch (strcase fn t) "*`.dw[gst]") (setq vr (strcase (substr (read-line fd) 1 6))))
((wcmatch (strcase fn t) "*`.dxf") (repeat 7 (read-line fd)) (setq vr (strcase (read-line fd))))
  )
  (if (= 'file (type fd))
    (close fd)
  )
  (cdr (assoc vr
      '(("AC1027" . "2013-2015")
("AC1024" . "2010-2012")
("AC1021" . "2007-2009")
("AC1018" . "2004-2006")
("AC1015" . "2000-2002")
("AC1014" . "Release 14")
("AC1012" . "Release 13")
("AC1009" . "Release 11/12")
("AC1006" . "Release 10")
("AC1004" . "Release 9")
("AC1003" . "Release 2.60")
("AC1002" . "Release 2.50")
("AC1001" . "Release 2.22")
("AC2.22" . "Release 2.22")
("AC2.21" . "Release 2.21")
("AC2.10" . "Release 2.10")
("AC1.50" . "Release 2.05")
("AC1.40" . "Release 1.40")
("AC1.2" . "Release 1.2")
("MC0.0" . "Release 1.0")
       )
       )
  )
)



Run by typing TEST.

« Last Edit: March 15, 2015, 02:40:01 PM by mailmaverick »

cyclops

  • Newt
  • Posts: 22
Mailmaverick,
When running "test" in C3D 2014, on a newly opened file, I get the following:
"error: bad argument type: (or stringp symbolp):"

When running "test" in C3D 2012, I get the same response as C3D 2014,
but if changes have been made, I get "The current drawing is unsaved."

I understand in C3D 2012 why is am getting "The current drawing is unsaved." because in my startup, I have system variable being set each time the users open a drawing, I do this to provide my users with a consistent drafting experience.

Will "test" work without the "The current drawing is unsaved" code, because the drawing will always be in that state on opening? The plan is to put "Test" in the startup before any system variables are changed, so the users can quit prior to changes.

The rest of the code looks to address the other needs but until the "error: bad argument..." is resolved, I can not test.

Thanks for the help.
Cy
It's 'O'Neill', with three L's!!!! (Jack O'Neill)

ronjonp

  • Needs a day job
  • Posts: 7529
Try changing this line:
Code: [Select]
(setq filever (LM:dwgversion (strcat (getvar 'dwgprefix) (getvar 'dwgname))))To this:
Code: [Select]
(setq filever (vl-princ-to-string (lm:dwgversion (strcat (getvar 'dwgprefix) (getvar 'dwgname)))))

More to read about AutoCAD version HERE too :)
« Last Edit: March 10, 2015, 09:50:27 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
I understand in C3D 2012 why is am getting "The current drawing is unsaved." because in my startup, I have system variable being set each time the users open a drawing, I do this to provide my users with a consistent drafting experience.
Note that the system variable DWGTITLED is read-only. You should only receive the message if your drawing has not been saved yet.

To solve the 'stringp' problem I would first check the C3D 2014 ACADVER value against the acadverlist.

Edit: While I was writing this, ronjonp has added a useful link to his message regarding ACADVER.
« Last Edit: March 10, 2015, 10:10:07 AM by roy_043 »