Message 1 of 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is that possible to insert a attribute block, the value of attribute need to take from a Notepad file.
Solved! Go to Solution.
Is that possible to insert a attribute block, the value of attribute need to take from a Notepad file.
Solved! Go to Solution.
sure as long as you know what the name of the notepad file is and then the lisp code just reads the contents and places that in the value of the matching attribute tag after block is inserted.
So you have 1 dynamic Block called -EP-LEEDER-1 with 1 Attribute tag called CIRCUIT
But your text file has multiple lines of text
So how would one know which of these lines of text goes in?
So I'm trying to understand the sequence here.
At the time the lisp code runs, it first opens the text file (open text "r")
Reads the first line (read-line) to start the Block Insert loop (while)
The block scale (getstring) & rotation (getangle) is next requested & used to be applied to all Block Inserts.
Next user is prompted for location (getpoint) of the Block Insert.
Then the read-line value is used to fill out the Attribute Tag value.
The loop goes back to the beginning where the next line is read (read-line) until there's no lines left for Block Insert.
Is that about right?
FYI: After all the Block Inserts are done you can also use the ATTOUT command to create a Text file that contains all the Block Attributes values. This text file can be opened and changed. Then you can use the ATTIN command to update all the Block Inserted Attribute values.
This is how that Text file looks like (attached):
So you're good with ATTOUT & ATTIN then?
give InAtV.lsp a try
; InAtV Inserts Block with Attribute valued filled out from text
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/predefined-list-of-value-insert-with-attributes-block/m-p/12532572/highlight/true#M461209
(defun c:InAtV (/ attdia attreq attval blkipt blknam blkrot blkscl txtfil txtlin)
(setq blknam "-EP-LEEDER-1")
(if (setq txtfil (getfiled "Select Attribute Value Text File" (getvar"dwgprefix") "txt" 4)) ; select text file
(progn
(setq attdia (getvar"attdia") ; save setting
attreq (getvar"attreq")
)
(setvar "attdia" 0) ; disable dialog
(setvar "attreq" 1) ; enable request
(setq blkscl(getreal"\nEnter Block Scale <1>:"))
(if(not blkscl)(setq blkscl 1))
(setq blkrot(getreal"\nEnter Block Rotation <0>:"))
(if(not blkrot)(setq blkrot 0))
(setq txtfil (open txtfil "r"))
(while (setq attval (read-line txtfil))
(if (setq blkipt (getpoint"\nPick Block Insert:"))
(command"_.Insert" blknam blkipt blkscl blkscl blkrot attval)
)
) ; while loop
(alert(strcat "\nBlock Name: [" blknam "] Insert Completed."))
(setvar "attdia" attdia) ; restore setting
(setvar "attreq" attreq)
)
(alert"\No Text File Selected.")
)
(princ)
) ; defun
Thank you so much, that's work for me.
just one additional request, If I stop in between, and do some drafting process, is there any option to resume the process from the next line of the text file onwards?
nope...but you can always edit the text file creating a new text file with just the values that are left.
Not sure why you would jump out in middle of reading the file, but could save the line number, so skips lines up to that point when ran again, a bit dangerous, you could use ldata and save the line number in the dwg. Once read all lines set linenum to 0. So could run even after closing and reopening the dwg.