BlackBox Posted August 18, 2011 Posted August 18, 2011 (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 August 18, 2011 by BlackBox Quote
MSasu Posted August 19, 2011 Posted August 19, 2011 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 Quote
ketxu Posted August 19, 2011 Posted August 19, 2011 Thank you very much. When i paste it in commandline, i reveiced Nil, so it has effected with CAD. But in vlide, nothing change ? Quote
MSasu Posted August 19, 2011 Posted August 19, 2011 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 Quote
BlackBox Posted August 19, 2011 Author Posted August 19, 2011 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). Quote
BlackBox Posted August 19, 2011 Author Posted August 19, 2011 cool tip RenderMan~Greg Thanks, troggarf. Quote
troggarf Posted August 19, 2011 Posted August 19, 2011 Gotta love Fridays (AKA "Beer-day") ~Greg Quote
BlackBox Posted August 19, 2011 Author Posted August 19, 2011 BTW troggarf - Nice Wordpress blog; I just started setting mine up this past weekend. Quote
troggarf Posted August 19, 2011 Posted August 19, 2011 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 Quote
BlackBox Posted August 19, 2011 Author Posted August 19, 2011 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! Quote
Ahankhah Posted November 28, 2011 Posted November 28, 2011 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)? Quote
BlackBox Posted November 28, 2011 Author Posted November 28, 2011 (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 , 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 November 28, 2011 by BlackBox Quote
Ahankhah Posted November 28, 2011 Posted November 28, 2011 RenderMan, thank you very much for your prompt reply. 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. 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. Quote
BlackBox Posted November 28, 2011 Author Posted November 28, 2011 RenderMan, thank you very much for your prompt reply. 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. 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: Quote
Ahankhah Posted November 28, 2011 Posted November 28, 2011 Perhaps this post will help get you started. :wink: Thanks a lot. Quote
alanjt Posted November 28, 2011 Posted November 28, 2011 http://www.theswamp.org/index.php?topic=30714.0 Quote
BlackBox Posted November 28, 2011 Author Posted November 28, 2011 http://www.theswamp.org/index.php?topic=30714.0 Great thread, Alan... Folks like Kerry, and yourself are truly brilliant with this stuff. Edit to add - I really liked the *-Load-Com idea. Quote
Ahankhah Posted November 28, 2011 Posted November 28, 2011 http://www.theswamp.org/index.php?topic=30714.0 Thank you very much alanjt for the nice offer. Quote
Recommended Posts
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.