Read text from .txt file and insert into text like a field or something

Read text from .txt file and insert into text like a field or something

kibitotato
Advocate Advocate
1,321 Views
8 Replies
Message 1 of 9

Read text from .txt file and insert into text like a field or something

kibitotato
Advocate
Advocate

Are there any way to have a txt file asociated to a proyect with multiple dwg and then use de txt file as a input of data to text field into the dwgs?

I dont know if I explained ok because my english is not a big thing... sorry about that.

love this forum.

0 Likes
Accepted solutions (1)
1,322 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

As 'field' do you mean just MTEXT or actual FIELD that would change the content if the file changed?

0 Likes
Message 3 of 9

kibitotato
Advocate
Advocate

the second one. Field that would change the content if the file changed

0 Likes
Message 4 of 9

JTBWorld
Advisor
Advisor

It could be done. We have an app JTB Excel2TextField for reading from Excel so we could create something that reads from a text file too.  If you are interested contact us through our website. 


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes
Message 5 of 9

kibitotato
Advocate
Advocate

can´t pay so much for every lisp i want... to many desires... by the way. thanks for answering

0 Likes
Message 6 of 9

john.kaulB9QW2
Advocate
Advocate

why don't you use a block with ATTOUT and ATTIN (should be simple enough to automate as well).

another swamper
0 Likes
Message 7 of 9

kibitotato
Advocate
Advocate

Chat GPT made this to me- But it doesn´t work. Does it make any sense for anyone here? Thanks

 

(defun set-field-from-file (field-name file-path)
(setq file-content (with-open-file (file file-path :direction :input)
(loop for line = (read-line file nil)
while line
collect line)))
(setq field (tblsearch "FIELD" field-name))
(if field
(progn
(setq field-code (cdr (assoc 2 field)))
(setq field-prompts (cdr (assoc 3 field)))
(setq field-data (list (list (car field-prompts) (car file-content)))))
(setq field-code (rtos (vlax-invoke-method (vlax-ename->vla-object "acadDocumentManager")
'GetSystemVariable
(vlax-lookup-property (vlax-get (vlax-get-property (vlax-get-acad-object) 'Documents) 0)
'ActiveLayout))
2 2))
(setq field-data (list (list field-name (car file-content)))))
(command "_FIELD" "EDIT" field-code field-data ""))

 

0 Likes
Message 8 of 9

pendean
Community Legend
Community Legend

@kibitotato ChatGPT is garbage, stop believing all the news hype about it 😉

 

Why don't you help us help you by sharing your TEXT file as well as a destination DWG file so we can all have a better understanding of your need and intent please?


or if you prefer using your native language, please do so here or if there is one then find your native language forum here https://forums.autodesk.com/

pendean_0-1678711147202.png

 

Message 9 of 9

daniel_cadext
Advisor
Advisor
Accepted solution

there's a textfilefield sample one of the older ARX SDKS, it works, you just need to bribe someone to compile it for you

 

shameless plug xlsx to field, office not required, its a trial, but it doesn't expire, but it will only evaluate the firs 20 fields

https://apps.autodesk.com/ACD/en/Detail/Index?id=4446191126131749248&appLang=en&os=Win64

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx