January 31, 2008

Toggling Plot Style Display in a Layout

A request in a thread in the AutoCAD® Architecture Customization Discussion Group for a way to be able to turn on or turn off the display of plot styles on a layout tab without having to open the Page Setup dialog got me thinking the other night. It occurred to be that this would be a handy routine to have, now that the tabs can be hidden in more recent versions of AutoCAD and AutoCAD Architecture, taking away the quick right-click access to the Page Setup command. It also offered me the opportunity to begin to become familiar with the "new" VL functions in AutoLISP, which became available quite some time ago, right around the time that I found myself with less time to spend writing LISP routines. As it turned out, I got a rather limited exposure to the VL commands, but I was able to make use of a few of them to change the current status of the display of plot styles on a layout tab. I posted my first version of that routine in a reply to the previously mentioned thread, and thought I would share the code here.

(defun C:PST ( ; No arguments.
acadDocument ; Holds reference to the active AutoCAD drawing object.
acadLayout ; Holds reference to the active Layout object.
acadObject ; Holds reference to the AutoCAD object.
showPStyles ; Holds current status of PlotStyle display on the active Layout.
) ;_ End arguments & local variables.
(cond ; Cond A
((= (getvar "TILEMODE") 1) ; Model tab is active, abort command.
"C:PST is meant for use on a Layout tab, not on the Model tab."
"\nPlease change to a Layout tab and try again."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A1.
(T ; Condition A2.
(vl-load-com) ; Load "vl" functions, if not already loaded.
acadObject (vlax-get-acad-object)
acadDocument (vlax-get-property acadObject 'ActiveDocument)
acadLayout (vlax-get-property acadDocument 'ActiveLayout)
showPStyles (vlax-get-property acadLayout 'ShowPlotStyles)
) ;_ End setq.
(if (= showPStyles :vlax-true)
(vlax-put-property acadLayout 'ShowPlotStyles :vlax-false)
(prompt "\nThe display of plot styles has been turned off. ")
) ;_ End progn.
(vlax-put-property acadLayout 'ShowPlotStyles :vlax-true)
(prompt "\nThe display of plot styles has been turned on. ")
) ;_ End progn.
) ;_ End if.
(vlax-release-object acadLayout)
(vlax-release-object acadDocument)
(vlax-release-object acadObject)
(command "_.REGENALL") ; Regenerate the screen graphics.
) ;_ End condition A2.
) ;_ End cond A.
) ;_ End C:PST.

The VL functions allow you to access the ActiveX object model (just like VBA!) in a LISP routine. Never having had the time to truly master VBA (and realizing that for ease of use, a LISP routine to run the VBA code would probably be needed anyway), for this relatively simple task it seemed to me that writing the entire thing in LISP was the better way to go. The vlax-get-acad-object function is used to get the AutoCAD "object" and save it to the acadObject variable. The vlax-get-property function is then used to get properties of the AutoCAD object and its subobjects:
  • The ActiveDocument property of the AutoCAD object is the currently active drawing object.
  • The ActiveLayout property of the currently active document is the currently active layout (or model) tab object.
  • The ShowPlotStyles property of a layout tab (not relevant for the Model tab, which can not display plot styles) indicates whether or not the display of plot styles is enabled for that layout tab. A value of :vlax-true indicates that the display is turned on; :vlax-false indicates that the display is turned off.
In developing the routine, I assigned the intermediate objects to variables, along with the value of the ShowPlotStyles property, so that I could see what sort of values each had and could figure out what my test string should be. After posting the routine, it occurred to me that I could have omitted assigning any of those values to a variable, and simply nested everything in the IF statement condition. I am not certain that would substantially improve performance, however, and felt that leaving it as written would be easier for me to decipher, should that be necessary in the future, after I have forgotten the details of how I wrote this routine.

I am also not certain if releasing the objects is necessary, given that the variables are local to the routine and should "go away" after it has run. Perhaps my next foray into VL territory will lead me to a better understanding of that.

January 24, 2008

Extend Linework to Wall Component Edge

Thanks go out to Steve Bennett for his reply in this thread in the AUGI AutoCAD Architecture 2008 Forum, for reminding me of what I am missing while using Autodesk® Architectural Desktop 2004 for production work. A similar question came up in the Autodesk AutoCAD Architecture 2008 Discussion Group today, and I was able to pass on Steve's suggestion. I decided to document it here so that I will remember it when we move to 2008 for production.

As you are likely aware, the AutoCAD® EXTEND command can be used to extend linework to a wall. When doing so, however, the linework will be extended to the justification line of the wall, which may or may not be the part of the wall to which you wanted the linework extended. The AEC Modify Tools can be used to extend linework to the edge of any component in the wall. Select the linework you wish to extend and, with grips on but none hot, right click and choose AEC Modify Tools > Extend from the context menu, as shown below.
You will be prompted to Select a boundary edge on the screen:. Move your cursor over the edge of the wall component to which you wish to extend the linework. You should get a "Boundary Edge" tool tip as well as a red line extending beyond the drawn graphics of the edge. When you have the right boundary, left click to select that as the extend edge.
You will now be prompted to Select a point near the end(s) to extend:. Left click anywhere near the end of the linework to extend, on the side that you want extended...
...and, just like that, the linework extends!

You can also trim linework to the face of any component using the AEC Modify Tools - simply pick the Trim option, instead of the Extend option, from the context menu.

Part 2 - AEC Trim

January 12, 2008

ACD-A Display System - Part 1, AutoCAD® Basics

I have been answering quite a few Display-System-related posts in the Autodesk Discussion Groups and AUGI Forums lately, and thought it would be helpful to post some information on the AutoCAD® Architecture Display System. Helpful to me, anyway, so I can just post a link, rather than (re)writing the information. The topic is a broad one, and if I wait until I have time to cover the entire subject, it will never happen. So here is the first of what I hope to be a multi-part series on the ACD-A/ADT Display System, a review of AutoCAD's display settings, as similar terms and features are used by ACD-A/ADT.

Color, Linetype, Entity Linetype Scale, Lineweight and Plot Style
The appearance and plotting of AutoCAD objects is controlled by four (CTB plot styles) or five (STB plot styles) properties of each object, which can be found and set on the Design tab of the Properties palette, in the General category.
Color: Determines the color used to draw the object on the screen. For color-dependent plot styles, also determines the plot style used to plot the object. When the object’s plot style calls for the plotted color to "use object color", also determines the plotted color (within the limitations of the plotting device used).

Linetype: Determines the pattern of dots, dashes and gaps used to drawn the object. Linetypes are defined in external text files with a LIN extension, following a prescribed format, and can be loaded into a drawing using the LINETYPE command.

Entity Linetype Scale: Three factors determine the final multiplier applied to the dashes and gaps included in the linetype definition. The first is the value of the LTSCALE system variable, which is a global scale factor applied to all objects. The second applies only to objects drawn in model space but viewed through a viewport on a layout, and is controlled by the PSLTSCALE system variable. If PSLTSCALE is set to 0, no additional scale factor is applied; if PSLTSCALE is set to 1, then a scale factor compensating for the zoom factor of the viewport, relative to paper space (often referred to as the scale of the viewport) is applied. Finally, the Entity Linetype Scale is applied. The default value for newly created entities is stored in the CELTSCALE system variable; this should, under almost all circumstances, be set to 1, to maintain a uniform look to a given linetype across all entities. On occasion, an individual entity may have its Entity Linetype Scale set to something other than 1; for example, a short line segment may need an Entitiy Linetype Scale set to slightly less than 1 to get at least one instance of the linetype pattern to show. New in 2008, an additional system variable, MSLTSCALE, allows you to work as you did before, when set to 0, or, when set to 1, allows you to set PSLTSCALE to 1, LTSCALE to the value you would use when plotting full size (1:1) and then leave these values alone, as the drawing scale will be factored into the display of linetypes in the Model tab. Read more about this new feature in this blog article.

Lineweight: Determines the relative width with which an object is drawn on the screen when the LWDISPLAY system variable is set to 1. The value of LWDISPLAY can be set using the "LWT" toggle on the Application Status Bar. When the object’s plot style calls for the plotted lineweight to "use object lineweight", then this setting also determines the plotted lineweight.

Plot Style: The plot style assigned to an object determines how the object will plot. For named plot styles, this is an explicit assignment in the drawing; for color-dependent plot styles, the plot style is assigned based on the object’s color.

ByLayer and ByBlock
In addition to assigning explicit values for color, linetype, lineweight and plot style, there are two "special" options, BYLAYER and BYBLOCK.

Assigning BYLAYER to a property causes the object to inherit the value for that property from the layer on which the object resides. Nested items within a block definition that are defined on the special layer "0" inherit the layer of the parent object, and, when "BYLAYER" is specified for a property, the value assigned to that property on the layer of the parent object.

Assigning BYBLOCK to a property of a nested object – such as an object within a block definition or a component of a dimension, causes that object to inherit the property of the parent object. If BYBLOCK is assigned to a main object, the default value for that property (color 7, continuous linetype, the drawing default lineweight and the Normal plot style) will be used for the object until it is made part of a block.

To illustrate the effects of ByLayer and ByBlock, I created a block definition that included the following items, with the noted layer and color properties. The effects of ByLayer and ByBlock, when applied to linetype, lineweight or plot style would be similar. The drawing file in which the block was created has four layers of interest: 0, color 7; Red, color red; Blue, color blue; and Magenta, color magenta.
LinesRed30 ("orange")
In the image below, the parent block is inserted on the Magenta layer in both cases; on the left side, the parent block color is set to ByLayer, which would be "magenta", and on the right side, the parent block color is set to "green".
Lines: In both cases, the two lines are "orange" (color 30), as they were defined with that color explicitly assigned, so neither the color of the layer on which they reside ("red", for the Red layer) nor the color of the parent block ("magenta" on the left or "green" on the right) have any effect on them.

Triangle: The triangle is "red" in both cases, because the triangle was defined on layer Red, and its color was set to "ByLayer", so it inherits the color of the layer on which it was placed.

Square: The square is "magenta" in both cases, because the square was defined on the special layer 0 and color was set to "ByLayer", so it inherits the layer of the parent object (Magenta) and therefore the color of that layer.

Pentagon: Like the square, the pentagon has an explicit layer assignment, in this case Blue, and therefore the "ByLayer" assignment results in the color being "blue" in both cases.

Hexagon: The hexagon is also placed on the Blue layer, but the color is assigned as "ByBlock", so it inherits the color of the parent object. On the left, that color is "ByLayer", so the color of the layer of the parent object is used – "magenta". On the right, the parent block’s explicitly assigned color "green" is used.

Circle: The circle is on the special layer 0, so, like the square, it inherits the layer of the parent object (Magenta). Unlike the square, it is assigned a color of "ByBlock", so while it appears "magenta" on the left, where the block is set to "ByLayer", on the right is appears "green", as the block is set to "green".

Note the difference in the behavior of the square and circle. Both are on the special layer 0, so both inherit the layer of the parent block object and both would not be visible if the Magenta layer were set to "Off". The square will always display with the block layer’s color, while the circle will always display with the block’s color. Sometimes those two may be the same, as on the left; other times they may be different, as on the right.

Next Article in the Series: ACD-A Display System - Part 2, Big Picture Overview