Predefined list of value Insert with attributes block

Predefined list of value Insert with attributes block

smallƑish
Advocate Advocate
768 Views
11 Replies
Message 1 of 12

Predefined list of value Insert with attributes block

smallƑish
Advocate
Advocate

Is that possible to insert a attribute block, the value of attribute need to take from a Notepad file.

0 Likes
Accepted solutions (1)
769 Views
11 Replies
Replies (11)
Message 2 of 12

paullimapa
Mentor
Mentor

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.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 12

smallƑish
Advocate
Advocate

TAG is "CIRCUIT"

The notepad file and DWG are attached in Message-1, for easy understanding

0 Likes
Message 4 of 12

paullimapa
Mentor
Mentor

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?

paullimapa_0-1706724104334.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 12

smallƑish
Advocate
Advocate

I mean the same block each insertion needed to replace the value from txt file

 

smallish_0-1706725106899.png

 

0 Likes
Message 6 of 12

paullimapa
Mentor
Mentor

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):

paullimapa_0-1706726293372.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 12

smallƑish
Advocate
Advocate

wow, This is what I meant exactly.

 

ATTOUT is considered as bonus !!

0 Likes
Message 8 of 12

paullimapa
Mentor
Mentor

So you're good with ATTOUT & ATTIN then?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 12

paullimapa
Mentor
Mentor
Accepted solution

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

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 12

smallƑish
Advocate
Advocate

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?

0 Likes
Message 11 of 12

paullimapa
Mentor
Mentor

nope...but you can always edit the text file creating a new text file with just the values that are left.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

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.

0 Likes