...well then, here's the code, a sample multiple visibility dynamic block and a step by step walkthrough on how to add another visibility in AutoCAD 2011, compared with how to walk through the code in AutoCAD 2020 (or another recent version).
There have been many posts regarding this excellent program in the past decade on the Autodesk, AUGI and the Swamp forums, but only a few recent ones which did not solve the issues, so I brought this up again to see if anyone can figure this out.
Visibility-add-eng.lsp was written by the late Andrey Lazebny about 11 years ago. He was a genius in regards to the AutoCAD object model and Lisp and was able to find a nifty way to get past the Autodesk limit of just one visibility parameter per dynamic block. He did this by tricking AutoCAD into defining a second visibility when he would watch the evaluation graph dictionary as he added something as simple as a point entity. He used that point to gain access to the DXF data for the dynamic block model and eventually figured out which assoc dotted pairs to use to create additional visibility parameters. Believe it or not, this still works today even when used in AutoCAD 2020.
However, the ability to create multiple visibility parameters is not very useful in itself unless it is accompanied by other tools to create distinct lists of entities which are associated with (managed by) the disparate visibility parameters, or you would only need one parameter as Autodesk originally gave us. So Andrey gave us 10 additional functions just to manage the association of which entities would be controlled by the various visibility parameters. This is where we need help.
Over the last 7 years I have built over 500 dynamic blocks using his program in AutoCAD 2011 and edited them thousands of times – sometimes radically - and they still work in AutoCAD 2020, flawlessly and without causing errors or corruption in the host drawing.
Since I continue to maintain a lot of “multiple-visibility“ dynamic blocks which need edits on occasion using AutoCAD 2011 (or older) to fully control the creation and editing of these, I began an effort to bring this program up to date with the latest AutoCAD object model. So I (an admitted Lisp kludge) started dissecting his functions to see if I could determine where the problems arise. I quickly found out that I am over my head.
I started studying the program in its most usable version (1.6 -works well in AutoCAD 2011). That version had already been through several people reviewing the code and writing notes – translating some of the comments, etc. I have tried to interpret more of the variables by using google translate and I turned the functions into simple 3 letter commands so that using the program wasn’t so typing dependent.
I have attached the result – visibility_add_engine_1-7.lsp, and a drawing containing a block I created using the program in AutoCAD 2011 earlier. I took this block which has two visibilities and attempted to add a 3rd as described in the walkthrough below. I can easily accomplish this using AutoCAD 2011 but I am attempting to do this using AutoCAD 2020 (or at least a much more recent version) and those attempts fail.
Testing instructions:Open
Visibility_Add_Engine Example Block.dwg using AutoCAD 2020 (or a recent version)
Right-click on the block and select “
Block Editor”Open Visibility-Add-engine 1.7.lsp in the
VLIDE editor.
Load Visibility-Add-engine 1.7.lsp into the block editor session.
Type
VPS<Enter> and select
VP_ALL_ON (select “
Save the changes”) to get the program to process the current visibility parameter and recognize it as current (active).
Add a new visibility by typing
VPA <Enter> - put it anywhere.
Select the new visibility and rename it “
typ_belt” and give it the description “BELT TYPE” using the properties palette. Select <
ESC> to disselect the visibility parameter.
Type
VPS<Enter> and select t
yp_belt to make it the current (Active) visibility parameter.
Use the
Visibility States button on the ribbon to open the visibility states manager and rename “
Visibility State0” as “
GREY”.
Use the New button to add a new visibility and Name it
“WHITE”
Set
GREY current and close the visibility states dialog box.
That is as far as we can go in AutoCAD's newer versions but I will describe how I proceed in AutoCAD 2011, and I'll follow up with a comparison to AutoCAD 2020:
AutoCAD 2011 method: (Don’t attempt this in newer AutoCAD, step through the VLIDE code instead)
At this point I usually use
RFV to remove all entities from the visibility set since every object in the block is considered part of the current visibility set because the set has not been defined yet. Using AutoCAD 2011 I usually type
RFV<Enter> and issue “
ALL” as the selection set, but
before I hit enter to finish the action, I hit “
R” to remove something from the selection set – the two lines (grey and white) ¼” apart representing the belt in the plan view near the attribute definitions. After I have selected those two lines, they remain as the only things in the selection set because the
RFV command was told to act on ALL (minus those two lines).
To verify that you have isolated the lines as the only objects in the current visibility type
GON<Enter> and the two lines will be highlighted, showing their grips.
Once I have the two lines as the active visibility set, I use the
Make Invisible button to hide the grey line in the
WHITE visibility state, and then I switch states to
GREY and hide the white line with the same button.
I leave
GREY as current and type in
VPS<Enter> and select
VP_ALL_ON to switch active visibility parameters back to the default. Once this is the default I will want to remove the two lines from this visibility set so that two separate visibility parameters are not fighting for control of the same objects. That can be allowed, but it gets hard to manage sometimes.
To remove the lines from
VP_ALL_ON I use
RFV<Enter> and select the two lines.
Once again
GON can be used to verify that they are no longer controlled by
VP_ALL_ON.That covers the AutoCAD 2011 workflow, but what breaks down in newer versions?
I will step through the code (where I stopped to detail the 2011 workflow) and reveal where things seem to stop working properly.
I took two computers, one with AutoCAD 2011 on it and another with AutoCAD 2020, and opened up the drawing and then block edited this block in the two versions of AutoCAD side by side. I used the same instructions as detailed above but instead of using commands to do the work, I stepped through the code on both computers simultaneously and checked what was returned against each version – keeping in mind that the 2011 results actually work, while something in AutoCAD has changed in the newer versions.
Adding a visibility seems to work correctly in all versions of AutoCAD, and it seems to have identical data returned when you evaluate results in the Lisp editor. However
RFV does not work in any version newer than 2011, so I wanted to step through that slowly and check all results until I find a difference.
I stepped through head function 07 (RFV) evaluating one line at a time but I used it to remove the 4 polylines that form the end roller (looks like the outline of a rolling pin) – I wanted to keep the selection set small for this test.
I found no difference in results until I got all the way through the execution of
eval_graf_output which I manually stepped through as well (instead of executing the function). The next line clears list_of_vis_sets which works fine on both versions as does the mapcar expression that follows it. If you check the results of
EVAL_GRAPH they are identical all the way to the end (885 items) – I checked them all.
(setq current_visibility (entget (car list_of_vis_sets))) correctly identifies the correct visibility parameter but now see the first divergence in results.
“Current_visibility” when evaluated reveals a list of 290 items in AutoCAD 2011, but in AutoCAD 2020 the list contains only 145 items.All I can attribute this to is that the mapcar function is producing a list_of_vis_sets but the actual entity at the top of the resultant list which is returned has less data in it.
(mapcar '(lambda (x)
(if (and (= (car x) 360)
(= (cdr (assoc 0 (entget (cdr x)))) "BLOCKVISIBILITYPARAMETER"))
(setq list_of_vis_sets (append list_of_vis_sets (list (cdr x)))))) EVAL_GRAPH)
That is why (entget (car list_of_vis_sets)) returns much less data in AutoCAD 2020, but why the data loss occurs is beyond me right now.
Links to posts about Visibility_add_engine:
http://www.theswamp.org/index.php?topic=50463.msg555888#msg555888http://www.theswamp.org/index.php?topic=50937.msg560655#msg560655(not really fixed as the poster had thought)
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/challenge-make-usable-a-very-old-lisp-with-autocad-2018/m-p/7467495?collapse_discussion=true&filter=location&location=forum-board:130&q=read%20dynamic%20properties%20visibility&search_type=thread(I’m just basically picking up from this post…)