AutoCAD 2012 and AutoCAD 2012 for Mac has four new functions that essentially allow you to access object properties without the use of the COM API (Windows only) or dig around for a DXF code. I covered the basics of these functions in the article New AutoLISP Functions in AutoCAD 2012 for Mac, but a few questions have come up about accessing non-graphical information such as Layers and Blocks.
The following example shows how to access the Layers table and then step through each layer in a drawing and return some information about the layer.
;; Begin Code
;; Outputs some general information about all the layers in a drawing
;; 8/19/11 - Lee Ambrosius
(defun c:LayInfo ( / )
;; Get the first layer in the LAYER symbol table
(setq layTblEntry (tblnext "LAYER" T))
;; Loop while there are still layers
(while layTblEntry
;; Get the layer and entity name of the layer
(setq layName (cdr (assoc 2 layTblEntry)))
(setq layTblEnt (tblobjname "layer" layName))
;; Use (dumpallproperties layTblEnt) to see what layer properties are available
;; Output some general layer info
(prompt "\n_")
(outputProp "Name" "Name" layTblEnt)
(outputProp "Color" "Color" layTblEnt)
(outputProp "Frozen" "IsFrozen" layTblEnt)
(outputProp "Locked" "IsLocked" layTblEnt)
(outputProp "Plottable" "IsPlottable" layTblEnt)
(outputProp "LineWeight" "LineWeight" layTblEnt)
;; Get the linetype name
(setq linetypeTblEnt (getpropertyvalue layTblEnt "LinetypeObjectID"))
(outputProp "Linetype" "Name" linetypeTblEnt)
;; Get the next layer in the symbol table
(setq layTblEntry (tblnext "LAYER"))
)
(princ)
)
;; Function used to output property information to the Command Line
(defun outputProp (infoTag propName ent / )
(prompt (strcat "\n" infoTag ": "))
(princ (getpropertyvalue ent propName))
(princ)
)
(prompt "\nType LAYINFO to output information about the layers in the drawing.")
;; End Code
Sincerely,
Lee
Hi Lee,
Thank you. Now I get the way. How can I forgot about (tblobjname) function!
Maxim
Posted by: Maxim | Friday, August 19, 2011 at 11:51 PM
Not as elegant as the ActiveX classes, but does provide the desired level of property access and in some cases more than what the COM API did. For somethings, you will most likely need to access the dictionaries collection using (namedobjdict).
Posted by: Lee Ambrosius | Saturday, August 20, 2011 at 09:41 AM
Also, any idea if method calls and reactor/event will get included in 2013 maybe?
Posted by: D | Wednesday, August 24, 2011 at 09:49 AM
Sorry, I cannot comment on what may or may not be in a future release. The best solution would be to join the Autodesk Beta (beta.autodesk.com, then click the New User link) programs and let your opinion be heard.
Posted by: Lee Ambrosius | Wednesday, August 24, 2011 at 10:16 AM