Author Topic: Part of lisp to find out which AutoCAD vertical is running  (Read 8659 times)

0 Members and 1 Guest are viewing this topic.

zride91

  • Guest
Part of lisp to find out which AutoCAD vertical is running
« on: August 28, 2014, 11:49:16 AM »
We are using the ACAD.lsp to drive our support paths in AutoCAD, in 2015 it looks like AutoCAD, AutoCAD MEP, and Civil 3D all use the same installed program directory, so if all (3) products are installed on one machine, our current ACAD.lsp files are not going to work, as they are unique per product. and AutoCAD is not going to know what to run, just the first it sees in the AutoCAD Support folder.

I am trying to write a condition statement in the beginning of our ACAD.lsp that would give us the ability to merge all (3) ACAD.lsp files into (1) by finding out which product is running.

I was thinking of using the (getvar "ROAMABLEROOTPREFIX") to identify what product is running, because even though all (3) products are installed in the same location, the user specific roamable root prefix is unique, where MEP and Civil 3D would be in the folder names.

I was thinking of something like the little lisp below that I was trying to see if the concept worked, but I am missing something even on this, as it is not working for me.

I am not very familiar with the lisp and figure I am missing some kind of syntax.  If anyone has ideas on getting the below to work, or any other ideas on how to work with the ACAD.lsp with multiple verticals installed, I am all ears.

Code: [Select]
(defun C:TEST (/)

(cond (((getvar "ROAMABLEROOTPREFIX")="*C3D*") (princ "\nTHIS IS CIVIL 3D!!!!"))
      (((getvar "ROAMABLEROOTPREFIX")="*MEP*") (princ "\nTHIS IS AutoCAD MEP!!!!"))
  (t (princ "\nTHIS IS AutoCAD!!!!"))
)

)

Thank you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #1 on: August 28, 2014, 11:57:25 AM »
(vlax-product-key)
;;--> "Software\\Autodesk\\AutoCAD\\R20.0\\ACAD-E001:409"

You'll need to run a conditional test based on this data :

http://adndevblog.typepad.com/autocad/2013/08/registry-values-for-productid-and-localeid-for-autocad.html


added:
the function has been cloned as (VLAX-MACHINE-PRODUCT-KEY) recently.
the (vlax-product-key) may become deprecated.
« Last Edit: August 28, 2014, 12:11:42 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #2 on: August 28, 2014, 12:02:26 PM »
This works, but maybe not as you would like. If I use the shortcut "Civil3D 2015 as Autocad" this still results in a "This is Civil 3d!".
Code - Auto/Visual Lisp: [Select]
  1. (defun C:TEST (/)
  2.  
  3. (cond ((wcmatch (getvar "ROAMABLEROOTPREFIX") "*C3D*") (princ "\nTHIS IS CIVIL 3D!!!!"))
  4.       ((wcmatch (getvar "ROAMABLEROOTPREFIX") "*MEP*") (princ "\nTHIS IS AutoCAD MEP!!!!"))
  5.           (t (princ "\nTHIS IS AutoCAD!!!!"))
  6. )
  7.  
  8. )

I had something in lisp that worked well for this, I will try to locate it.

zride91

  • Guest
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #3 on: August 28, 2014, 12:10:01 PM »
Thank you Jeff and Kerry!! 

Jeff, I was missing the wcmatch, this made my little test lisp work as I wanted.
I do know that running Civil 3D as AutoCAD will still register as Civil 3D.  I am hoping to get rid of that shortcut with 2015 so it will not be a problem.

Kerry, using the product codes is a neat idea, I will try this out as well.

BlackBox

  • King Gator
  • Posts: 3770
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #4 on: August 28, 2014, 12:21:03 PM »
(vlax-product-key)
;;--> "Software\\Autodesk\\AutoCAD\\R20.0\\ACAD-E001:409"

You'll need to run a conditional test based on this data :

http://adndevblog.typepad.com/autocad/2013/08/registry-values-for-productid-and-localeid-for-autocad.html


added:
the function has been cloned as (VLAX-MACHINE-PRODUCT-KEY) recently.
the (vlax-product-key) may become deprecated.

I usually add something like this to support both adaptations; User hive in this example:

Code - Auto/Visual Lisp: [Select]
  1. ;; ...
  2.         (if vlax-user-product-key                                       ; If 2013+
  3.           (vlax-user-product-key)                                       ; Use new function
  4.           (vlax-product-key)                                            ; Use legacy function
  5.         )
  6. ;; ...
  7.  
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #5 on: August 28, 2014, 12:30:30 PM »
Here's another:

(defun c:test (/ path)
  (cond   ((null (setq path (findfile "acad.exe"))) (princ "\nUKNOWN!"))
   ((wcmatch path "*3D*") (princ "\nTHIS IS CIVIL 3D!!!!"))
   ((wcmatch path "*MEP*") (princ "\nTHIS IS AutoCAD MEP!!!!"))
   ((princ "\nTHIS IS AutoCAD!!!!"))
  )
)
« Last Edit: August 28, 2014, 12:55:23 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #6 on: August 28, 2014, 12:45:13 PM »
Ron, that no longer works in 2015, as all Verticals now install to the same folder and use the same acad.exe. The vertical specific files are in subfolders:
C:\Program Files\Autodesk\AutoCAD 2015\C3D
C:\Program Files\Autodesk\AutoCAD 2015\ACA
C:\Program Files\Autodesk\AutoCAD 2015\MEP

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #7 on: August 28, 2014, 12:51:43 PM »
Good to know, Thanks  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #8 on: August 28, 2014, 12:55:48 PM »
Could you not use:
Code - Auto/Visual Lisp: [Select]
  1. (getvar 'product)

Or have I overlooked something?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #9 on: August 28, 2014, 01:04:28 PM »
Could you not use:
Code - Auto/Visual Lisp: [Select]
  1. (getvar 'product)

Or have I overlooked something?
Lee,

From my quick test, (getvar 'product) displays "AutoCAD" for both C3D 2014 and AutoCAD 2015.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

zride91

  • Guest
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #10 on: August 28, 2014, 01:05:25 PM »
Lee Mac, when I just put (getvar 'product) in the Civil 3D command line, it just returns "AutoCAD".  I'll look more into this variable though as it does seem to be the most logical to use. 

I had defaulted to the roamablerootprefix because it was already in out acad.lsp (autocad uses it out of the box to define some of the support paths) and I knew it gave me something I could work with.

Thank you all for the very quick responses, this should do quite nicely :)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #11 on: August 28, 2014, 01:08:06 PM »
Could you not use:
Code - Auto/Visual Lisp: [Select]
  1. (getvar 'product)

Or have I overlooked something?
Lee,

From my quick test, (getvar 'product) displays "AutoCAD" for both C3D 2014 and AutoCAD 2015.

I see - I didn't have access to a Vertical in which to test - thanks Ron  :-)

Another suggestion:
Code - Auto/Visual Lisp: [Select]

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #12 on: August 28, 2014, 01:26:40 PM »
I was thinking the same thing, but you'd have to check (getenv "ShowFullPathInTitle") too because a drawing name could throw off the test  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #13 on: August 28, 2014, 01:39:08 PM »
I was thinking the same thing, but you'd have to check (getenv "ShowFullPathInTitle") too because a drawing name could throw off the test  :)

Good point - I guess you could ensure the match isn't enclosed in square brackets, but I agree that it could be tricky.

zride91

  • Guest
Re: Part of lisp to find out which AutoCAD vertical is running
« Reply #14 on: August 28, 2014, 03:23:30 PM »
Thanks again all, I was able to get the acad.lsp merged to the one file and it works beautifully with the multiple flavors of AutoCAD installed.  Next deployment I am thinking to use Kerry's suggestion to the product code so this can differentiate the different year versions of AutoCAD too (even though I could modify my wcmatch parameters as well).  As Jeff mentioned, this will apply the Civil 3D config if you run Civil 3D as AutoCAD, but with the AutoCAD workspace now in Civil 3D, I will remove the shortcuts after install as I don't see the need for it.  Thank you again for all the help and the little bit of time you replied in!  8-)

Code: [Select]
(vl-load-com)

;; This sets a reference to the install path of your product
(setq acadloc
   (vl-registry-read
      (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key))
   "ACADLOCATION")
)

;; This sets a reference to the files portion of the acad preferences
(setq *files*
(vla-get-files
  (vla-get-preferences (vlax-get-acad-object))
))

;; This builds the string of Support File Search Paths depending of the version of AutoCAD product
(cond ((wcmatch (getvar "ROAMABLEROOTPREFIX") "*C3D*")
      (setq sfsp
       (strcat
        (getvar "ROAMABLEROOTPREFIX") "SUPPORT;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\StartupLisp\\2015;"
acadloc "\\SUPPORT;"
        acadloc "\\SUPPORT\\en-us;"
        ;;acadloc "\\FONTS;"
        acadloc "\\HELP;"
        acadloc "\\EXPRESS;"
        acadloc "\\SUPPORT\\COLOR;"
        acadloc "\\CIVIL;"
        acadloc "\\bin\\fdo;"
        "C:\\programdata\\autodesk\\c3d 2015\\enu\\data\\symbols\\mvblocks;"
        "C:\\program files\\autodesk\\applicationplugins\\acworkflow.bundle\\contents\\win64;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\Fonts;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Pats;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Lisp;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Lisp\\SteelShapes;"
        "C:\\Program Files\\Autodesk\\AutoCAD Raster Design 2015\\;"
        "C:\\Program Files\\Autodesk\\AutoCAD Raster Design 2015\\Help;"
        )
   )
   )
      ((wcmatch (getvar "ROAMABLEROOTPREFIX") "*MEP*")
  (setq sfsp
       (strcat
        "K:\\CAD\\2_Configurations\\AutoCAD\\StartupLisp\\2015;"
        (getvar "ROAMABLEROOTPREFIX") "SUPPORT;"
        (getvar "ROAMABLEROOTPREFIX") "SUPPORT\\PATS;"
        acadloc "\\SUPPORT;"
        acadloc "\\SUPPORT\\en-US;"
        ;;acadloc "\\FONTS;"
        acadloc "\\HELP;"
        acadloc "\\EXPRESS;"
        acadloc "\\SUPPORT\\COLOR;"
        acadloc "\\ACA;"
        acadloc "\\MEP;"
        "C:\\ProgramData\\Autodesk\\MEP 2015\\enu\\Layers\\;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Pats;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\Fonts;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Lisp;"
        "C:\\Program Files\\Autodesk\\AutoCAD Raster Design 2015\\;"
        "C:\\Program Files\\Autodesk\\AutoCAD Raster Design 2015\\Help;"
        )
   )
   )
  (t
  (setq sfsp
       (strcat
        "K:\\CAD\\2_Configurations\\AutoCAD\\StartupLisp\\2015;"
        (getvar "ROAMABLEROOTPREFIX") "SUPPORT;"
        acadloc "\\SUPPORT;"  ;acadloc "\\FONTS;"
        acadloc "\\HELP;"
        acadloc "\\EXPRESS;"
        acadloc "\\SUPPORT\\COLOR;"
        "C:\\Program Files\\Autodesk\\AutoCAD Raster Design 2015\\;"
        "C:\\Program Files\\Autodesk\\AutoCAD Raster Design 2015\\Help;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\Fonts;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Pats;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Lisp;"
        "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\Lisp\\SteelShapes;"
        )
   )
   )
)

;; This applies the above string to the current session of AutoCAD.
(vla-put-SupportPath *files* sfsp)

;; Other File paths
(vla-put-EnterpriseMenuFile *files* "K:\\CAD\\2_Configurations\\AutoCAD\\BASupport\\BA_custom")
(vla-put-TemplateDwgPath *files* "S:\\CAD\\1_BA Standards\\AutoCAD\\2013 Format\\Templates")
(vla-put-PrinterConfigPath *files* "K:\\CAD\\2_Configurations\\AutoCAD\\Plotters")
(vla-put-PrinterDescPath *files* "K:\\CAD\\2_Configurations\\AutoCAD\\Plotters\\PMP Files")
(vla-put-PrinterStyleSheetPath *files* "K:\\CAD\\2_Configurations\\AutoCAD\\Plot Styles")

; Release the object
(vlax-release-object *files*)