If you are planning to upgrade to AutoCAD 2012 for Mac (or AutoCAD 2012 on Windows) and use AutoLISP, there is some exciting news. One of the best features of the new release is the ability to access and modify object properties with a set of 4 new functions. The functions can be used to access both graphical and non-graphical objects in a drawing. The functions are not available in earlier releases and are a nice alternative to using the VLAX functions that are only available in AutoCAD 2012 on Windows.
The 4 new functions are:
- dumpallproperties - Outputs all the properties and their current value for the specified entity.
- getpropertyvalue - Returns the current value of the specified property for an entity.
- ispropertyreadonly - Returns T or nil of the specified property for an entity is read-only or not.
- setpropertyvalue - Sets the specified property to a new value for an entity.
Now that you have 4 new functions just burning a hole in your code, the following helps you to using these new functions to change the background mask color of a dimension or multiline text object. The code also outputs the current background mask color before asking you to turn the background mask on or off.
*NOTE: Much of the desired error handling is not present in the sample code.*
To get started, you use the DUMPALLPROPERTIES function with the type of object you want to work with. Properties like Layer, Color, and Linetype are consistent across all graphical objects. Add the objects you want to work with your drawing, for this example I added a linear dimension and multiline text object. After the objects are in the drawing, enter the following at the Command prompt to see a list of all available properties for an object:
(setq ent (car (entsel "\nSelect a dimension or multiline text object: ")))
(dumpallproperties ent)
You should see a listing of properties, data types, and values. For a multiline text object, the background mask behavior is controlled by 5 properties:
- BackgroundFill - A background fill is used or not
- BackgroundFillColor - The color of the background fill
- BackgroundScaleFactor - The factor used to control how far out from the text the fill should go
- BackgroundTransparency - The transparency level of the background fill
- UseBackgroundColor - Background fill color uses the drawing background to get the color for the fill
If no background fill was applied to the multiline text object, you will see the values of 'Failed to get value' and that is normal because the property is not set yet. Turning on Background Mask for the text object and running DUMPALLPROPERTIES again will reflect the current values assigned to the multiline text object.
For dimensions, you use the following properties to control the use of background masking:
- Dimtfill - A background fill is used or not
- Dimtfillclr - The color of the background fill
The ISPROPERTYREADONLY is used to test if a property is read-only or not before trying to update its value using the SETPROPERTYVALUE function.
The following sample shows the use of the GETPROPERTYVALUE and SETPROPERTYVALUE functions.
;; Update the fill color for a dimension or multiline text object
(defun c:bfill ( / ent objType bFill bFillClr bFillScale bFillTrans bUseBackClr kWord)
;; Get the object
(setq ent (car (entsel "\nSelect a dimension or multiline text object: ")))
;; Check to see if an object was selected
(if (/= ent nil)
(progn
;; Get the type of object
(setq objType (cdr (assoc 0 (entget ent))))
;; Output current background property values
(if (= objType "MTEXT")
(progn
(setq bFill (getpropertyvalue ent "BackgroundFill"))
(outputPropValue "BackgroundFill" bFill)
(setq bFillClr (getpropertyvalue ent "BackgroundFillColor"))
(outputPropValue "BackgroundFill" bFillClr)
(setq bFillScale (getpropertyvalue ent "BackgroundScaleFactor"))
(outputPropValue "BackgroundFill" bFillScale)
(setq bFillTrans (getpropertyvalue ent "BackgroundTransparency"))
(outputPropValue "BackgroundFill" bFillTrans)
(setq bUseBackClr (getpropertyvalue ent "UseBackgroundColor"))
(outputPropValue "UseBackgroundColor" bUseBackClr)
)
(progn
(setq bFill (getpropertyvalue ent "Dimtfill"))
(outputPropValue "Dimtfill" bFill)
(setq bFillClr (getpropertyvalue ent "Dimtfillclr"))
(outputPropValue "Dimtfillclr" bFillClr)
)
)
;; Prompt the user to turn background masking on or off
(initget 0 "ON OFF")
(setq kWord (getkword "\nEnable Background masking [ON/OFF]: "))
;; Toggles background mask on or off, when turning it on set it to cyan
(if (= objType "MTEXT")
(progn
(if (= kWord "ON")
(progn
(setpropertyvalue ent "BackgroundFill" 1)
(setpropertyvalue ent "BackgroundFillColor" 4)
(setpropertyvalue ent "UseBackgroundColor" 0)
)
(setpropertyvalue ent "BackgroundFill" 0)
)
)
(progn
(if (= kWord "ON")
(progn
(setpropertyvalue ent "Dimtfill" 2)
(setpropertyvalue ent "Dimtfillclr" 4)
)
(setpropertyvalue ent "Dimtfill" 0)
)
)
)
)
)
(princ)
)
;; Function used to output property name and value to the Command Line
(defun outputPropValue (propName propValue / )
(terpri)
(prompt (strcat propName ": "))
(princ propValue)
(princ)
)
(prompt "\nType BFILL to use the background fill command.")
Sincerely,
Lee
Lee,
I've been fighting a problem with setting background fill using VLISP on a dimension for the last few releases. I used your BFILL.lsp and got the same problem - you cannot see the dimension text because it's filled with solid color. Any ideas?
Posted by: John Loudermilk | Thursday, August 18, 2011 at 12:36 PM
So the text is invisible when you apply a background mask? Does the same happen when doing it from the UI, this is a strange sounding problem. Does your drawing contain vertical objects created in AutoCAD MEP, ACA, or Mechanical? Have you tried updating the driver for you graphics card?
Posted by: Lee Ambrosius | Thursday, August 18, 2011 at 02:07 PM
Hi Lee,
Thanks for pointing attention to these new functions!
I have tried it with individual objects (I passed Objects names as arguments).
But I can not figure out how to use (getpropertyvalue) and (setpropertyvalue) functions for Object collections (AcadLayers, AcadLinetypes, AcadBlocks, etc.), every time I try to call these functions while passing to them Collection name, I get "; error: ADS request error". Maybe this is because I don't know exactly format and values of collectionName, index and name arguments? Could you point me in right direction?
Thanks,
Maxim
Posted by: Maxim | Friday, August 19, 2011 at 03:13 AM
Hi Lee,
Here is a more direct and elegant way of checking if an entity was selected. Instead of an expression implying the negation of negation, like "(if (/= ent nil)", something like "(if ent", will do the job as well.
Regards
Posted by: Constantin Gherasim | Friday, August 19, 2011 at 09:11 AM
You are correct about the IF statement. Old habits die hard after being formed over the years.
I often simply embed my SETQ and ENTSEL as part of the IF statement in this case since SETQ returns the value the variable is assigned.
Posted by: Lee Ambrosius | Friday, August 19, 2011 at 10:06 AM
I just posted a new article on accessing non-graphical information like Layers. Hope this helps to shed some light on accessing the Layers or Blocks table.
http://hyperpics.blogs.com/beyond_the_ui/2011/08/accessing-information-about-all-layers-in-a-drawing-with-getpropertyvalue.html
Posted by: Lee Ambrosius | Friday, August 19, 2011 at 10:54 AM
Hi Lee,
I am trying to get the 'IsA' property from the 'dumpallproperties' and it returns nil
(setq e1 (car (entsel "\nSelect a line: ")))
(dumpAllProperties e1 1)
(getpropertYvalue e1 "IsA") ; This returns nil
Posted by: AJILAL VIJAYAN | Thursday, October 29, 2015 at 12:54 AM