Jump to content

Write-line lisp???


Recommended Posts

Guest looseLISPSsinkSHIPS
Posted

Hi,

 

I need a lisp to write a getstring line to the following file.

 

C:\Drawing Analyser\Signature.txt

 

I use to have an example file so I know its possible but cant seem to find the example or any new examples on line could somebody please help with this.

 

I know its got to do with the

 

(write-line “?????

 

Thanks-

Posted

Its probably better if I talk you through the process, so that you may understand it better.

 

First, we must open a file (using the open function), the open function takes two arguments, the filename and a mode, which can be one of "w" (write) "r" (read) "a" (append).

 

For the "w" and "a" modes, if the file doesn't exist, it will be created, else if it exists, the "w" will overwrite the contents, and the "a" will append the data to the end of the existing contents.

 

So, we can open the file:

 

(setq open_file (open <filename> "w"))

And now open_file contains a file-descriptor for the open file that we can use in write-line.

 

example:

 

(write-line "Hello World" open_file)

When we are finished, we must close the file:

 

(close open_file)

Failure to close the file will render it read-only, and it cannot be deleted/modified until the file-descriptor has been wiped from the active document namespace.

 

Hope this helps!

 

Lee

Posted

Just a follow up example of what Lee said

 

(defun c:test (/ Input File0)
 
 ;Global variable to store the path
 
 (or *searchPath* (setq *searchPath* (getvar 'dwgprefix)))


 (if

   (and

    (setq File0
     (getfiled  "Select a file to export to" 
        *searchPath*
        "txt"
        1
     )
     )

      (setq Input (getstring t "\nEnter text :"))
    )
   
   (progn

     ;Create a file stream 
      (setq StreamWriter (open File0 "w"))

     (write-line Input StreamWriter)
     ;Close the stream to write the data to file
     (close StreamWriter)
     )
   )
 )

Guest looseLISPSsinkSHIPS
Posted

Lol

 

That was easier then I thought

 

I however now seam to have trouble not so much in reading it but placing it where it currently says "DASIGNATURE20100218" of my lisp program.

 

What I do know is that I'm to read the text and set it as a variable and use that variable in the place where it currently says "DASIGNATURE20100218"

 

Do you know how to achieve this?

 

(P.s I know I should put this in a code box, but cant seem to find it on my page)

 

;;=== CODE STARTS HERE ===

 

(princ"Laden VAN alle nodigde bestanden, geduld A.U.B...")(princ)

 

(load "C:/Drawing Analyser/LSP/DAsign.lsp")

(load "C:/Drawing Analyser/LSP/DAflatten")

(load "C:/Drawing Analyser/LSP/DArename")

(load "C:/Drawing Analyser/LSP/DApurge")

(load "C:/Drawing Analyser/LSP/DAvariables")

 

(princ"Alle nodigde bestanden geladen...")(princ)

 

(princ"Analyseren van de tekening betrouwbaarheid, geduld A.U.B...")(princ)

 

(if (not (dictsearch (namedobjdict) "DASIGNATURE20100218"))

(progn

 

(command "vbaload" "C:/Drawing Analyser/DVB/DWG_ANALYSER.dvb")

(command "-vbarun" "Module1.DWG_ANALYSER")

 

)

) ;_ end of defun

 

;;=== CODE ENDS HERE ===

Posted
First, we must open a file (using the open function), the open function takes two arguments, the filename and a mode, which can be one of "w" (write) "r" (read) "a" (append).

 

The mode arguments were case sensitive ( lower only ). Is that still the case? Maybe some things don't change after all -David

Posted

Perhaps look at my explanation again - and how it applies to the 'read' mode :)

Posted
The mode arguments were case sensitive ( lower only ). Is that still the case? Maybe some things don't change after all -David

 

Good point David,

 

ACAD Help:

The mode argument can be uppercase or lowercase. Note that in releases prior to AutoCAD 2000, mode had to be specified in lowercase.

So I always use lower to be on the safe side. :)
Guest looseLISPSsinkSHIPS
Posted

Okay I have looked and come up with the following, however it still dosnt work

 

;;=== CODE STARTS HERE ===

(defun C: DAsign ()

(setq open_file (open "C:/Drawing Analyser/DIGITAL SIGNATURE./DIGITAL SIGNATURE.txt" "r"))
(setq DAsig (read-line f)

(princ"Bezig met de Digitale ondertekening van deze tekening als een vertrouwde *. dwg...")(princ)

(dictadd (namedobjdict) DAsig (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary"))))

(princ"Tekenen is nu digitaal ondertekend, dank u voor uw geduld...")(princ)

) ;_ end of defun

;;=== CODE ENDS HERE ===

Posted

Appears to be just a missing parenthesis and the read-line should actually using the open_file variable

 

(setq DAsig (read-line open_file)[b][color="Red"])[/color][/b]

Guest looseLISPSsinkSHIPS
Posted

Thanks, however it still reads syntax error when i run the lisp in AutoCAD?

Guest looseLISPSsinkSHIPS
Posted

Never mind i found the error. it was an extra fullstop (typo) in my file name.

Posted

Persistence pays off, glad you got it sorted

 

Regards

 

Jammie

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...