Jump to content

Recommended Posts

Posted

In the office we currently have 2 flavours of AutoCAD (2011 & 2013) which require a different VB.Net dll loaded. I have the basics of the loaded worked out (thanks again Lee & BB) but don't know how to do the conditional test. Ideally I would test on what version of AutoCAD is running but not knowing how to do that I am looking at checking their log in names. Can somebody fill in the gaps please....

 

; get login name
(setq usr (getvar 'loginname))

; create list of names, ie "dave" "bill" "fred"
(if (= usr List_of_names)
   (progn
; if in list load the 2013 dll
   )
   (progn
; not in list so load the 2011 dll
   )

Posted

You can test the AutoCAD version using the ACADVER System Variable, e.g.:

(setq acv (atof (getvar 'acadver)))
(cond
   (   (= 19.0 acv) ;; 2013
       ; ... do something ...
   )
   (   (= 18.1 acv) ;; 2011
       ; ... do something ...

Posted

What we do, as we run multiple verticals and multiple versions of (i.e., Map 2011, Civil 3D 2011, AMEP 2011, Map 2012, Civil 3D 2012, AMEP 2012, etc.), is to have an appropriate support structure where each has it's own Acad.lsp, and AcadDoc.lsp file.

 

We found this to be far simpler than to have one monolithic file with myriad CONDitional facets... It (having one for each) also makes evolving _that_ vertical's setup that much easier when implementing a new version, as we are about to do with 2014 products / suites.

Posted

again, thanks Lee. Why are these so much simpler than I make them?

 

Out of interest, how would you look for something contained within a list - and what would the list look like.

Posted

Out of curiosity... Why not use Autoloader for 2013?

 

2011 is not Autoloader capable, so you'd only need to add the NETLOAD call for that version... When you add a version newer than 2013, you can simply modify your PackageContents.xml file accordingly, and it will load the correct assembly for the correct version from the outset.

 

** ETA - This is what I do for our current 2011, and 2012 versions, as 2012 supports Autoloader.

Posted

OOPS, forgot to press "Post". Its there now but looks like I'm ignoring BB today.

 

The big problem we have here is I know the most about customisation, but I don't know much. I try to do things the way it is going to be easiest for me :). I suggested everybody try the 2011 dll about a month ago and so far nobody has. I want to push my dll on to each machine without anybody noticing. The ACAD.LSP I had a few weeks ago seemed to do the trick and now I need to extend it abit.

 

Can I ask one of you (I think it is mostly Lee's code) to have a quick look at this and confirm it will do what I want?

 

(
   (lambda ( / acv dir dll loc net usr )
       (setq acv (atof (getvar 'acadver)))
         (cond
             ((= 19.0 acv) ;;2013
             (setq  dir "P:\\Design_Office\\SupportFiles\\"
                    dll "RA_DesignOffice(2013).dll"
                    loc (strcat "C:\\" dll)
                    net (strcat dir    dll)
             ))
             ((= 18.1 acv) ;; 2011
             (setq  dir "P:\\Design_Office\\SupportFiles\\"
                    dll "RA_DesignOffice.dll"
                    loc (strcat "C:\\" dll)
                    net (strcat dir    dll)
             ))
         )
       (cond
           (   (not (findfile net))
               (princ "\nNetwork dll not found.")
           )
           (   (not (findfile loc))
               (if (vl-file-copy net loc)
                   (command "_.netload" loc)
                   (princ "\nUnable to copy dll from network.")
               )
           )
           (   (or (equal (vl-file-systime loc) (vl-file-systime net))
                   (and (vl-file-delete loc) (vl-file-copy net loc))
               )
               (command "_.netload" loc)
           )
           (   (princ "\nFailed to update dll, contact Dave."))
       )
       (princ)
   )
)

Posted
Out of curiosity... Why not use Autoloader for 2013?

 

2011 is not Autoloader capable, so you'd only need to add the NETLOAD call for that version... When you add a version newer than 2013, you can simply modify your PackageContents.xml file accordingly, and it will load the correct assembly for the correct version from the outset.

 

** ETA - This is what I do for our current 2011, and 2012 versions, as 2012 supports Autoloader.

the usual, no time to do it right, plenty of time to do it twice.

 

or to put it another way, I know you have mentioned it but I haven't studied it yet. I will look in to it now....

Posted

Autoloader is great at what it does, truly it is... I'm quite critical of it in the Beta forums, only as it is at odds with Autodesk's stated goal of their new Security Protocol, but the mechanism itself is quite good.

 

It (Autoloader) also allows for one to have internal custom code loaded as needed (i.e., per-session, or per-document... Yes, even for LISP), which precludes the need for Acad.lsp, and AcadDoc.lsp altogether... Instead now, it can be "YourCompanyName".lsp and "YourCOmpanyName"Doc.lsp and still be loaded accordingly without the risk of malicious code that targets the built-in autoload feature. You would need to modify SecureLoad to prevent undesired Acad* files from being loaded without my 'Blacklist' utility.

 

Also worthy of note, is that even LISP code is loaded via Autoloader prior to Acad.lsp in the startup sequence.

 

As a result, I'm considering porting my 'Blacklist for AutoCAD' plug-in back to LISP from .NET as Autoloader would allow for me to do what the plug-in is intended to do where I need it to do it within the startup sequence, which prior to Autoloader, could only be done via a Registered .NET assembly in the ..\Applications\ folder of the HKCU hive for a given ProductKey... That, and Autodesk didn't like my calling the plug-in 'Antivirus for AutoCAD' as it implies that their Security Protocol is somehow insufficient (which it is). :roll:

 

 

 

In any event, I could easily create an Autoloader .bundle for you to try out, and you'd just have to drop in the appropriate assemblies. Lemon squeezy.

Posted
again, thanks Lee. Why are these so much simpler than I make them?

 

No worries Dave :thumbsup:

 

Out of interest, how would you look for something contained within a list - and what would the list look like.

 

You could use the member function to test for the presence of an item in a given list, e.g.:

(member (strcase (getvar 'loginname) t) '("dave" "bill" "fred"))

[aside: the list may be quoted as a 'literal list' as there are no expressions to be evaluated within the list. (more on quoted expressions) ]

 

Alternatively, you could use a succession of or expressions, e.g.:

(setq usr (strcase (getvar 'loginname) t))
(or (= "dave" usr)
   (= "bill" usr)
   (= "fred" usr)
)

However, in my opinion this becomes less readable for more than two or three items.

 

Can I ask one of you (I think it is mostly Lee's code) to have a quick look at this and confirm it will do what I want?

 

I would recommend:

(
   (lambda ( / dir dll loc net )
       (setq dir "P:\\Design_Office\\SupportFiles\\"
             dll (if (= 19.0 (atof (getvar 'acadver))) "RA_DesignOffice(2013).dll" "RA_DesignOffice.dll")
             loc (strcat "C:\\" dll)
             net (strcat dir    dll)
       )
       (cond
           (   (not (findfile net))
               (princ "\nNetwork dll not found.")
           )
           (   (not (findfile loc))
               (if (vl-file-copy net loc)
                   (command "_.netload" loc)
                   (princ "\nUnable to copy dll from network.")
               )
           )
           (   (or (equal (vl-file-systime loc) (vl-file-systime net))
                   (and (vl-file-delete loc) (vl-file-copy net loc))
               )
               (command "_.netload" loc)
           )
           (   (princ "\nFailed to update dll, contact Dave."))
       )
       (princ)
   )
)

Since you only have two conditions for the dll filename, for me it is more readable to use an if statement over cond (I realise that I demonstrated a cond expression in my earlier post, but thought you might have additional conditions to be added); furthermore, if the AutoCAD version is neither 2013 nor 2011, the if statement shown above also accounts for all other cases.

Posted

You may name your files any way you choose, but just as an observation... WRT .NET Development, you may find it useful to suffix the assembly name with the Database version you've developed the plug-in for (i.e., RA_DesignOffice18.dll, and RA_DesignOffice19.dll, etc.) instead of the release version's year as the plug-in is compatible with all version year's on the same major Database version. :thumbsup:

 

This is especially useful when you have a single Visual Studio Solution, with multiple (Database-specific) Projects, which each build their own resultant assembly (see second image attachment).

 

 

 

Separately, especially so if you choose to use Autoloader one day, you'll want to add an External Tool to your Visual Studio setup, specifically 'Create GUID' (see first image attachment)... This tutorial shows you how to add.

 

 

 

** ETA - I went to replace one of the images, and now they won't sort in the order I want for some reason.

ct.vs.multi-project.solution.png

ct.vs.external.tools.create.guid.png

Posted

I'm sorry for 'offtopicing' but...

What does the .dll file stand for and for what it is used? D:

Posted
I'm sorry for 'offtopicing' but...

What does the .dll file stand for and for what it is used? D:

a dll is a Dynamic Link Library, basically a store for information. In this case it contains a number of short VB.Net routines that we use during our drawing processes.
Posted

Oh, thank you (:

And another doubt...

Every lisp routine for AutoCAD can be done using VB.Net? And vice versa?

Posted
a dll is a Dynamic Link Library, basically a store for information. In this case it contains a number of short VB.Net routines that we use during our drawing processes.

 

To build on Dave's apt response, if I may, especially in terms of AutoCAD, a .DLL file (a Class Library typed assembly) is a plug-in which is loaded into AutoCAd to provide additional functionality, most often through Commands (CommandMethod Methods), LISP functions (LispFunction Methods), and also event-driven functionality.

 

Also (to the best of my knowledge), again in terms of AutoCAD, a .DLL is indicative of a a .NET plug-in, whereas an ObjectARX (C++ for AutoCAD) plug-in will have an .ARX file extension.

 

This as opposed to an external application, such as a stand-alone .EXE, etc. which does not get loaded into AutoCAD.

 

HTH

Posted
Oh, thank you (:

And another doubt...

Every lisp routine for AutoCAD can be done using VB.Net? And vice versa?

Probably. Most things in AutoCAD can be performed a number of ways. For some LISP may be the easiest way forwards, for others VB.Net or C++ may be better. In a very few cases there may only be one way.

 

I can program in LISP but I am not very good at it. The only language I have formal training in is FORTRAN so I found the change to BASIC pretty easy. From that background I found VBA suited me but now I need to change to VB.Net. There are more LISP gurus here than there are other languages.

Posted

I'm new at coding, so, apologize my noobiness ):

I try to login everyday and read all new posts, it helps me a lot. Reading and try understanding codes is a very good way of learning.

Thank you for replying me, guys (:

Posted

No worries; we all start somewhere... Happy to help :beer:

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