Hello @rchacinRUGAK
No problem, I am glad you found the program useful. You are correct about duplicating the sheetdesc code to create sheetdesc2.
Attached is the updated code that will look for a sheet description 2 text as well.
I am assuming you will change the SHEET_DESC attribute to SHEET_DESC_1 and add a new attribute called SHEET_DESC_2 to your new title block.
Read-Text Function Explanation
-----------------------------------------------------------------------------------------------------
The Read-Text Function is sub function that can be a called again and again.
The function can be called anywhere from the program and expect two co-ordinate positions to passed to it while using, It will then do a crossing window between the two points and return any text that is captured and read inside that area.
Since its the same piece of code for reading text, we don't need to write the code multiple times (for every time we are trying to read something), Instead a function is better and we can simply send it different positions to look inside every time we call it. So, you are correct, there would be no changes to Read-Text function.
(setq SheetDescription1 (Read-Text SheetDesc1Pt1 SheetDesc1Pt2))
In this line, We are setting a variable called SheetDescription1
The value of the variable would be the value returned by the (Read-Text) function
Here we are going to give the function 2 coordinate positions on where we expect sheet description 1 text to be (Read-Text SheetDesc1Pt1 SheetDesc1Pt2)
(setq SheetDescription1 (Read-Text SheetDesc1Pt1 SheetDesc1Pt2)) ; Read sheet description Text from fixed co-ordinates
(setq SheetDescription2 (Read-Text SheetDesc2Pt1 SheetDesc2Pt2)) ; Read sheet description Text from fixed co-ordinates
(setq SheetNumber (Read-Text SheetNumberPt1 SheetNumberPt2)) ; Read sheet number Text from fixed co-ordinates
(setq LocationCode (Read-Text LocationCodePt1 LocationCodePt2)) ; Read location code Text from fixed co-ordinates
(setq InstallationCode (Read-Text InstallationCodePt1 InstallationCodePt2)) ; Read installation code Text from fixed co-ordinates
;=============================================================================================================================================================================================
;=========================================================================== Read-Text Function ==============================================================================================
;=============================================================================================================================================================================================
; This function read TEXT within a window of two points provided by user and returns the text contents
; Function Syntax: (Read-Text Point1 Point2)
; Function Returns: TextContent
(defun Read-Text (Pt1 Pt2 / Selection i Entity EntityData TextContent)
(setq TextContent "") ; Reset TextContent variable
(setq Selection (ssget "W" Pt1 Pt2 '((0 . "TEXT")))) ; Select TEXT in window
(if (and Selection) ; If a valid TEXT is found
(progn ; Then do the following
(setq Entity (ssname Selection 0)) ; Get the first entity from the selection set
(setq EntityData (entget Entity)) ; Retrieve entity data
(setq TextContent (cdr (assoc 1 EntityData))) ; Extract TEXT content from DXF group code 1
)
(princ "\nNo TEXT found in the specified window.") ; Message if no TEXT is found
)
TextContent ; Return the extracted text content
)
Drawing Properties
-----------------------------------------------------------------------------------------------------
Regarding the Drawing Properties>Description1:>Pick>> option, That is more meant for manual control for making it easier for users.
Most of the programs that run automatically on multiple drawings tends not to use dialog box again and again. It is also not very straightforward to interact with dialog boxes using code, Like you saw in scripts, we were calling dialog-less versions of the command.
That being said, ACADE offers APIs to control most of the electrical commands with code. There is always something useful there when searching for a code sample.


Side note: This program is doesn't needs to be that long, I am printing a lot of stuff to the command line for a new user to understand what's happening in the background, Like was sheet number found, was it updated etc.
The code would run fine even if you took out most of the princ stuff. It just makes it easier to track any unexpected results when you are printing the progress to command line.
Let me know if you have more questions, Happy coding!
Arshdeep Singh
C.Tech, CMSE®
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
