July 29, 2016

ACA/AMEP: "BIND" Bound External Reference Named Object Naming

Whenever possible, I try to avoid binding External References with the BIND option; I prefer to use the INSERT option when I cannot leave the references as external. In cases where the "root" layer (for example, A-Door) has the same layer attributes and is treated the exact same way, whether as a "live" layer in the host file or a layer within one or more external references, using the INSERT option simply combines all of the various layers with the same root name into one layer (A-Door in the example here). But there are times when one has to work on a project done by others (perhaps, many others, over a long period of time), where the various layers with the same root name (A-Door, External01|A-Door, External02|A-Door, etc.) are not treated the same way, in particular, with regard to on/off, freeze/thaw and/or viewport freeze/thaw status. If A-Door is on, thawed and viewport thawed, External01|A-Door is globally frozen and External02|A-Door is viewport frozen, using the INSERT option of the BIND command will not preserve what is seen in the sheet. (Or, maybe it does, if nothing on that layer is visible in the viewports on that sheet - but if you are tasked with preparing hundreds of files for turnover at the end of a project on which you did not work, including disciplines other than your own, you will likely not have time to carefully note what is visible in each viewport on each sheet and then reproduce that.) Using the BIND option of the BIND command may be the best course in this case.

I have been involved in such an effort lately, and in the course of that have come to a clearer understanding of how named objects are renamed when using the BIND option of the BIND command. I knew that the named objects in each external reference were renamed, using the external reference name as a prefix, with the vertical bar (|) delimiter being replaced with, typically, $0$. So, External01|A-Door would become External01$0$A-Door. A long time ago, when all this was new to me, I (erroneously) thought that the "0" in the delimiter was the layer name on which the external reference resided, as back then most, if not all, of our external references were placed on Layer 0. At some point, I did a "bind-bind" on an external reference on a different layer, and still got $0$ as the delimiter, and realized that the "0" was not the layer name on which the external reference was at the time of binding, but did not give it a whole lot of additional thought.

In my current effort, I am writing AutoLISP code to help automate certain processing tasks which involve being able to specify layer attributes for the root layer name, and have those applied to all variations of that root layer name, whether or not the layer has a prefix/delimiter from having been "bind-bound". I wanted my code to be able to identify the final delimiter in a layer name, so that the root name could be extracted. I made a very brief attempt to find something in the Help that described how the delimiter is determined, without any success. (It may be in there, and I just did not have enough patience to find it.) So I played around with some test files, with a very small number of layers, to figure out if the delimiter could ever be anything but $0$. As it turns out, it can, but, at least for the way we work, it will almost always be $0$. Your experience may vary, as your workflow may differ from ours.

When you bind-bind an external reference, AutoCAD® will create unique names for all of the named objects in the external reference, whether or not there is a named object of the same type and name in the host file. It does this as previously noted, by starting with a prefix that is the same as the external reference name (which may or may not be the same as the external file name), adding a delimiter consisting of a $ character followed by an integer followed by a $ character, and finally the root name of the named object. The first time you bind-bind an external reference of a given name, that integer will be 0. Should you later add an external reference of that same name (having renamed the bound block -OR- exploded the bound block and purged the definition), and then bind-bind that reference, AutoCAD will see that there already are named objects using the $0$ delimiter, and will increment the integer to "1" - $1$. Do all of that again, and the delimiter will be $2$. Do it eleven times, and the delimiter becomes $10$.

Armed with that knowledge, I was able to write code that would examine the layer names character-by-character, starting at the right end, and would collect the root name in a variable. Once a $ character was found, if it is preceded by one or more integers and then another $ character, that delimiter was saved and the routine then had both the root layer name and the last delimiter in the layer name, allowing the routine to be able to process things accordingly. (If you externally reference a file that has itself had an external reference bind-bound, and then bind-bind the reference, you can get named objects with multiple delimiters, such as External01$0$PreviouslyBound01$0$A-Door.)

No comments: