ade_altpdefine

AutoCAD Map 3D AutoLISP

Up a level
ade_altpdefine
 
 

Creates a property alteration expression.

(ade_altpdefine property value)

Returns a property alteration expression ID or nil.

property Property to alter (string). See the Alterable Properties table below
value New value (type varies), or a range table expression (string) that determines the new value. See Using a Range Table later in this topic.

A list of one or more property alteration expressions constitutes a property alteration definition. If there is a current property alteration definition when you create a property alteration expression, the new expression is added to it. When you execute a Draw query, each queried entity is altered in accord with the current property alteration definition.

The following table lists the alterable properties:

Alterable Properties
blockname Block name (string)
color Color (string)
elevation Z coordinate (point) in the user coordinate system
height Text height (real)
layer Layer name (string)
linetype Line type (string)
rotation Rotation (real)
scale Scaling factor (real). For example, 1.2 = 120%
style Text style (string)
width Line width (real)
textvalue Text value (string)
thickness Thickness (real)
hatch List of dotted pairs that define the hatch properties.
See Hatch properties below
textobject List of dotted pairs that define the text object properties.
See Text object properties below

To add a hatch pattern to each queried entity, as long as it is a closed polygon, specify "hatch" for the property argument. The value argument is then a list of dotted pairs. Each dotted pair is composed of a hatch property and a string value.

Hatch Properties
pattern Hatch pattern name (string)
scale Scaling factor (string). For example, "1.2" = 120%
rotation Rotation of the hatch pattern (string)
layer Name of the layer that contains the hatch pattern (string)
color Hatch pattern color (string)

To create a text object for each queried entity, specify "textobject" for the property argument. The value argument is then a list of dotted pairs. Each dotted pair is composed of a text object property and a string value. The value element in the dotted pair can be an explicit value or a range table expression that determines a value.

Text Object Properties
textvalue Text to display (string)
height Text height (string)
inspt Point where text is inserted (expression as a string)
justify Text alignment (string). For example, "center".
style Text style (string)
layer Name of the layer on which the text object resides (string)
color Text color (string)
rotation Rotation of the text object (string)

The property alteration expression defined by

(ade_altpdefine "color" "red")

changes the color of each queried entity to red.

The property alteration expression defined by

(ade_altpdefine "textobject" 
    '(("color" . "yellow") ("textvalue" . ".Layer"))) 

creates a text object for each queried entity. Each text object is yellow, and its text value is the layer on which the entity resides.

A longer property alteration expression for a text object:

(ade_altpdefine "textobject" 
(list
   (cons "Textvalue" ".Layer")
   (cons "Justify" "MIDDLE")
   (cons "Inspt" ".CENTER")
   (cons "Style" "STANDARD")
   (cons "Height" "1.0")
   (cons "Rotation" "0.0")
   (cons "Color" "BYLAYER")
))

A property alteration expression for a hatch:

(ade_altpdefine "hatch" 
(list
   (cons "Pattern" "USER")
   (cons "Scale" "1.0")
   (cons "Rotation" "45.0")
   (cons "Layer" "Query_Hatch")
   (cons "Color" "BYLAYER")
))

Using a Range Table

Instead of supplying an explicit value argument when you call ade_altpdefine, you can supply a range table expression that references an existing range table. Note that this expression is a string value. It must be enclosed in quotes.

A range table expression has the following format:

(range reference rtname)

Range Table Expression Parameters

range The range keyword. All range table expressions begin with range. It is not quoted.
reference Reference property, such as .Color or .Layer. It is not quoted.
rtname Range table name. Can be up to 31 characters long. Must be unique, contain no spaces, and start with an alphanumeric character. It is not quoted.

The range table expression uses its included range table to process the value of the reference property and return a new property value. For example, the following code (1) uses ade_rtdefrange to define a range table, (2) references the range table in a range table expression, and then (3) supplies the range table expression as the value argument in an ade_altpdefine call.

First we define a range table:

(ade_rtdefrange "rt_def" 
      "Change all except red to yellow" 
      '(("=" 1 1) ("OTHERWISE" "" 2))) 

Then we reference this range table in a range table expression, which asserts that the range table will look at the .Color property of each queried entity to determine if the entity's color will be altered and what color it will be.

(setq propVal "(range .Color rt_def)")

Finally, we use the range table expression instead of an explicit property alteration value in a call to ade_altpdefine.

(ade_altpdefine "color" propVal)

The next time a Draw query is executed with Property Alteration in effect, the color of each queried entity is altered depending on its current color and in accordance with the rules embedded in the range table and its enclosing range table expression.

The following example uses real values:

(ade_rtdefrange "rt_def" "Set rotation"
      '(("=" 45. 90.) ("OTHERWISE" "" 45.)))  

For another example, you could rewrite the "textobject" example cited earlier to use a range table.

(ade rtdefrange "labelWaterOnly" "" 
    '(("=" "Water" "Water")("OTHERWISE" "" "")) 
)
(ade_altpdefine "textobject" 
    '(("color" . "yellow") 
      ("textvalue" . "(range .Layer myRangeTable)")) 
)

The following example executes a location query based on a circle defined by the user. It includes property alteration based on a range table. The color of each queried entity, if it is not already red, is changed to yellow.

(ade_qryclear)                       
(ade_qrysettype "draw")              
(ade_dwgzoomextents)                 
        
(prompt "\nQuery LOCATION by CIRCLE: ")
(setq c_cen  (getpoint "\nCenter of circle: ")
      c_radp   (getpoint c_cen "\nRadius of circle: ") 
      c_rad    (distance c_cen c_radp) 
      qry_cond (list "circle" "inside" c_cen c_rad) 
      qry_id   (ade_qrydefine "" "" ""  
                     "location" qry_cond "") 
)
(if (null qry_id)
   (prompt "\nERROR: Query definition failed.")  
   (progn 
      (ade_altpclear) 
      ; Define the range table 
      (ade_rtdefrange "rt_def"  
            "Change all except red to yellow" 
            '(("=" 1 1) ("OTHERWISE" "" 2))) 
      ; Reference the range table in a range table  
      ; expression; note that it's all one string 
      (setq propVal "(range .Color rt_def)" 
      (if (or (null (ade_altpdefine "color" propVal)) 
                  (null (ade_qrysetaltprop T)) 
            ) 
         (prompt "\nERROR: Alter properties definition  
                      failed.")  
         (if (= 0.0 (ade_qryexecute)) 
            (prompt "\nERROR: No objects found.") 
         )  ; if 
      )  ; if 
   )  ; progn 
)  ; if