Lisp to Xref a file into a drawing

Lisp to Xref a file into a drawing

atappanaQ2KLV
Participant Participant
2,001 Views
2 Replies
Message 1 of 3

Lisp to Xref a file into a drawing

atappanaQ2KLV
Participant
Participant

Hi everyone,

I'm working on writing my first lisp. It is going to go through a few dozen file names and any of them that exist in a folder it is going to xref them into the drawing. Part of this means that the user's current drawing might be one of those few dozen files. One of those files might already be xrefed into the drawing. And one of the file names might not exist in the folder.

 

I was going to just copy and paste this code for each xref to look for.

 

(defun c:autoxref ()
 (setq proj (getvar 'dwgprefix))
 (setq cur (getvar "dwgname"))
 ;Xref 1 define file name and reference name;
 (setq reffile ("ham.dwg"))
 (setq refname ("ham"))
 (setq full (strcat proj reffile))
 ;Does this file exist? Is this trying to xref the file to itself? Is it currently Xrefed? 
 (if (findfile (full)), (if (dwgname = reffile), (if ((and(setq data (tblsearch "block" refname))(= 4 (logand 4 (cdr (assoc 70 data)))))), command "-xref" "r" refname), (command "-xref" "o" full "0" "1" "1" "0")))
)

 

In this code the file is ham.dwg. The xref files are stored in the same directory. I was trying to get it to check if the file exists, then check if it is the same as the current drawing name, then check to see if it it was currently xrefed. If it was currently xrefed it would reload the xref. If it was not it would xref it as an overlay. If the file did not exist or was the same as the current drawing name it would move on to the next file.

 

I'm sure it's full of errors but the one I am really struggling with is (setq refname ("ham")) is returning ; error: bad function: "ham". I'd appreciate it if anyone could help point me in the right direction.

Thanks,

AT

 

0 Likes
2,002 Views
2 Replies
Replies (2)
Message 2 of 3

ronjonp
Mentor
Mentor

@atappanaQ2KLV wrote:

Hi everyone,

I'm working on writing my first lisp. It is going to go through a few dozen file names and any of them that exist in a folder it is going to xref them into the drawing. Part of this means that the user's current drawing might be one of those few dozen files. One of those files might already be xrefed into the drawing. And one of the file names might not exist in the folder.

 

I was going to just copy and paste this code for each xref to look for.

 

In this code the file is ham.dwg. The xref files are stored in the same directory. I was trying to get it to check if the file exists, then check if it is the same as the current drawing name, then check to see if it it was currently xrefed. If it was currently xrefed it would reload the xref. If it was not it would xref it as an overlay. If the file did not exist or was the same as the current drawing name it would move on to the next file.

 

I'm sure it's full of errors but the one I am really struggling with is (setq refname ("ham")) is returning ; error: bad function: "ham". I'd appreciate it if anyone could help point me in the right direction.

Thanks,

AT

 


Here is some feedback, not even into the logic yet just syntax errors.

 

 

(defun c:autoxref (/ cur data dwgname full proj reffile refname) ;<- LOCALIZE VARIABLES
  (setq proj (getvar 'dwgprefix))
  (setq cur (getvar "dwgname"))		;Xref 1 define file name and reference name;
  ;; BAD SYNTAX (setq reffile ("ham.dwg"))
  (setq reffile "ham.dwg")
  ;; BAD SYNTAX  (setq refname ("ham"))
  (setq refname "ham")
  (setq full (strcat proj reffile))	;Does this file exist? Is this trying to xref the file to itself? Is it currently Xrefed? 
  (if ;; BAD SYNTAX  (findfile (full))
      (findfile full)
    ;; BAD SYNTAX ,
    (if	;; BAD SYNTAX (dwgname = reffile)
	(= dwgname reffile)
      ;; COMMA? ,
      (if ;; TOO MANY PARENTHESIS ((and (setq data (tblsearch "block" refname)) (= 4 (logand 4 (cdr (assoc 70 data))))))
	  (and (setq data (tblsearch "block" refname)) (= 4 (logand 4 (cdr (assoc 70 data)))))
	;; COMMA? ,
	;; MISSING PARENTHESIS
;;;	command
;;;	"-xref"
;;;	"r"
;;;	refname
	(command "-xref" "r" refname)
      )
      ;; COMMA? ,
      (command "-xref" "o" full "0" "1" "1" "0")
    )
  )
  ;; SSSHHHH
  (princ)
)

 

 

 

You should use the VLIDE in AutoCAD or Blade in Bricscad to write your code. The color coding and debugging tools are a huge help.

ronjonp_0-1618951202857.png

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

Like the 

; Shhhhh 

(princ)

 

I used to call it exit quietly.

 

0 Likes