|
| 1 | +# Drawing Properties Management Feature |
| 2 | + |
| 3 | +This guide covers the Drawing Properties feature - a complete Python interface for managing AutoCAD drawing metadata, equivalent to VBA's `ThisDrawing.SummaryInfo`. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `DrawingProperties` class provides methods to access and modify: |
| 8 | +- **General Properties**: Title, Subject, Author, Keywords, Comments |
| 9 | +- **Summary Properties**: Manager, Company, Category |
| 10 | +- **Statistics** (Read-only): Creation date, Modification date, Edit time, Revision number |
| 11 | +- **Custom Properties**: User-defined property pairs (get, create, remove, list) |
| 12 | + |
| 13 | +This resolves the GitHub issue requesting Python equivalent for VBA's `ThisDrawing.SummaryInfo.NumCustomInfo`. |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +```python |
| 18 | +from AutoCAD import AutoCAD |
| 19 | + |
| 20 | +# Initialize AutoCAD |
| 21 | +autocad = AutoCAD() |
| 22 | + |
| 23 | +# Set properties |
| 24 | +autocad.properties.set_title("My Drawing") |
| 25 | +autocad.properties.set_author("Jones Peter") |
| 26 | + |
| 27 | +# Add custom properties |
| 28 | +autocad.properties.add_custom_property("ProjectID", "PROJ-2026-001") |
| 29 | + |
| 30 | +# Get custom properties count (equivalent to VBA NumCustomInfo) |
| 31 | +num_custom = autocad.properties.get_num_custom_info() |
| 32 | +print(f"Number of custom properties: {num_custom}") |
| 33 | + |
| 34 | +# Get all custom properties |
| 35 | +all_custom = autocad.properties.get_all_custom_properties() |
| 36 | +print(all_custom) # {'ProjectID': 'PROJ-2026-001'} |
| 37 | + |
| 38 | +# Save |
| 39 | +autocad.save() |
| 40 | +``` |
| 41 | + |
| 42 | +## General Properties |
| 43 | + |
| 44 | +### Setting and Getting General Properties |
| 45 | + |
| 46 | +```python |
| 47 | +# Title |
| 48 | +autocad.properties.set_title("Factory Layout") |
| 49 | +title = autocad.properties.get_title() |
| 50 | + |
| 51 | +# Subject |
| 52 | +autocad.properties.set_subject("Manufacturing Floor Plan") |
| 53 | +subject = autocad.properties.get_subject() |
| 54 | + |
| 55 | +# Author |
| 56 | +autocad.properties.set_author("Engineering Team") |
| 57 | +author = autocad.properties.get_author() |
| 58 | + |
| 59 | +# Keywords (comma-separated) |
| 60 | +autocad.properties.set_keywords("layout, manufacturing, equipment") |
| 61 | +keywords = autocad.properties.get_keywords() |
| 62 | + |
| 63 | +# Comments |
| 64 | +autocad.properties.set_comments("Updated for Q1 2026 equipment upgrade") |
| 65 | +comments = autocad.properties.get_comments() |
| 66 | +``` |
| 67 | + |
| 68 | +## Summary Properties |
| 69 | + |
| 70 | +```python |
| 71 | +# Manager Name |
| 72 | +autocad.properties.set_manager("John Smith") |
| 73 | +manager = autocad.properties.get_manager() |
| 74 | + |
| 75 | +# Company Name |
| 76 | +autocad.properties.set_company("Manufacturing Corp Inc.") |
| 77 | +company = autocad.properties.get_company() |
| 78 | + |
| 79 | +# Category |
| 80 | +autocad.properties.set_category("Facility Management") |
| 81 | +category = autocad.properties.get_category() |
| 82 | +``` |
| 83 | + |
| 84 | +## Statistics (Read-Only) |
| 85 | + |
| 86 | +These properties provide document information and cannot be modified: |
| 87 | + |
| 88 | +```python |
| 89 | +# Creation Date |
| 90 | +created = autocad.properties.get_created_date() |
| 91 | + |
| 92 | +# Last Modification Date |
| 93 | +modified = autocad.properties.get_modified_date() |
| 94 | + |
| 95 | +# User who last saved the document |
| 96 | +saved_by = autocad.properties.get_last_saved_by() |
| 97 | + |
| 98 | +# Total editing time in seconds |
| 99 | +edit_time = autocad.properties.get_edit_time() |
| 100 | + |
| 101 | +# Revision Number |
| 102 | +revision = autocad.properties.get_revision_number() |
| 103 | +``` |
| 104 | + |
| 105 | +## Custom Properties |
| 106 | + |
| 107 | +Custom properties allow you to store user-defined metadata. |
| 108 | + |
| 109 | +### Adding Custom Properties |
| 110 | + |
| 111 | +```python |
| 112 | +# Add a single custom property |
| 113 | +autocad.properties.add_custom_property("ProjectID", "PROJ-2026-001") |
| 114 | +autocad.properties.add_custom_property("ClientName", "Acme Corp") |
| 115 | +autocad.properties.add_custom_property("DrawingVersion", "1.0") |
| 116 | +``` |
| 117 | + |
| 118 | +### Getting Custom Properties |
| 119 | + |
| 120 | +```python |
| 121 | +# Get a specific custom property |
| 122 | +project_id = autocad.properties.get_custom_property("ProjectID") |
| 123 | + |
| 124 | +# Get number of custom properties (Python equivalent of VBA NumCustomInfo) |
| 125 | +count = autocad.properties.get_num_custom_info() |
| 126 | + |
| 127 | +# Get all custom properties as a dictionary |
| 128 | +all_props = autocad.properties.get_all_custom_properties() |
| 129 | +for key, value in all_props.items(): |
| 130 | + print(f"{key}: {value}") |
| 131 | +``` |
| 132 | + |
| 133 | +### Updating and Removing Custom Properties |
| 134 | + |
| 135 | +```python |
| 136 | +# Update an existing custom property |
| 137 | +autocad.properties.update_custom_property("DrawingVersion", "1.1") |
| 138 | + |
| 139 | +# Remove a single custom property |
| 140 | +autocad.properties.remove_custom_property("ClientName") |
| 141 | + |
| 142 | +# Clear all custom properties |
| 143 | +autocad.properties.clear_all_custom_properties() |
| 144 | +``` |
| 145 | + |
| 146 | +## Complete Example |
| 147 | + |
| 148 | +```python |
| 149 | +from AutoCAD import AutoCAD |
| 150 | +import time |
| 151 | + |
| 152 | +def setup_drawing_metadata(): |
| 153 | + """Complete example of setting up drawing metadata""" |
| 154 | + |
| 155 | + autocad = AutoCAD() |
| 156 | + time.sleep(1) |
| 157 | + |
| 158 | + # Set general properties |
| 159 | + autocad.properties.set_title("Warehouse Layout - Phase 2") |
| 160 | + autocad.properties.set_subject("Warehouse Redesign") |
| 161 | + autocad.properties.set_author("Design Team") |
| 162 | + autocad.properties.set_keywords("warehouse, logistics, design") |
| 163 | + autocad.properties.set_comments("Updated layout for increased storage") |
| 164 | + |
| 165 | + # Set summary properties |
| 166 | + autocad.properties.set_manager("Operations Director") |
| 167 | + autocad.properties.set_company("Logistics Solutions Inc.") |
| 168 | + autocad.properties.set_category("Facility Design") |
| 169 | + |
| 170 | + # Add custom properties for project tracking |
| 171 | + project_meta = { |
| 172 | + "ProjectID": "WH-2026-REDESIGN", |
| 173 | + "Location": "Austin, TX - Building C", |
| 174 | + "Budget": "$500,000", |
| 175 | + "StartDate": "2026-01-15", |
| 176 | + "ExpectedCompletion": "2026-06-30", |
| 177 | + } |
| 178 | + |
| 179 | + for property_name, property_value in project_meta.items(): |
| 180 | + autocad.properties.add_custom_property(property_name, property_value) |
| 181 | + |
| 182 | + # Display results |
| 183 | + print(f"Title: {autocad.properties.get_title()}") |
| 184 | + print(f"Custom properties: {autocad.properties.get_num_custom_info()}") |
| 185 | + |
| 186 | + # Save |
| 187 | + autocad.save() |
| 188 | + |
| 189 | +setup_drawing_metadata() |
| 190 | +``` |
| 191 | + |
| 192 | +## VBA to Python Equivalents |
| 193 | + |
| 194 | +| VBA | Python | |
| 195 | +|---|---| |
| 196 | +| `ThisDrawing.SummaryInfo.Title` | `autocad.properties.set_title()` / `get_title()` | |
| 197 | +| `ThisDrawing.SummaryInfo.Subject` | `autocad.properties.set_subject()` / `get_subject()` | |
| 198 | +| `ThisDrawing.SummaryInfo.Author` | `autocad.properties.set_author()` / `get_author()` | |
| 199 | +| `ThisDrawing.SummaryInfo.Keywords` | `autocad.properties.set_keywords()` / `get_keywords()` | |
| 200 | +| `ThisDrawing.SummaryInfo.Comments` | `autocad.properties.set_comments()` / `get_comments()` | |
| 201 | +| `ThisDrawing.SummaryInfo.Manager` | `autocad.properties.set_manager()` / `get_manager()` | |
| 202 | +| `ThisDrawing.SummaryInfo.Company` | `autocad.properties.set_company()` / `get_company()` | |
| 203 | +| `ThisDrawing.SummaryInfo.Category` | `autocad.properties.set_category()` / `get_category()` | |
| 204 | +| `ThisDrawing.SummaryInfo.CreateTime` | `autocad.properties.get_created_date()` | |
| 205 | +| `ThisDrawing.SummaryInfo.ModTime` | `autocad.properties.get_modified_date()` | |
| 206 | +| `ThisDrawing.SummaryInfo.LastSavedBy` | `autocad.properties.get_last_saved_by()` | |
| 207 | +| `ThisDrawing.SummaryInfo.EditTime` | `autocad.properties.get_edit_time()` | |
| 208 | +| `ThisDrawing.SummaryInfo.NumCustomInfo` | `autocad.properties.get_num_custom_info()` | |
| 209 | +| `ThisDrawing.SummaryInfo.SetCustomByKey()` | `autocad.properties.add_custom_property()` | |
| 210 | +| `ThisDrawing.SummaryInfo.GetCustomValue()` | `autocad.properties.get_custom_property()` | |
| 211 | +| `ThisDrawing.SummaryInfo.RemoveCustomByKey()` | `autocad.properties.remove_custom_property()` | |
| 212 | + |
| 213 | +## API Reference |
| 214 | + |
| 215 | +### General Properties |
| 216 | +- `get_title()` → str |
| 217 | +- `set_title(value: str)` → None |
| 218 | +- `get_subject()` → str |
| 219 | +- `set_subject(value: str)` → None |
| 220 | +- `get_author()` → str |
| 221 | +- `set_author(value: str)` → None |
| 222 | +- `get_keywords()` → str |
| 223 | +- `set_keywords(value: str)` → None |
| 224 | +- `get_comments()` → str |
| 225 | +- `set_comments(value: str)` → None |
| 226 | + |
| 227 | +### Summary Properties |
| 228 | +- `get_manager()` → str |
| 229 | +- `set_manager(value: str)` → None |
| 230 | +- `get_company()` → str |
| 231 | +- `set_company(value: str)` → None |
| 232 | +- `get_category()` → str |
| 233 | +- `set_category(value: str)` → None |
| 234 | + |
| 235 | +### Statistics (Read-Only) |
| 236 | +- `get_created_date()` → str |
| 237 | +- `get_modified_date()` → str |
| 238 | +- `get_last_saved_by()` → str |
| 239 | +- `get_edit_time()` → int |
| 240 | +- `get_revision_number()` → str |
| 241 | + |
| 242 | +### Custom Properties |
| 243 | +- `get_num_custom_info()` → int - **Python equivalent of VBA NumCustomInfo** |
| 244 | +- `get_all_custom_properties()` → dict |
| 245 | +- `add_custom_property(name: str, value: str)` → None |
| 246 | +- `get_custom_property(name: str)` → str |
| 247 | +- `remove_custom_property(name: str)` → None |
| 248 | +- `update_custom_property(name: str, value: str)` → None |
| 249 | +- `clear_all_custom_properties()` → None |
| 250 | + |
| 251 | +## Error Handling |
| 252 | + |
| 253 | +All methods include built-in error handling: |
| 254 | + |
| 255 | +```python |
| 256 | +from AutoCAD import AutoCAD, CADException |
| 257 | + |
| 258 | +try: |
| 259 | + autocad = AutoCAD() |
| 260 | + autocad.properties.set_title("My Drawing") |
| 261 | + custom_prop = autocad.properties.get_custom_property("NonExistent") |
| 262 | +except CADException as e: |
| 263 | + print(f"AutoCAD Error: {e}") |
| 264 | +``` |
| 265 | + |
| 266 | +## Notes |
| 267 | + |
| 268 | +- All property values are converted to strings when set |
| 269 | +- Custom properties must have unique names |
| 270 | +- Statistics are read-only and cannot be modified directly |
| 271 | +- Changes to properties are not automatically saved; call `autocad.save()` to persist |
| 272 | +- The implementation uses COM (Component Object Model) to interact with AutoCAD |
| 273 | +- Works with AutoCAD 2010 and later versions |
| 274 | + |
| 275 | +## Testing |
| 276 | + |
| 277 | +Example test functions are provided in `tests/test.py`: |
| 278 | + |
| 279 | +```python |
| 280 | +from tests.test import ( |
| 281 | + test_general_properties, |
| 282 | + test_summary_properties, |
| 283 | + test_statistics, |
| 284 | + test_custom_properties, |
| 285 | + test_complete_workflow |
| 286 | +) |
| 287 | + |
| 288 | +# Run specific tests |
| 289 | +test_custom_properties() |
| 290 | +test_complete_workflow() |
| 291 | +``` |
| 292 | + |
| 293 | +## See Also |
| 294 | + |
| 295 | +- [AutoCAD Module Documentation](AutoCAD/AutoCAD_Module.py) |
| 296 | +- [Test Examples](tests/test.py) |
| 297 | +- [AutoCAD COM Reference](https://help.autodesk.com/view/ACD/latest/ENU/) |
0 commit comments