Jump to content

Recommended Posts

Posted (edited)

So I was trying to find out how on Earth one goes about creating a custom TypeLib (prompted by this thread), and unexpectedly stumbled upon this awesome (and now undocumented) compiler function called PRAGMA, which enables you to protect/unprotect LISP symbols.

 

Many of you may have known about this since back in the early 2000's, but I'm like a kid who just found their new favorite toy! A search in the forums yielded no result, so I thought I'd share.

 

For example, if you have some sub-functions, or custom variables that you commonly use, PRAGMA will enable you to protect the symbol (make it turn blue) in VLIDE:

 

(setq acadApp (vlax-get-acad-object))
(setq activeDoc (vla-get-activedocument acadApp))
(defun FOO () "FOO")

(pragma '((protect-assign acadApp activeDoc FOO)))

... Note that once you load the pragma statement, the symbols "acadApp," "activeDoc" and "FOO" turn blue.

 

To unprotect a symbol, simply load this pragma statement:

 

(pragma '((unprotect-assign acadApp activeDoc FOO)))

You could add the protect statement to your ACADDOC.lsp, or even *.MNL files. This would even be great for custom applications.

 

Enjoy!

Edited by BlackBox
  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • BlackBox

    10

  • Ahankhah

    5

  • alanjt

    3

  • troggarf

    3

Posted

This is really great!!! Thank you very much for sharing it!

 

I was wondering from a long time why some libraries had their symbols recognized in editor...

 

Regards,

Mircea

Posted

Thank you very much. When i paste it in commandline, i reveiced Nil, so it has effected with CAD. But in vlide, nothing change ?

Posted

It works for me both if the code is loaded at command prompt or in VLisp editor. Found one issue, seems that doesn't work if the file that contain it is compiled.

 

Regards,

Mircea

Posted

I'm glad this is helpful to you... unfortunately this function, while functional, is no longer documented. Apparently the last known documentation for this function comes from an old "Vital LISP" manual that I have not yet been able to find.

 

As for the code not working when compiled, that is why I suggested ACADDOC.lsp, or *.MNL, albeit that I have not tested both (yet).

Posted
cool tip RenderMan

~Greg

 

Thanks, troggarf. :beer:

Posted

BTW troggarf - Nice Wordpress blog; I just started setting mine up this past weekend. ;)

Posted

Thanks,

Don't forget to post the link when its ready. I'll add it to my list of resources, (AKA places to loiter at...)

I just started a new job and have actually had more time to hang out here and at the swamp and have it be really useful. I haven't been able to tune in to Prager lately...

~Greg

Posted

I'll probably add a small link to my signature when I feel that the site is presentable; perhaps even post it initially as a faux 'announcement'. :)

 

I somewhat reluctantly started building the site, because of a coworker's encouragement mostly. I do a lot of internal development, the forum stuff just helps sharpen the little skill I have. LoL So with their encouragement (for which I am grateful), I started a Wordpress site. I'm still trying to figure the best way to leverage the blog platform to suite both my public / professional content - I obviously can't post our internal workings out there, and it would take too much time to 'generalize' all of the hard-coded stuff. Perhaps I'll end up with more than one site! LoL :sigh:

 

I too have been missing Dennis' show for some time. Friday is *usually* a great day... I think I'll try to catch it (the show) today.

 

Happy Friday, Greg! :beer:

  • 3 months later...
Posted

RenderMan,

your introduction to Pragma is excellent. I appreciate your contributing it with other 'CAD lovers'.

 

I have a question about Pragma: Is it possible to find out whether any symbol is protected or not via lisp (and not by vision)?

Posted (edited)

RenderMan,

your introduction to Pragma is excellent. I appreciate your contributing it with other 'CAD lovers'.

 

Ahankhah, that is very kind of you to say :oops:, and you are very welcome, my friend. :)

 

I have a question about Pragma: Is it possible to find out whether any symbol is protected or not via lisp (and not by vision)?

 

At this time, I am unsure of how to determine if a symbol is protected programmatically, other than that the user will be prompted if attempting to modify a protected symbol... Additional information on Protected Symbols.

 

 

Separately, as a small update to this thread, as I've been writing more and more .NET code, I did come across a .NET Method that allows you to add functionality to the VLIDE (as a protected symbol).

 

For example, after NETLOADing a .DLL compiled for your version of AutoCAD containing (VB.NET shown):

 

[color=blue][font=Consolas]Imports[/font][/color][font=Consolas] System[/font]
[color=blue][font=Consolas]Imports[/font][/color][font=Consolas] Autodesk.AutoCAD.Runtime[/font]
[color=blue][font=Consolas]Imports[/font][/color][font=Consolas] Autodesk.AutoCAD.ApplicationServices[/font]
[color=blue][font=Consolas]Imports[/font][/color][font=Consolas] Autodesk.AutoCAD.DatabaseServices[/font]
[color=blue][font=Consolas]Imports[/font][/color][font=Consolas] Autodesk.AutoCAD.Geometry[/font]
[color=blue][font=Consolas]Imports[/font][/color][font=Consolas] Autodesk.AutoCAD.EditorInput[/font]

[color=green][font=Consolas]' This line is not mandatory, but improves loading performances[/font][/color]
[font=Consolas]<[color=blue]Assembly[/color]: [color=#2B91AF]CommandClass[/color]([color=blue]GetType[/color](FOO.[color=#2B91AF]FOOCommands[/color]))> [/font]
 
[color=blue][font=Consolas]Namespace[/font][/color][font=Consolas] FOO[/font]

 [font=Consolas]  [color=blue]Public[/color] [color=blue]Class[/color] [color=#2B91AF]FOOCommands[/color][/font]

 [font=Consolas]      <[color=#2B91AF]LispFunction[/color]([color=#A31515]"FooFunction"[/color], [color=#A31515]"MyFooFunction"[/color])> _[/font]
 [font=Consolas]      [color=blue]Public[/color] [color=blue]Function[/color] FooFunction([color=blue]ByVal[/color] args [color=blue]As[/color] [color=#2B91AF]ResultBuffer[/color])[/font]
 [font=Consolas]          [color=blue]Return[/color] [color=#A31515]"FOO"[/color][/font]
 [font=Consolas]      [color=blue]End[/color] [color=blue]Function[/color][/font]

 [font=Consolas]  [color=blue]End[/color] [color=blue]Class[/color][/font]

[color=blue][font=Consolas]End[/font][/color][font=Consolas] [color=blue]Namespace[/color][/font]

... Both "FooFunction" and "MyFooFunction" appear in VLIDE as protected symbols, and are fully functional:

 

_$ (FooFunction)
; error: no function definition: FOOFUNCTION
_$ [color=red]<Netload DLL Here>[/color]
_$ (FooFunction)
"FOO"

HTH

Edited by BlackBox
Posted

RenderMan, thank you very much for your prompt reply. :D

 

I had writen C codes in AutoCAD long time ago, when AutoCAD introduced this extension and named it 'ADS'. The code had to be compiled with a C compiler named Watcom C (DOS prompt, command line compiler, without any editor). With this ability I changed AutoCAD R12 somehow to Persian.

So "Watcom C" and "ADS" sound nostalgic to me. :glare:

 

I think it is the time to upgrade my codes to C and C# to get more helps from you and other kind members of very interesting CADTutor forum. :)

Posted
RenderMan, thank you very much for your prompt reply. :D

 

Again, my friend, you are welcome. :)

 

I had writen C codes in AutoCAD long time ago, when AutoCAD introduced this extension and named it 'ADS'. The code had to be compiled with a C compiler named Watcom C (DOS prompt, command line compiler, without any editor). With this ability I changed AutoCAD R12 somehow to Persian.

So "Watcom C" and "ADS" sound nostalgic to me. :glare:

 

I think it is the time to upgrade my codes to C and C# to get more helps from you and other kind members of very interesting CADTutor forum. :)

 

I am still relatively new to coding in general (+/-2 yrs?), but I am always working to improve... Perhaps this post will help get you started. :wink:

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