Author Topic: [help] Arxload *.crx and *.arx in AutoCAD 2015  (Read 13569 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: [help] vlx unload in AutoCAD 2015
« Reply #15 on: April 17, 2014, 01:19:44 PM »
Thank you, Irneb . I do it like following :
Code - Auto/Visual Lisp: [Select]
  1. (if (and (not(member "GEOMCAL.ARX" (mapcar (function strcase) (arx))))
  2.          (not(member "GEOMCAL.CRX" (mapcar (function strcase) (arx)))))
  3.     (cond ((findfile "GEOMCAL.CRX") (arxload (findfile "GEOMCAL.CRX") nil))
  4.           ((findfile "GEOMCAL.ARX") (arxload (findfile "GEOMCAL.ARX") nil))))

Maybe another way could be:
Code - Auto/Visual Lisp: [Select]
  1. (setq axl (mapcar 'strcase (arx)))
  2.     (   (member "GEOMCAL.ARX" axl))
  3.     (   (member "GEOMCAL.CRX" axl))
  4.     (   (and (setq tmp (findfile "geomcal.arx")) (arxload tmp nil)))
  5.     (   (and (setq tmp (findfile "geomcal.crx")) (arxload tmp nil)))
  6. )

The same behaviour could be achieved using OR:
Code - Auto/Visual Lisp: [Select]
  1. (setq axl (mapcar 'strcase (arx)))
  2. (or (member "GEOMCAL.ARX" axl)
  3.     (member "GEOMCAL.CRX" axl)
  4.     (and (setq tmp (findfile "geomcal.arx")) (arxload tmp nil))
  5.     (and (setq tmp (findfile "geomcal.crx")) (arxload tmp nil))
  6. )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [help] vlx unload in AutoCAD 2015
« Reply #16 on: April 17, 2014, 02:21:31 PM »
Lee,
Your optional code is still questionable, result wise.

There is a chance the original code from chlh_jd does not conform to the required load logic.

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.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: [help] vlx unload in AutoCAD 2015
« Reply #17 on: April 17, 2014, 02:49:03 PM »
Lee,
Your optional code is still questionable, result wise.

Are you saying the CRX should be preferred over the ARX if both are available?

owenwengerd

  • Bull Frog
  • Posts: 451
Re: [help] vlx unload in AutoCAD 2015
« Reply #18 on: April 17, 2014, 07:28:50 PM »
My 2 cents:

1) The .crx should always be preferred (unless both .arx or .crx may exist, and the app utilizes additional functionality in the .arx when it is available). The reason is two-fold. First, code should usually be optimized for the most recent version of AutoCAD, since over a typical app's lifetime it will be running on the current or a later version of AutoCAD much more often than on older versions of AutoCAD. Second, it's best to minimize dependencies, and in the event both a .crx and an .arx are available (or will be in a future AutoCAD), choosing the .crx results in fewer dependencies.

2) It's usually a bad idea to check whether the dependent module is already loaded instead of just going ahead and loading it, again for two reasons. One, there is very little performance benefit, and possibly even a net loss if the module usually is NOT loaded. Two, the act of calling (arxload) might be the mechanism that expresses a dependency on the module -- and if it is, then skipping the (arxload) could mean the module might be unloaded between the time it's status is checked and the time it is used. In fact, current versions of AutoCAD do not perform reference counting via (arxload), but there is such a mechanism under the hood that is used by ObjectARX apps, and it could very well be utilized in a future version of AutoCAD.

GP

  • Newt
  • Posts: 83
  • Vercelli, Italy
Re: [help] vlx unload in AutoCAD 2015
« Reply #19 on: April 18, 2014, 03:29:43 AM »
The reason is (arxload (findfile "geomcal.arx"))-->(arxload nil)
In AutoCAD 2015 , geomcal.arx Extension has been changed into ".crx"

In AutoCAD 2013, geomcal, geom3d and other...

My 2 cents (for all versions):

(or CAL (arxload "GEOMCAL"))
(or ALIGN (arxload "GEOM3D"))
(or MIRROR3D (arxload "GEOM3D"))
.....
.....
« Last Edit: April 18, 2014, 03:41:28 AM by GP »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [help] vlx unload in AutoCAD 2015
« Reply #20 on: April 18, 2014, 05:11:59 AM »
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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: [help] vlx unload in AutoCAD 2015
« Reply #21 on: April 18, 2014, 06:23:54 AM »
2) It's usually a bad idea to check whether the dependent module is already loaded instead of just going ahead and loading it, again for two reasons. One, there is very little performance benefit, and possibly even a net loss if the module usually is NOT loaded. Two, the act of calling (arxload) might be the mechanism that expresses a dependency on the module -- and if it is, then skipping the (arxload) could mean the module might be unloaded between the time it's status is checked and the time it is used. In fact, current versions of AutoCAD do not perform reference counting via (arxload), but there is such a mechanism under the hood that is used by ObjectARX apps, and it could very well be utilized in a future version of AutoCAD.
There's one issue with this in AutoLisp. From the help on the arxload function:
Quote
Attempting to load an application that has previously been loaded results in an error. Before using arxload you should use the arx function to check the currently loaded applications.
So the help documentation actually states that you must first check to see if the file has already been loaded. So the documentation actually contradicts this, should the documentation be ignored and no check be done?

Given I understand fully that this check is non-trivial as an entire list needs to be searched using member or vl-position - this can be very time consuming if the list is long (hopefully it isn't but can you make the assumption).

So more probably you can simply pass an on-failure to the arxload function so the lisp environment doesn't crash if the file was already loaded.

What's not clear though is if it searches for various known extensions to the file like the load function does. It appears so from the examples, but nowhere is it explicitly stated:
Only that:
Quote
You can omit the .arx extension from the file name.
Is this a case of the documentation needing updating in that it should state the following?
Quote
You can omit the .arx or .crx extension from the file name.
If so then to alleviate both possible issues it is extremely simple:
Code - Auto/Visual Lisp: [Select]
  1. (arxload "geomcal" nil)

If not then you can always do something like this:
Code - Auto/Visual Lisp: [Select]
  1. (or (arxload "geomcal.crx" nil)
  2.     (arxload "geomcal.arx" nil)
  3. )
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: [help] vlx unload in AutoCAD 2015
« Reply #22 on: April 18, 2014, 06:51:30 AM »
(or CAL (arxload "GEOMCAL"))
That's a good idea to get around the possibly slow check through the arx list, it should be faster since it's using the symbol table instead of the list of strings. Not sure how AutoLisp implements this internally, but most languages use something faster than a serial list search - usually something like a hash table.

Though I can think of one situation where such might not work: What if another defun / symbol was created with the name cal? E.g. what if someone's rolled their own "cal" function (like I did here)but you want to rather use the geomcal one?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: [help] vlx unload in AutoCAD 2015
« Reply #23 on: April 18, 2014, 06:57:28 AM »
What's not clear though is if it searches for various known extensions to the file like the load function does. It appears so from the examples, but nowhere is it explicitly stated: ...
Doing a bit more searching in the documentation ... even the 2015 docs say nothing about CRX. Only arx for windows and bundle for Mac: http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-965A0D2A-CFD0-4D7C-9D2B-2D8188F0DAC8

Though now the wording on searching the arx list has changed from "you should" to "you may want to".
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

chlh_jd

  • Guest
Re: [help] vlx unload in AutoCAD 2015
« Reply #24 on: April 18, 2014, 09:41:30 AM »
Thanks LeeMac for opt suggest . :-) It does require the order just like Owen's clarify .  Maybe
Code - Auto/Visual Lisp: [Select]
  1. ((lambda (a)
  2.    (if (and (not (member "GEOMCAL.ARX" a)) (not (member "GEOMCAL.CRX" a)))
  3.       (cond ((findfile "GEOMCAL.CRX")
  4.              (arxload "GEOMCAL.CRX" nil))
  5.             ((findfile "GEOMCAL.ARX")
  6.              (arxload "GEOMCAL.ARX" nil)))))
  7.  

Thanks Kerry for keeping paying attention .  :-)

My 2 cents:

1) The .crx should always be preferred (unless both .arx or .crx may exist, and the app utilizes additional functionality in the .arx when it is available). The reason is two-fold. First, code should usually be optimized for the most recent version of AutoCAD, since over a typical app's lifetime it will be running on the current or a later version of AutoCAD much more often than on older versions of AutoCAD. Second, it's best to minimize dependencies, and in the event both a .crx and an .arx are available (or will be in a future AutoCAD), choosing the .crx results in fewer dependencies.

2) It's usually a bad idea to check whether the dependent module is already loaded instead of just going ahead and loading it, again for two reasons. One, there is very little performance benefit, and possibly even a net loss if the module usually is NOT loaded. Two, the act of calling (arxload) might be the mechanism that expresses a dependency on the module -- and if it is, then skipping the (arxload) could mean the module might be unloaded between the time it's status is checked and the time it is used. In fact, current versions of AutoCAD do not perform reference counting via (arxload), but there is such a mechanism under the hood that is used by ObjectARX apps, and it could very well be utilized in a future version of AutoCAD.

Thanks Owen a lot for Clarified it .

Thanks Irneb for keep helping me , Indeed there is  no clear something about .crx and .arx by AutoCAD .

Thanks GP's suggest , by this way it has some case like Irneb has said , before I used cal function of geomcal.arx , I did it to cal "-0.2+5^3/2*sin(1.4)"  like
Code - Auto/Visual Lisp: [Select]
  1. (defun cal (str / r o)
  2.   ;;from http://www.mjtd.com/BBS/dispbbs.asp?boardID=3&ID=62105&page=1
  3.                 (vlax-get-acad-object)
  4.                 "ScriptControl"
  5.               ))
  6.     (progn
  7.       (vlax-put-property o "language" "vbs")
  8.       (setq r (vl-catch-all-apply 'vla-eval (list o str)))
  9.       (vlax-release-object o)
  10.       (if (not (vl-catch-all-error-p r))
  11.         r))))
  12.  
« Last Edit: April 18, 2014, 10:04:01 AM by chlh_jd »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [help] Arxload *.crx and *.arx in AutoCAD 2015
« Reply #25 on: April 18, 2014, 11:52:03 AM »
I'm in dire need of coffee this morning so there's a very good chance I'm overlooking something but in my mind it needn't be any more ambitious than this:

Code: [Select]
(   (lambda ( a b )
        (or
            (vl-some '(lambda (f) (member f a)) b)
            (vl-some '(lambda (f) (and (findfile f) (arxload f nil))) b)
        )
    )
    (mapcar 'strcase (arx))
   '("GEOMCAL.CRX" "GEOMCAL.ARX")
)

or

Code: [Select]
(   (lambda ( a b )
        (or
            (vl-some '(lambda (f) (member f a)) b)
            (arxload "geomcal" nil)
        )
    )
    (mapcar 'strcase (arx))
   '("GEOMCAL.CRX" "GEOMCAL.ARX")
)

:shrug:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

owenwengerd

  • Bull Frog
  • Posts: 451
Re: [help] Arxload *.crx and *.arx in AutoCAD 2015
« Reply #26 on: April 18, 2014, 12:06:15 PM »
Michael, it's documented somewhere that (arx) always returns results in all lower case, so you can eliminate your (strcase) if you ensure that the module names are all lower case.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [help] Arxload *.crx and *.arx in AutoCAD 2015
« Reply #27 on: April 18, 2014, 12:21:03 PM »
Thanks Owen. It's really hard to break the habit of thwarting case issues. :)

For fun:

Code: [Select]
(defun _ArxLoad ( basename )
    (   (lambda ( a b x )
            (or
                (vl-some '(lambda (s) (member (strcat b "." s) a)) x)
                (arxload b nil)
            )
        )
        (arx)
        (strcase (vl-filename-base basename) t) ;; ijit proofed
       '("crx" "arx")
    )
)

(_ArxLoad "geomcal")
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kean

  • Newt
  • Posts: 48
Re: [help] Arxload *.crx and *.arx in AutoCAD 2015
« Reply #28 on: April 22, 2014, 08:03:37 AM »
It seems like I didn't set a notification to follow this thread (fixed, now).

Something I should probably add on the whole .arx vs. .crx question: just as monolithic .arx apps were encouraged to split out custom entity definitions into a .dbx, these same .arx apps should now see long-term benefit from splitting into .arx (for GUI) and .crx (for everything else). The .arx module's GUI-centric commands would then call into core implementations inside the .crx modules (which also house command-line versions of the commands that call into the same core functions).

So vl.arx probably implements some GUI-related stuff and depends on vl.crx. You can see the dependency using the Dependency Walker (see below).

All this also applies to .NET applications, although their nature isn't declared by the file extension. You could (should) have a .DLL module that refers to acdbmgd.dll and accoremgd.dll (which can then be loaded by the Core Console) and then an AutoCAD-specific .DLL that would depend on the first .DLL and could also make use of acmgd.dll (in addition to accoremgd.dll and acdbmgd.dll).

The ability to call commands natively in AutoCAD 2015's .NET API should greatly help this GUI separation work (or you could just have the GUI code call into functions that are shared between the two modules in some way).

Hopefully all this isn't making the topic less clear. Let me know if that's the case - I'll try to broaden the explanation into a blog post.

Kean

chlh_jd

  • Guest
Re: [help] Arxload *.crx and *.arx in AutoCAD 2015
« Reply #29 on: April 24, 2014, 11:04:08 AM »
Thanks Kean , thank you a lot   :-)
Although I know DotNet so little , it seems that : currently , vl.arx  include vl.crx because it shoud  not only be used in the core .